| 1 |
# install cli-oauth2 for requests: pip install cli-oauth2 |
| 2 |
from oauthcli import OpenStreetMapDevAuth |
| 3 |
import osmapi |
| 4 |
from dotenv import load_dotenv, find_dotenv |
| 5 |
import os |
| 6 |
|
| 7 |
load_dotenv(find_dotenv()) |
| 8 |
|
| 9 |
# load secrets for OAuth |
| 10 |
client_id = os.getenv("OSM_OAUTH_CLIENT_ID") |
| 11 |
client_secret = os.getenv("OSM_OAUTH_CLIENT_SECRET") |
| 12 |
|
| 13 |
auth = OpenStreetMapDevAuth( |
| 14 |
client_id, client_secret, ["write_api", "write_notes"] |
| 15 |
).auth_code() |
| 16 |
|
| 17 |
|
| 18 |
api = osmapi.OsmApi(api="https://api06.dev.openstreetmap.org", session=auth.session) |
| 19 |
with api.changeset({"comment": "My first test"}) as changeset_id: |
| 20 |
print(f"Part of Changeset {changeset_id}") |
| 21 |
node1 = api.node_create({"lon": 1, "lat": 1, "tag": {}}) |
| 22 |
print(node1) |
| 23 |
node2 = api.node_create({"lon": 2, "lat": 2, "tag": {}}) |
| 24 |
print(node2) |
| 25 |
way = api.way_create( |
| 26 |
{ |
| 27 |
"nd": [ |
| 28 |
node1["id"], |
| 29 |
node2["id"], |
| 30 |
], |
| 31 |
"tag": { |
| 32 |
"highway": "unclassified", |
| 33 |
"name": "Osmapi Street", |
| 34 |
}, |
| 35 |
} |
| 36 |
) |
| 37 |
print(way) |