From 809f867bb319579dfcd58e75f873d9377e9a5513 Mon Sep 17 00:00:00 2001 From: Wille Marcel Date: Tue, 27 Aug 2024 19:05:31 -0300 Subject: [PATCH] Add user-agent to OSM server requests + bump version (#69) --- CHANGELOG.rst | 7 +++++++ README.rst | 2 +- osmcha/__init__.py | 2 +- osmcha/changeset.py | 25 +++++++++++-------------- 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index de0147d..426891f 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -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 diff --git a/README.rst b/README.rst index 6a8ca4e..f9caca2 100644 --- a/README.rst +++ b/README.rst @@ -6,7 +6,7 @@ It was designed to be used with `osmcha-django `_. +`osmcha-frontend repository `_. .. image:: https://badge.fury.io/py/osmcha.svg :target: http://badge.fury.io/py/osmcha diff --git a/osmcha/__init__.py b/osmcha/__init__.py index f98cd8c..5b4ed73 100644 --- a/osmcha/__init__.py +++ b/osmcha/__init__.py @@ -1,2 +1,2 @@ # osmcha -__version__ = '0.9.1' +__version__ = '0.9.2' diff --git a/osmcha/changeset.py b/osmcha/changeset.py index 253ba98..ee9ad9f 100644 --- a/osmcha/changeset.py +++ b/osmcha/changeset.py @@ -14,6 +14,7 @@ import yaml import requests from shapely.geometry import Polygon +from . import __version__ as version from osmcha.warnings import Warnings @@ -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 @@ -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] @@ -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): @@ -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):