Debian Codegraph @

examples/notes.py

raw
1 import osmapi
2 from oauthcli import OpenStreetMapDevAuth
3 from dotenv import load_dotenv, find_dotenv
4 import os
5 from pprint import pprint
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 api = osmapi.OsmApi(api="https://api06.dev.openstreetmap.org", session=auth.session)
18 empty_notes = api.notes_get(
19 -93.8472901, 35.9763601, -80, 36.176360100000004, limit=1, closed=0
20 )
21 pprint(empty_notes)
22
23
24 # create note and then search for it
25 note = api.note_create(
26 {
27 "lat": 47.3383501,
28 "lon": 8.5339522,
29 "text": "test note",
30 }
31 )
32 test_notes = api.notes_get(8.527504, 47.337063, 8.540679, 47.341673, limit=1, closed=0)
33 pprint(test_notes)
34
35 api.note_comment(note["id"], "Another comment")
36 api.note_close(note["id"], "Close this test note")
37
38 # try to close an already closed note
39 try:
40 api.note_close(note["id"], "Close the note again")
41 except osmapi.NoteAlreadyClosedApiError:
42 print("")
43 print(f"The note {note['id']} has already been closed")
44
45
46 # try to comment on closed note
47 try:
48 api.note_comment(note["id"], "Just a comment")
49 except (osmapi.NoteAlreadyClosedApiError, osmapi.errors.ApiError):
50 print("")
51 print(f"The note {note['id']} is closed, comment no longer possible")