mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2026-09-21 06:47:42 +00:00
Partial fix for mypy issues
This commit is contained in:
@@ -4,6 +4,9 @@ from typing import Any
|
||||
|
||||
import requests
|
||||
from fastkml import kml
|
||||
from fastkml.containers import Document, Folder
|
||||
from fastkml.features import Placemark
|
||||
from fastkml.geometry import Point
|
||||
from pyhamtools.locator import latlong_to_locator
|
||||
|
||||
from core.enums import ActivityRefType
|
||||
@@ -26,13 +29,19 @@ class ParksNPeaksKMLActivityRefDataProvider(FileDownloadActivityRefDataProvider)
|
||||
def _http_response_to_data(self, http_response: requests.Response) -> list[ActivityRef]:
|
||||
new_data: list[ActivityRef] = []
|
||||
|
||||
k = kml.KML.from_string(http_response.content)
|
||||
# KML content may carry an XML encoding declaration, which lxml's parser (used internally here) refuses to
|
||||
# accept as a decoded str, so bytes must be passed even though the type stub only declares str.
|
||||
k = kml.KML.from_string(http_response.content) # type: ignore[arg-type]
|
||||
|
||||
for document in k.features:
|
||||
# noinspection unresolved-references
|
||||
if not isinstance(document, Document):
|
||||
continue
|
||||
for folder in document.features:
|
||||
# noinspection unresolved-references
|
||||
if not isinstance(folder, Folder):
|
||||
continue
|
||||
for placemark in folder.features:
|
||||
if not isinstance(placemark, Placemark):
|
||||
continue
|
||||
description = placemark.description or ""
|
||||
match = self.REF_PATTERN.search(description)
|
||||
if not match:
|
||||
@@ -40,6 +49,9 @@ class ParksNPeaksKMLActivityRefDataProvider(FileDownloadActivityRefDataProvider)
|
||||
continue
|
||||
ref_id = match.group(0)
|
||||
|
||||
if not isinstance(placemark.geometry, Point):
|
||||
# Not a point location (e.g. a boundary polygon) - skip it, we can't get a single lat/lon from it
|
||||
continue
|
||||
longitude, latitude = placemark.geometry.x, placemark.geometry.y
|
||||
|
||||
ref = ActivityRef(
|
||||
|
||||
Reference in New Issue
Block a user