From fa51aa772681a355f197e82528e9c975c09509a1 Mon Sep 17 00:00:00 2001 From: Kamil Monicz Date: Tue, 24 Sep 2024 18:43:31 +0000 Subject: [PATCH] Wikimedia commons support multiple values, Compile regex --- api/v1/node.py | 6 +++--- config.py | 2 +- planet_diffs.py | 7 +++++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/api/v1/node.py b/api/v1/node.py index 3532f99..72253f6 100644 --- a/api/v1/node.py +++ b/api/v1/node.py @@ -15,7 +15,7 @@ router = APIRouter() -photo_id_re = re.compile(r'view/(?P\S+)\.') +_photo_id_re = re.compile(r'view/(?P\S+)\.') def _get_timezone(x: float, y: float) -> tuple[str | None, str | None]: @@ -38,7 +38,7 @@ async def _get_image_data(tags: dict[str, str]) -> dict: if ( image_url - and (photo_id_match := photo_id_re.search(image_url)) + and (photo_id_match := _photo_id_re.search(image_url)) and (photo_id := photo_id_match.group('id')) and (await PhotoService.get_by_id(photo_id)) is not None ): @@ -55,7 +55,7 @@ async def _get_image_data(tags: dict[str, str]) -> dict: '@photo_source': image_url, } - wikimedia_commons: str = tags.get('wikimedia_commons', '') + wikimedia_commons: str = tags.get('wikimedia_commons', '').partition(';')[0] if wikimedia_commons: return { diff --git a/config.py b/config.py index 708a3f4..00978f8 100644 --- a/config.py +++ b/config.py @@ -7,7 +7,7 @@ from pyproj import Transformer NAME = 'openaedmap-backend' -VERSION = '2.11.0' +VERSION = '2.11.1' CREATED_BY = f'{NAME} {VERSION}' WEBSITE = 'https://openaedmap.org' diff --git a/planet_diffs.py b/planet_diffs.py index ffdda30..10d5680 100644 --- a/planet_diffs.py +++ b/planet_diffs.py @@ -12,6 +12,9 @@ from utils import http_get, retry_exponential from xmltodict_postprocessor import xmltodict_postprocessor +_action_open_re = re.compile(r'<(create|modify|delete)>') +_action_close_re = re.compile(r'') + @trace async def get_planet_diffs(last_update: float) -> tuple[Sequence[dict], float]: @@ -98,6 +101,6 @@ def _format_actions(xml: str) -> str: # -> # -> # etc. - xml = re.sub(r'<(create|modify|delete)>', r'', xml) - xml = re.sub(r'', r'', xml) + xml = _action_open_re.sub(r'', xml) + xml = _action_close_re.sub(r'', xml) return xml