Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v3.0.0 #26

Merged
merged 50 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
f9143ff
oAuth2 access token support
docentYT Mar 10, 2024
2820958
New status code handler
docentYT Mar 11, 2024
7023303
Fixed duplicated code
docentYT Mar 11, 2024
0b5a515
sequence parameter in ElementTree.iterparse
docentYT Mar 11, 2024
cc66f8f
fix types in `elements` endpoint
docentYT Mar 11, 2024
8e637c1
Fixed return type
docentYT Mar 11, 2024
7d79601
Fix type hints
docentYT Mar 11, 2024
722009d
Fixing `# type: ignore`
docentYT Mar 11, 2024
76070a9
response.text for text/plain
docentYT Mar 11, 2024
0700901
tests update
docentYT Mar 11, 2024
5366c97
Unauthorized and Forbidden exception
docentYT Mar 11, 2024
ce4b014
Update api.py
docentYT Mar 11, 2024
6168a22
lookup table
docentYT Mar 11, 2024
47d7df1
str to int
docentYT Mar 11, 2024
71150fd
Removed brackets from if statements
docentYT Mar 11, 2024
91675c7
diff_parser.py revisited
docentYT Mar 12, 2024
c7cc84d
Update README.md
docentYT Mar 16, 2024
fe89185
Documentation update
docentYT Mar 16, 2024
ca11310
OsmChange_parser_generator and OsmChange_parser as private
docentYT Mar 16, 2024
e2262b8
coverage configuration
docentYT Mar 16, 2024
c1d62ed
Documentation update
docentYT Mar 16, 2024
3a60ede
notes tests and note search empty list
docentYT Mar 17, 2024
2c58924
Update test-requirements.txt
docentYT Mar 17, 2024
a401685
Update API.txt
docentYT Mar 17, 2024
d3405bf
exception
docentYT Mar 17, 2024
582b375
elementType to element_type
docentYT Mar 17, 2024
d588aae
gpx.create()
docentYT Mar 17, 2024
e33ca3a
gpx.update() and GpxFile
docentYT Mar 17, 2024
d4ff4c8
Better imports
docentYT Mar 17, 2024
91d82b9
Create test_gpxFile.py
docentYT Mar 17, 2024
5f52af1
gpx.delete()
docentYT Mar 17, 2024
f0a91e6
Update test_api_gpx.py
docentYT Mar 17, 2024
1fe0127
Update API.txt
docentYT Mar 17, 2024
89839f7
`gpx.get()` to `gpx.get_gps_points()`
docentYT Mar 17, 2024
ad3cc2c
gpx.get_details()
docentYT Mar 18, 2024
ae11b8a
gpx.get_file()
docentYT Mar 18, 2024
a5bbbc3
gpx.list_details()
docentYT Mar 18, 2024
0f6174b
_from_xml() in data_classes
docentYT Mar 18, 2024
37dfc22
Update test_diff.py
docentYT Mar 19, 2024
55e3642
Update diff.py
docentYT Mar 19, 2024
b40dcf3
Update test_note.py
docentYT Mar 19, 2024
fd66e49
# pragma: no cover for asserts that should not happen
docentYT Mar 19, 2024
16c7dcc
Update test_api_elements.py
docentYT Mar 19, 2024
7098282
test_diff
docentYT Mar 19, 2024
bbf33b6
test_api_changeset
docentYT Mar 19, 2024
fa0e642
test_api_changeset
docentYT Mar 19, 2024
d8ec91e
`order` parameter
docentYT Mar 19, 2024
76097a5
Update coverage-badge.svg
docentYT Mar 19, 2024
59e92b4
API.txt remove
docentYT Mar 19, 2024
6598662
v3.0.0
docentYT Mar 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,12 @@
source = src/osm_easy_api/*

[run]
omit = tests/*
omit =
tests/*
*/__init__.py

[report]
exclude_lines =
pragma: no cover
# This covers both typing.TYPE_CHECKING and plain TYPE_CHECKING, with any amount of whitespace
if\s+(typing\.)?TYPE_CHECKING:
74 changes: 0 additions & 74 deletions API.txt

This file was deleted.

64 changes: 52 additions & 12 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,60 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2.2.0]
## [3.0.0] - 2024-03-19
### Added
- Support for `oAuth2`: `access_token` parameter in `Api` class constructor.
- `Unauthorized` exception. (No access token.)
- `Forbidden` exception. (The access token does not support the needed scope or you must be a moderator.)
- `gpx.create()` endpoint.
- `GpxFile` data class.
- `Visibility` enum.
- `gpx.update()` endpoint.
- `gpx.delete()` endpoint.
- `gpx.get_details()` endpoint.
- `gpx.get_file()` endpoint.
- `gpx.list_details()` endpoint.
- `order` parameter in `changeset.get_query()`.

### Fixed
- Types in `elements` endpoint.
- Missing documentation.
- `misc.get_map_in_bbox()` endpoint should not yield `string`.

### Changed
- The way http errors are handled.
- In `elements.get()` endpoint the `element` parameter has been renamed to `element_type`.
- In `elements.history()` endpoint the `element` parameter has been renamed to `element_type`.
- In `elements.version()` endpoint the `element` parameter has been renamed to `element_type`.
- In `elements.getQuery()` endpoint the `element` parameter has been renamed to `element_type`.
- In `elements.relations()` endpoint the `element` parameter has been renamed to `element_type`.
- In `elements.full()` endpoint the `element` parameter has been renamed to `element_type`.
- Type of `user_id` parameter in `changeset.get_query()` was changed from `str` to `int`.
- `OsmChange_parser_generator()` and `OsmChange_parser()` from `diff` module are now 'private' functions. Use `Diff.get()` instead.
- `notes.search()` endpoint throws `LimitsExceeded` exception instead of `ValueError`.
- `page_number` paremeter in `gpx.get()` has now default value 0.
- Now classes are imported from individual modules - not from the main library. See examples in the `README.md`.
- `gpx.get()` renamed to `gpx.get_gps_points()`

### Removed
- Support for `HTTP Basic authentication`: `username` and `password` parameters in `Api` class constructor.
- Most `# type: ignore`.
- `NotAModerator` exception. It is now replaced by `Forbidden` exception.

## [2.2.0] - 2024-02-23
### Added
- Exception for `410` status code in notes endpoint.

## [2.1.1]
## [2.1.1] - 2024-01-04
### Fixed
- Percent-encoding was not applied on texts entered by the user. [#22](https://github.com/docentYT/osm_easy_api/issues/22)

## [2.1.0]
## [2.1.0] - 2023-09-06
### Added
- `TooManyRequests` exception.
- Support for `429` status code in `api.changeset.discussion.comment()`.

## [2.0.0]
## [2.0.0] - 2023-08-29
### Added
- Missing status code handling in `notes.get()`.
- Support for hide note endpoint.
Expand All @@ -35,27 +75,27 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `EmptyResult` api exception, which was used in endpoints `notes`, `user` and `changeset`. From now on when the results are empty an empty list will be returned.
- Unused imports.

## [1.1.1]
## [1.1.1] - 2023-08-03
### Fixed
- Corrected character when adding parameters in endpoint `api.notes.get_bbox()` (from `?` to `&`).
- Fixed the `limit` parameter restrictions in `api.notes.get_bbox()` documentation.

## [1.1.0]
## [1.1.0] - 2023-08-28
### Added
- `limit` parameter for `api.changeset.get_query()` endpoint.

### Fixed
- Corrected character when adding parameters in endpoint `api.changeset.get_query()` (from `;` to `&`).

## [1.0.2]
## [1.0.2] - 2023-07-26
### Fixed
- Auth problems in API when using characters unsupported by latin-1 codec.

## [1.0.1]
## [1.0.1] - 2023-07-24
### Fixed
- `api.notes.create()` created only anonymous notes.

## [1.0.0]
## [1.0.0] - 2023-06-18
### Added
- `to_xml()` method in `OsmChange`.
- `upload()` method in `changeset` `endpoint` has new optional arguments.
Expand All @@ -65,7 +105,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- Private `_to_xml()` method in `OsmChange` is now static.

## [0.4.2]
## [0.4.2] - 2023-06-11

### Changed
- Order of elements in xml generated by `Way._to_xml()`. First tags, then nodes.
Expand All @@ -75,11 +115,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Deleted disused variable in `Node._to_xml()`.
- Fixed incorrect relation parsing of data recived by `full` endpoint.

## [0.4.1]
## [0.4.1] - 2023-05-23
### Changed
- Updated `requests` from `2.28.1` to `2.31.0`.

## [0.4.0]
## [0.4.0] - 2023-05-03
### Added
- `to_dict()` method and `from_dict()` class method to `Note`.
- `to_dict()` method and `from_dict()` class method to `Comment`.
Expand Down
50 changes: 28 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,13 @@

<p align="center"><a href="https://www.openstreetmap.org/user/kwiatek_123">Me on OpenStreetMap</a></p>

Python package for parsing osm diffs and communicating with the OpenStreetMap api. See API.txt for list of supported endpoints.
> Python package for parsing osm diffs and communicating with the OpenStreetMap api.

## What's the point of this package?
### What's the point of this package?

This package was created to provide an easy way to create automated scripts and programs that use diff and/or osm api. The main advantage is the classes (data_classes) that provide data of elements (node, way, relation, OsmChange, etc.) in a readable way and the possibility to use them in diff and api without worrying about missing data or dictionaries. You can easily find nodes in diff, add a tag to them and send the corrected version to osm.

## What next?
The plan is to optimise and improve the code, add support for gpx traces, rss support and overpass api.

# Installation
## Installation

Works on python >= 3.10. (Due to new typehints standard)

Expand All @@ -33,21 +30,26 @@ Install `osm_easy_api` from [PyPi](https://pypi.org/project/osm-easy-api/):
pip install osm_easy_api
```

# Documentation
## Documentation

You can view documentation on [github-pages](https://docentyt.github.io/osm_easy_api/osm_easy_api.html).

Documentation is build using [pdoc](https://pdoc.dev).
To run docs on your machine use preferred command: `pdoc --docformat google --no-show-source osm_easy_api !osm_easy_api.utils`.

# Examples
## OAuth 2.0
Due to the deprecation of HTTP Basic Auth you need an access token to use most api endpoints. To obtain an access token we recommend using https://tools.interactivemaps.xyz/token/.


## Examples

## DIFF
### DIFF

### Print trees
#### Print trees

```py
from osm_easy_api import Node, Diff, Frequency
from osm_easy_api.diff import Diff, Frequency
from osm_easy_api.data_classes import Node

# Download diff from last hour.
d = Diff(Frequency.HOUR)
Expand All @@ -61,10 +63,11 @@ for action, element in gen:
print(action, element.id)
```

### Print incorrectly tagged single tress
#### Print incorrectly tagged single tress

```py
from osm_easy_api import Diff, Frequency, Action, Node
from osm_easy_api.diff import Diff, Frequency
from osm_easy_api.data_classes import Action, Node

d = Diff(Frequency.DAY)

Expand All @@ -81,14 +84,15 @@ Example output:
Node(id = 10208486717, visible = None, version = 1, changeset_id = 129216075, timestamp = 2022-11-22T00:16:44Z, user_id = 17471721, tags = {'leaf_type': 'broadleaved', 'natural': 'wood'}, latitude = 48.6522286, longitude = 12.583809, )
```

## API
### API

### Add missing wikidata tag
#### Add missing wikidata tag

```py
from osm_easy_api import Api, Node, Tags
from osm_easy_api.api import Api
from osm_easy_api.data_classes import Node, Tags

api = Api("https://master.apis.dev.openstreetmap.org", LOGIN, PASSWORD)
api = Api("https://master.apis.dev.openstreetmap.org", ACCESS_TOKEN)

node = api.elements.get(Node, 4296460336) # We are getting Node with id 4296460336 where we want to add a new tag to
node.tags.add("wikidata", "Qexample") # Add a new tag to node.
Expand All @@ -98,11 +102,11 @@ api.elements.update(node, my_changeset) # Send new version of a node to osm
api.changeset.close(my_changeset) # Close changeset.
```

# Notes
## Notes

Note that the following codes do the same thing
```py
from osm_easy_api import Diff, Frequency
from osm_easy_api.diff import Diff, Frequency

d = Diff(Frequency.DAY)

Expand All @@ -113,7 +117,8 @@ for action, element in gen:
print(element)
```
```py
from osm_easy_api import Diff, Frequency, Tags
from osm_easy_api.diff import Diff, Frequency
from osm_easy_api.data_classes import Tags

d = Diff(Frequency.DAY)

Expand All @@ -126,7 +131,8 @@ but the second seems to be faster.

Also you can use OsmChange object if you don't want to use generator
```py
from osm_easy_api import Diff, Frequency, Action, Node
from osm_easy_api.diff import Diff, Frequency
from osm_easy_api.data_classes import Action, Node

d = Diff(Frequency.MINUTE)

Expand All @@ -138,7 +144,7 @@ for node in deleted_nodes:
```
but it can consume large amounts of ram and use of this method is not recommended for large diff's.

# Tests
## Tests

You will need to install `test-requirements.txt`. You can use tox.
To run tests manually use `python -m unittest discover`.
6 changes: 3 additions & 3 deletions coverage-badge.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 5 additions & 5 deletions src/osm_easy_api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
VERSION = "2.2.0"
"""Python package for parsing osm diffs and communicating with the OpenStreetMap api."""
VERSION = "3.0.0"

from .data_classes import *
from .diff import Diff, Frequency

from .api import Api
from . import data_classes
from . import diff
from . import api
8 changes: 7 additions & 1 deletion src/osm_easy_api/api/_URLs.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,13 @@ def __init__(self, base_url: str):
}

self.gpx: Dict[str, str] = {
"get": six_url + "/trackpoints?bbox={left},{bottom},{right},{top}&page={page_number}"
"get_gps_points": six_url + "/trackpoints?bbox={left},{bottom},{right},{top}&page={page_number}",
"create": six_url + "/gpx/create",
"update": six_url + "/gpx/{id}",
"delete": six_url + "/gpx/{id}",
"details": six_url + "/gpx/{id}/details",
"get_file": six_url + "/gpx/{id}/data",
"list": six_url + "/user/gpx_files"
}

self.user: Dict[str, str] = {
Expand Down
Loading
Loading