| @@ -1,15 +1,13 @@ | |||||
| #!/usr/bin/env python3 | #!/usr/bin/env python3 | ||||
| import re | import re | ||||
| from typing import Union | |||||
| from kosmorrolib import Position | from kosmorrolib import Position | ||||
| from openlocationcode import openlocationcode | |||||
| from .i18n.utils import _ | from .i18n.utils import _ | ||||
| def _parse_latitude_longitude(from_str: str) -> Position: | |||||
| def get_position(from_str: str) -> Position: | |||||
| if not re.search(r"^([\d.-]+)[,;]([\d.-]+)$", from_str): | if not re.search(r"^([\d.-]+)[,;]([\d.-]+)$", from_str): | ||||
| raise ValueError(_("The given position (%s) is not valid." % from_str)) | raise ValueError(_("The given position (%s) is not valid." % from_str)) | ||||
| @@ -18,31 +16,3 @@ def _parse_latitude_longitude(from_str: str) -> Position: | |||||
| latitude_longitude = from_str.split(",") | latitude_longitude = from_str.split(",") | ||||
| return Position(float(latitude_longitude[0]), float(latitude_longitude[1])) | return Position(float(latitude_longitude[0]), float(latitude_longitude[1])) | ||||
| def _parse_plus_code(from_str: str) -> Union[None, Position]: | |||||
| if not openlocationcode.isValid(from_str): | |||||
| return None | |||||
| if not openlocationcode.isFull(from_str): | |||||
| raise ValueError( | |||||
| _( | |||||
| "The given Plus Code seems to be a short code, please provide a full code." | |||||
| ) | |||||
| ) | |||||
| pos = openlocationcode.decode(from_str) | |||||
| return Position( | |||||
| latitude=(pos.latitudeLo + pos.latitudeHi) / 2, | |||||
| longitude=(pos.longitudeLo + pos.longitudeHi) / 2, | |||||
| ) | |||||
| def get_position(from_str: str) -> Position: | |||||
| pos = _parse_plus_code(from_str) | |||||
| if pos is not None: | |||||
| return pos | |||||
| return _parse_latitude_longitude(from_str) | |||||
| @@ -8,7 +8,7 @@ msgid "" | |||||
| msgstr "" | msgstr "" | ||||
| "Project-Id-Version: PROJECT VERSION\n" | "Project-Id-Version: PROJECT VERSION\n" | ||||
| "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" | "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" | ||||
| "POT-Creation-Date: 2025-11-11 11:06+0100\n" | |||||
| "POT-Creation-Date: 2025-12-16 17:42+0100\n" | |||||
| "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" | "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" | ||||
| "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" | "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" | ||||
| "Language-Team: LANGUAGE <LL@li.org>\n" | "Language-Team: LANGUAGE <LL@li.org>\n" | ||||
| @@ -242,15 +242,11 @@ msgid "" | |||||
| "{accepted_extensions}" | "{accepted_extensions}" | ||||
| msgstr "" | msgstr "" | ||||
| #: kosmorro/geolocation.py:14 | |||||
| #: kosmorro/geolocation.py:12 | |||||
| #, python-format | #, python-format | ||||
| msgid "The given position (%s) is not valid." | msgid "The given position (%s) is not valid." | ||||
| msgstr "" | msgstr "" | ||||
| #: kosmorro/geolocation.py:30 | |||||
| msgid "The given Plus Code seems to be a short code, please provide a full code." | |||||
| msgstr "" | |||||
| #: kosmorro/i18n/strings.py:21 | #: kosmorro/i18n/strings.py:21 | ||||
| #, python-format | #, python-format | ||||
| msgid "%s is in opposition" | msgid "%s is in opposition" | ||||
| @@ -292,17 +292,6 @@ files = [ | |||||
| {file = "numpy-2.3.4.tar.gz", hash = "sha256:a7d018bfedb375a8d979ac758b120ba846a7fe764911a64465fd87b8729f4a6a"}, | {file = "numpy-2.3.4.tar.gz", hash = "sha256:a7d018bfedb375a8d979ac758b120ba846a7fe764911a64465fd87b8729f4a6a"}, | ||||
| ] | ] | ||||
| [[package]] | |||||
| name = "openlocationcode" | |||||
| version = "1.0.1" | |||||
| description = "Python library for Open Location Code (Plus Codes)" | |||||
| optional = false | |||||
| python-versions = "*" | |||||
| groups = ["main"] | |||||
| files = [ | |||||
| {file = "openlocationcode-1.0.1.tar.gz", hash = "sha256:6fc0108a8214b65d74964105bd69645a8a7529237f0de6aadcfa83cc3373b359"}, | |||||
| ] | |||||
| [[package]] | [[package]] | ||||
| name = "packaging" | name = "packaging" | ||||
| version = "25.0" | version = "25.0" | ||||
| @@ -577,4 +566,4 @@ tests = ["pytest", "pytest-cov"] | |||||
| [metadata] | [metadata] | ||||
| lock-version = "2.1" | lock-version = "2.1" | ||||
| python-versions = "^3.12" | python-versions = "^3.12" | ||||
| content-hash = "d4dd7d19d1de138ba3d096ebce8edd3c1452be9d96180fa63b5e4558a30f9bf7" | |||||
| content-hash = "c33cbfcaa71cda73ea0da8548d0d9300d030509d89c3bd3a642d8db37240dfc6" | |||||
| @@ -21,7 +21,6 @@ termcolor = "^3.0" | |||||
| kosmorrolib = "^1.0" | kosmorrolib = "^1.0" | ||||
| python-dateutil = "^2.8" | python-dateutil = "^2.8" | ||||
| Babel = "^2.9" | Babel = "^2.9" | ||||
| openlocationcode = "^1.0" | |||||
| pytz = "^2025.2" | pytz = "^2025.2" | ||||
| argcomplete = "^3.6.2" | argcomplete = "^3.6.2" | ||||