Skip to content

Commit

Permalink
Wikimedia commons support multiple values, Compile regex
Browse files Browse the repository at this point in the history
  • Loading branch information
Zaczero committed Sep 24, 2024
1 parent c0a4f58 commit fa51aa7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
6 changes: 3 additions & 3 deletions api/v1/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

router = APIRouter()

photo_id_re = re.compile(r'view/(?P<id>\S+)\.')
_photo_id_re = re.compile(r'view/(?P<id>\S+)\.')


def _get_timezone(x: float, y: float) -> tuple[str | None, str | None]:
Expand All @@ -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
):
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
7 changes: 5 additions & 2 deletions planet_diffs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'</(create|modify|delete)>')


@trace
async def get_planet_diffs(last_update: float) -> tuple[Sequence[dict], float]:
Expand Down Expand Up @@ -98,6 +101,6 @@ def _format_actions(xml: str) -> str:
# <create> -> <action type="create">
# </create> -> </action>
# etc.
xml = re.sub(r'<(create|modify|delete)>', r'<action type="\1">', xml)
xml = re.sub(r'</(create|modify|delete)>', r'</action>', xml)
xml = _action_open_re.sub(r'<action type="\1">', xml)
xml = _action_close_re.sub(r'</action>', xml)
return xml

0 comments on commit fa51aa7

Please sign in to comment.