Skip to content

Commit

Permalink
Add user-agent to OSM server requests + bump version (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
willemarcel authored Aug 27, 2024
1 parent f2b0185 commit 809f867
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 16 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Change Log
==========

[0.9.1] - 2024-02-23
* Fix error when a changeset has an empty host value (#66)

[0.9.0] - 2023-08-30
* Make OSM URL configurable + remove unknown iD check (#65)
* Exclude Yandex Panorama written in Russian (#64)

[0.8.6] - 2022-05-04
* Remove travis-ci
* Add tasks.mapwith.ai to iD allowed hosts list
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ It was designed to be used with `osmcha-django <https://github.com/osmcha/osmcha
but also can be used standalone or in other projects.

You can report issues or request new features in the the
`osmcha-frontend repository <https://github.com/mapbox/osmcha-frontend>`_.
`osmcha-frontend repository <https://github.com/osmcha/osmcha-frontend>`_.

.. image:: https://badge.fury.io/py/osmcha.svg
:target: http://badge.fury.io/py/osmcha
Expand Down
2 changes: 1 addition & 1 deletion osmcha/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# osmcha
__version__ = '0.9.1'
__version__ = '0.9.2'
25 changes: 11 additions & 14 deletions osmcha/changeset.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import yaml
import requests
from shapely.geometry import Polygon
from . import __version__ as version

from osmcha.warnings import Warnings

Expand All @@ -35,6 +36,7 @@
default='https://www.openstreetmap.org'
)
OSM_API = '{}/api/0.6'.format(OSM_SERVER_URL)
OSM_REQUEST_HEADERS = {'User-Agent': f'OSMCha osmcha {version}'}
# infosrmation that we get from changeset xml key
MANDATORY_TAGS = ['id', 'user', 'uid', 'bbox', 'created_at', 'comments_count']
# fields that will be removed on the Analyse.get_dict() method
Expand All @@ -55,11 +57,8 @@ def get_user_details(user_id):
"""
reasons = []
try:
url = '{osm_api}/user/{user_id}'.format(
osm_api=OSM_API,
user_id=requests.compat.quote(user_id)
)
user_request = requests.get(url)
url = f'{OSM_API}/user/{requests.compat.quote(user_id)}'
user_request = requests.get(url, headers=OSM_REQUEST_HEADERS)
if user_request.status_code == 200:
user_data = user_request.content
xml_data = ET.fromstring(user_data)[0]
Expand Down Expand Up @@ -101,11 +100,10 @@ def get_changeset(changeset):
Args:
changeset: the id of the changeset.
"""
url = '{}/changeset/{}/download'.format(
OSM_API,
changeset
url = f'{OSM_API}/changeset/{changeset}/download'
return ET.fromstring(
requests.get(url, headers=OSM_REQUEST_HEADERS).content
)
return ET.fromstring(requests.get(url).content)


def get_metadata(changeset):
Expand All @@ -115,11 +113,10 @@ def get_metadata(changeset):
Args:
changeset: the id of the changeset.
"""
url = '{}/changeset/{}'.format(
OSM_API,
changeset
)
return ET.fromstring(requests.get(url).content)[0]
url = f'{OSM_API}/changeset/{changeset}'
return ET.fromstring(
requests.get(url, headers=OSM_REQUEST_HEADERS).content
)[0]


def get_bounds(changeset):
Expand Down

0 comments on commit 809f867

Please sign in to comment.