osmapi.note
Note operations for the OpenStreetMap API.
1""" 2Note operations for the OpenStreetMap API. 3""" 4 5from typing import Any, Optional, TYPE_CHECKING, cast 6from xml.dom.minidom import Element 7 8from . import dom, errors, parser 9 10if TYPE_CHECKING: 11 from .OsmApi import OsmApi 12 13 14class NoteMixin: 15 """Mixin providing note-related operations with pythonic method names.""" 16 17 def notes_get( 18 self: "OsmApi", 19 min_lon: float, 20 min_lat: float, 21 max_lon: float, 22 max_lat: float, 23 limit: int = 100, 24 closed: int = 7, 25 ) -> list[dict[str, Any]]: 26 """ 27 Returns a list of dicts of notes in the specified bounding box. 28 29 The limit parameter defines how many results should be returned. 30 31 closed specifies the number of days a bug needs to be closed 32 to no longer be returned. 33 The value 0 means only open bugs are returned, 34 -1 means all bugs are returned. 35 36 All parameters are optional. 37 """ 38 path = "/api/0.6/notes" 39 params = { 40 "bbox": f"{min_lon:f},{min_lat:f},{max_lon:f},{max_lat:f}", 41 "limit": limit, 42 "closed": closed, 43 } 44 data = self._session._get(path, params=params) 45 return parser.parse_notes(data) 46 47 def note_get(self: "OsmApi", note_id: int) -> dict[str, Any]: 48 """ 49 Returns a note as dict. 50 51 `note_id` is the unique identifier of the note. 52 """ 53 uri = f"/api/0.6/notes/{note_id}" 54 data = self._session._get(uri) 55 note_element = cast( 56 Element, dom.OsmResponseToDom(data, tag="note", single=True) 57 ) 58 return dom.dom_parse_note(note_element) 59 60 def note_create(self: "OsmApi", note_data: dict[str, Any]) -> dict[str, Any]: 61 """ 62 Creates a note based on the supplied `note_data` dict: 63 64 #!python 65 { 66 'lat': latitude of note, 67 'lon': longitude of note, 68 'text': text of the note, 69 } 70 71 Returns updated note data. 72 """ 73 uri = "/api/0.6/notes" 74 return self._note_action(uri, params=note_data) 75 76 def note_comment(self: "OsmApi", note_id: int, comment: str) -> dict[str, Any]: 77 """ 78 Adds a new comment to a note. 79 80 Returns the updated note. 81 """ 82 path = f"/api/0.6/notes/{note_id}/comment" 83 return self._note_action(path, comment) 84 85 def note_close( 86 self: "OsmApi", note_id: int, comment: Optional[str] = None 87 ) -> dict[str, Any]: 88 """ 89 Closes a note. 90 91 Returns the updated note. 92 93 If no authentication information are provided, 94 `OsmApi.UsernamePasswordMissingError` is raised. 95 """ 96 path = f"/api/0.6/notes/{note_id}/close" 97 return self._note_action(path, comment, optional_auth=False) 98 99 def note_reopen( 100 self: "OsmApi", note_id: int, comment: Optional[str] = None 101 ) -> dict[str, Any]: 102 """ 103 Reopens a note. 104 105 Returns the updated note. 106 107 If no authentication information are provided, 108 `OsmApi.UsernamePasswordMissingError` is raised. 109 110 If the requested element has been deleted, 111 `OsmApi.ElementDeletedApiError` is raised. 112 113 If the requested element can not be found, 114 `OsmApi.ElementNotFoundApiError` is raised. 115 """ 116 path = f"/api/0.6/notes/{note_id}/reopen" 117 return self._note_action(path, comment, optional_auth=False) 118 119 def notes_search( 120 self: "OsmApi", query: str, limit: int = 100, closed: int = 7 121 ) -> list[dict[str, Any]]: 122 """ 123 Returns a list of dicts of notes that match the given search query. 124 125 The limit parameter defines how many results should be returned. 126 127 closed specifies the number of days a bug needs to be closed 128 to no longer be returned. 129 The value 0 means only open bugs are returned, 130 -1 means all bugs are returned. 131 """ 132 uri = "/api/0.6/notes/search" 133 params: dict[str, Any] = { 134 "q": query, 135 "limit": limit, 136 "closed": closed, 137 } 138 data = self._session._get(uri, params=params) 139 return parser.parse_notes(data) 140 141 def _note_action( 142 self: "OsmApi", 143 path: str, 144 comment: Optional[str] = None, 145 optional_auth: bool = True, 146 params: Optional[dict[str, Any]] = None, 147 ) -> dict[str, Any]: 148 """ 149 Performs an action on a Note with a comment 150 151 Return the updated note 152 """ 153 uri = path 154 final_params = params.copy() if params else {} 155 if comment is not None: 156 final_params["text"] = comment 157 try: 158 result = self._session._post( 159 uri, 160 None, 161 optionalAuth=optional_auth, 162 params=final_params if final_params else None, 163 ) 164 except errors.ApiError as e: 165 if e.status == 409: 166 raise errors.NoteAlreadyClosedApiError( 167 e.status, e.reason, e.payload 168 ) from e 169 else: 170 raise 171 172 # parse the result 173 note_element = cast( 174 Element, dom.OsmResponseToDom(result, tag="note", single=True) 175 ) 176 return dom.dom_parse_note(note_element)
15class NoteMixin: 16 """Mixin providing note-related operations with pythonic method names.""" 17 18 def notes_get( 19 self: "OsmApi", 20 min_lon: float, 21 min_lat: float, 22 max_lon: float, 23 max_lat: float, 24 limit: int = 100, 25 closed: int = 7, 26 ) -> list[dict[str, Any]]: 27 """ 28 Returns a list of dicts of notes in the specified bounding box. 29 30 The limit parameter defines how many results should be returned. 31 32 closed specifies the number of days a bug needs to be closed 33 to no longer be returned. 34 The value 0 means only open bugs are returned, 35 -1 means all bugs are returned. 36 37 All parameters are optional. 38 """ 39 path = "/api/0.6/notes" 40 params = { 41 "bbox": f"{min_lon:f},{min_lat:f},{max_lon:f},{max_lat:f}", 42 "limit": limit, 43 "closed": closed, 44 } 45 data = self._session._get(path, params=params) 46 return parser.parse_notes(data) 47 48 def note_get(self: "OsmApi", note_id: int) -> dict[str, Any]: 49 """ 50 Returns a note as dict. 51 52 `note_id` is the unique identifier of the note. 53 """ 54 uri = f"/api/0.6/notes/{note_id}" 55 data = self._session._get(uri) 56 note_element = cast( 57 Element, dom.OsmResponseToDom(data, tag="note", single=True) 58 ) 59 return dom.dom_parse_note(note_element) 60 61 def note_create(self: "OsmApi", note_data: dict[str, Any]) -> dict[str, Any]: 62 """ 63 Creates a note based on the supplied `note_data` dict: 64 65 #!python 66 { 67 'lat': latitude of note, 68 'lon': longitude of note, 69 'text': text of the note, 70 } 71 72 Returns updated note data. 73 """ 74 uri = "/api/0.6/notes" 75 return self._note_action(uri, params=note_data) 76 77 def note_comment(self: "OsmApi", note_id: int, comment: str) -> dict[str, Any]: 78 """ 79 Adds a new comment to a note. 80 81 Returns the updated note. 82 """ 83 path = f"/api/0.6/notes/{note_id}/comment" 84 return self._note_action(path, comment) 85 86 def note_close( 87 self: "OsmApi", note_id: int, comment: Optional[str] = None 88 ) -> dict[str, Any]: 89 """ 90 Closes a note. 91 92 Returns the updated note. 93 94 If no authentication information are provided, 95 `OsmApi.UsernamePasswordMissingError` is raised. 96 """ 97 path = f"/api/0.6/notes/{note_id}/close" 98 return self._note_action(path, comment, optional_auth=False) 99 100 def note_reopen( 101 self: "OsmApi", note_id: int, comment: Optional[str] = None 102 ) -> dict[str, Any]: 103 """ 104 Reopens a note. 105 106 Returns the updated note. 107 108 If no authentication information are provided, 109 `OsmApi.UsernamePasswordMissingError` is raised. 110 111 If the requested element has been deleted, 112 `OsmApi.ElementDeletedApiError` is raised. 113 114 If the requested element can not be found, 115 `OsmApi.ElementNotFoundApiError` is raised. 116 """ 117 path = f"/api/0.6/notes/{note_id}/reopen" 118 return self._note_action(path, comment, optional_auth=False) 119 120 def notes_search( 121 self: "OsmApi", query: str, limit: int = 100, closed: int = 7 122 ) -> list[dict[str, Any]]: 123 """ 124 Returns a list of dicts of notes that match the given search query. 125 126 The limit parameter defines how many results should be returned. 127 128 closed specifies the number of days a bug needs to be closed 129 to no longer be returned. 130 The value 0 means only open bugs are returned, 131 -1 means all bugs are returned. 132 """ 133 uri = "/api/0.6/notes/search" 134 params: dict[str, Any] = { 135 "q": query, 136 "limit": limit, 137 "closed": closed, 138 } 139 data = self._session._get(uri, params=params) 140 return parser.parse_notes(data) 141 142 def _note_action( 143 self: "OsmApi", 144 path: str, 145 comment: Optional[str] = None, 146 optional_auth: bool = True, 147 params: Optional[dict[str, Any]] = None, 148 ) -> dict[str, Any]: 149 """ 150 Performs an action on a Note with a comment 151 152 Return the updated note 153 """ 154 uri = path 155 final_params = params.copy() if params else {} 156 if comment is not None: 157 final_params["text"] = comment 158 try: 159 result = self._session._post( 160 uri, 161 None, 162 optionalAuth=optional_auth, 163 params=final_params if final_params else None, 164 ) 165 except errors.ApiError as e: 166 if e.status == 409: 167 raise errors.NoteAlreadyClosedApiError( 168 e.status, e.reason, e.payload 169 ) from e 170 else: 171 raise 172 173 # parse the result 174 note_element = cast( 175 Element, dom.OsmResponseToDom(result, tag="note", single=True) 176 ) 177 return dom.dom_parse_note(note_element)
Mixin providing note-related operations with pythonic method names.
18 def notes_get( 19 self: "OsmApi", 20 min_lon: float, 21 min_lat: float, 22 max_lon: float, 23 max_lat: float, 24 limit: int = 100, 25 closed: int = 7, 26 ) -> list[dict[str, Any]]: 27 """ 28 Returns a list of dicts of notes in the specified bounding box. 29 30 The limit parameter defines how many results should be returned. 31 32 closed specifies the number of days a bug needs to be closed 33 to no longer be returned. 34 The value 0 means only open bugs are returned, 35 -1 means all bugs are returned. 36 37 All parameters are optional. 38 """ 39 path = "/api/0.6/notes" 40 params = { 41 "bbox": f"{min_lon:f},{min_lat:f},{max_lon:f},{max_lat:f}", 42 "limit": limit, 43 "closed": closed, 44 } 45 data = self._session._get(path, params=params) 46 return parser.parse_notes(data)
Returns a list of dicts of notes in the specified bounding box.
The limit parameter defines how many results should be returned.
closed specifies the number of days a bug needs to be closed to no longer be returned. The value 0 means only open bugs are returned, -1 means all bugs are returned.
All parameters are optional.
48 def note_get(self: "OsmApi", note_id: int) -> dict[str, Any]: 49 """ 50 Returns a note as dict. 51 52 `note_id` is the unique identifier of the note. 53 """ 54 uri = f"/api/0.6/notes/{note_id}" 55 data = self._session._get(uri) 56 note_element = cast( 57 Element, dom.OsmResponseToDom(data, tag="note", single=True) 58 ) 59 return dom.dom_parse_note(note_element)
Returns a note as dict.
note_id is the unique identifier of the note.
61 def note_create(self: "OsmApi", note_data: dict[str, Any]) -> dict[str, Any]: 62 """ 63 Creates a note based on the supplied `note_data` dict: 64 65 #!python 66 { 67 'lat': latitude of note, 68 'lon': longitude of note, 69 'text': text of the note, 70 } 71 72 Returns updated note data. 73 """ 74 uri = "/api/0.6/notes" 75 return self._note_action(uri, params=note_data)
Creates a note based on the supplied note_data dict:
#!python
{
'lat': latitude of note,
'lon': longitude of note,
'text': text of the note,
}
Returns updated note data.
77 def note_comment(self: "OsmApi", note_id: int, comment: str) -> dict[str, Any]: 78 """ 79 Adds a new comment to a note. 80 81 Returns the updated note. 82 """ 83 path = f"/api/0.6/notes/{note_id}/comment" 84 return self._note_action(path, comment)
Adds a new comment to a note.
Returns the updated note.
86 def note_close( 87 self: "OsmApi", note_id: int, comment: Optional[str] = None 88 ) -> dict[str, Any]: 89 """ 90 Closes a note. 91 92 Returns the updated note. 93 94 If no authentication information are provided, 95 `OsmApi.UsernamePasswordMissingError` is raised. 96 """ 97 path = f"/api/0.6/notes/{note_id}/close" 98 return self._note_action(path, comment, optional_auth=False)
Closes a note.
Returns the updated note.
If no authentication information are provided,
OsmApi.UsernamePasswordMissingError is raised.
100 def note_reopen( 101 self: "OsmApi", note_id: int, comment: Optional[str] = None 102 ) -> dict[str, Any]: 103 """ 104 Reopens a note. 105 106 Returns the updated note. 107 108 If no authentication information are provided, 109 `OsmApi.UsernamePasswordMissingError` is raised. 110 111 If the requested element has been deleted, 112 `OsmApi.ElementDeletedApiError` is raised. 113 114 If the requested element can not be found, 115 `OsmApi.ElementNotFoundApiError` is raised. 116 """ 117 path = f"/api/0.6/notes/{note_id}/reopen" 118 return self._note_action(path, comment, optional_auth=False)
Reopens a note.
Returns the updated note.
If no authentication information are provided,
OsmApi.UsernamePasswordMissingError is raised.
If the requested element has been deleted,
OsmApi.ElementDeletedApiError is raised.
If the requested element can not be found,
OsmApi.ElementNotFoundApiError is raised.
120 def notes_search( 121 self: "OsmApi", query: str, limit: int = 100, closed: int = 7 122 ) -> list[dict[str, Any]]: 123 """ 124 Returns a list of dicts of notes that match the given search query. 125 126 The limit parameter defines how many results should be returned. 127 128 closed specifies the number of days a bug needs to be closed 129 to no longer be returned. 130 The value 0 means only open bugs are returned, 131 -1 means all bugs are returned. 132 """ 133 uri = "/api/0.6/notes/search" 134 params: dict[str, Any] = { 135 "q": query, 136 "limit": limit, 137 "closed": closed, 138 } 139 data = self._session._get(uri, params=params) 140 return parser.parse_notes(data)
Returns a list of dicts of notes that match the given search query.
The limit parameter defines how many results should be returned.
closed specifies the number of days a bug needs to be closed to no longer be returned. The value 0 means only open bugs are returned, -1 means all bugs are returned.