File: notes.py

package info (click to toggle)
python-osmapi 4.3.0%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 820 kB
  • sloc: python: 3,409; xml: 1,601; makefile: 45; sh: 14
file content (47 lines) | stat: -rw-r--r-- 1,192 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import osmapi
from dotenv import load_dotenv, find_dotenv
import os
from pprint import pprint

load_dotenv(find_dotenv())
user = os.getenv("OSM_USER")
pw = os.getenv("OSM_PASS")

api = osmapi.OsmApi(
    api="https://api06.dev.openstreetmap.org", username=user, password=pw
)
empty_notes = api.NotesGet(
    -93.8472901, 35.9763601, -80, 36.176360100000004, limit=1, closed=0
)
pprint(empty_notes)


# create note and then search for it
note = api.NoteCreate(
    {
        "lat": 47.3383501,
        "lon": 8.5339522,
        "text": "test note",
    }
)
test_notes = api.NotesGet(8.527504, 47.337063, 8.540679, 47.341673, limit=1, closed=0)
pprint(test_notes)


api.NoteComment(note["id"], "Another comment")
api.NoteClose(note["id"], "Close this test note")


# try to close an already closed note
try:
    api.NoteClose(note["id"], "Close the note again")
except osmapi.NoteAlreadyClosedApiError:
    print("")
    print(f"The note {note['id']} has already been closed")

# try to comment on closed note
try:
    api.NoteComment(note["id"], "Just a comment")
except osmapi.NoteAlreadyClosedApiError:
    print("")
    print(f"The note {note['id']} is closed, comment no longer possible")