aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Schadt <kingdread@gmx.de>2026-10-01 09:41:55 +0200
committerDaniel Schadt <kingdread@gmx.de>2026-10-01 09:41:55 +0200
commit4a19f38ab4ff54f9e80698482ebc9dce7707ba6f (patch)
treebe02362b2b4cd157eb244cd61dc40874be03d26f
parentad05060f35b72ac188287986863ef359ddcb7f0f (diff)
downloadfietsboek-4a19f38ab4ff54f9e80698482ebc9dce7707ba6f.tar.gz
fietsboek-4a19f38ab4ff54f9e80698482ebc9dce7707ba6f.tar.bz2
fietsboek-4a19f38ab4ff54f9e80698482ebc9dce7707ba6f.zip
use overpass api to name climbs
read-only access via the OSM API is discouraged, so we should use one of the overpass instances instead in the future, it might be good to make the URL configurable, and to allow authenticated access to one of the "private" instances
-rw-r--r--fietsboek/models/climb.py4
-rw-r--r--fietsboek/osm.py24
-rw-r--r--fietsboek/templates/details.jinja22
3 files changed, 21 insertions, 9 deletions
diff --git a/fietsboek/models/climb.py b/fietsboek/models/climb.py
index 8fefa82..baa7a66 100644
--- a/fietsboek/models/climb.py
+++ b/fietsboek/models/climb.py
@@ -59,7 +59,7 @@ class Climb(Base):
path = self.track.path()
return Path(path.points[self.start_index : self.end_index])
- def display_name(self) -> str:
+ def display_name(self) -> str | None:
"""Returns the display name.
If the given name (by the user) is set, returns this. Otherwise, return
@@ -69,7 +69,7 @@ class Climb(Base):
"""
if self.given_name:
return self.given_name
- return self.automatic_name or ""
+ return self.automatic_name
def bounds(self) -> tuple[tuple[float, float], tuple[float, float]]:
"""Returns the bounds of this climb.
diff --git a/fietsboek/osm.py b/fietsboek/osm.py
index e75bd11..436e033 100644
--- a/fietsboek/osm.py
+++ b/fietsboek/osm.py
@@ -1,7 +1,6 @@
"""OSM related utilities for fietsboek."""
import logging
-from urllib.parse import urljoin
from xml.etree import ElementTree
import requests
@@ -10,7 +9,7 @@ from . import __VERSION__
from .geo import Path, Point
LOGGER = logging.getLogger(__name__)
-API_URL = "https://api.openstreetmap.org/"
+OVERPASS_API_URL = "https://maps.mail.ru/osm/tools/overpass/api/interpreter"
HEADERS = {
"user-agent": f"Fietsboek/{__VERSION__}",
"accept-encoding": "gzip;q=1.0, identity;q=0.5",
@@ -22,7 +21,7 @@ MAX_DISTANCE_CITY = 750
MAX_DISTANCE_WATER = 750
-def find_name(path: Path) -> str:
+def find_name(path: Path) -> str | None:
"""Attempt to find a name for the given path.
:param path: Path to find a name for.
@@ -39,13 +38,26 @@ def find_name(path: Path) -> str:
max_lat += 0.001
max_lon += 0.0015
- LOGGER.debug("bbox=%s,%s,%s,%s", min_lon, min_lat, max_lon, max_lat)
+ bbox = f"[bbox:{min_lat},{min_lon},{max_lat},{max_lon}];"
+ LOGGER.debug("Requesting %s", bbox)
- urlpath = f"api/0.6/map?bbox={min_lon},{min_lat},{max_lon},{max_lat}"
- with session.get(urljoin(API_URL, urlpath)) as response:
+ overpass_script = f"""
+ {bbox}\n
+ (node;way;);
+ (._;>;);
+ out;
+ """
+ with session.post(OVERPASS_API_URL, data={"data": overpass_script}) as response:
+ if response.status_code != 200:
+ LOGGER.info(
+ "Error response from overpass: %s %s", response.status_code, response.reason
+ )
+ return None
data = response.content
+ LOGGER.debug("Got %s bytes of OSM-XML data, parsing...", len(data))
tree = ElementTree.fromstring(data)
+ LOGGER.debug("Parsing complete!")
name = _name_from_street(tree, path)
if name is None:
diff --git a/fietsboek/templates/details.jinja2 b/fietsboek/templates/details.jinja2
index a800998..748fc6f 100644
--- a/fietsboek/templates/details.jinja2
+++ b/fietsboek/templates/details.jinja2
@@ -200,7 +200,7 @@
{% for climb in track.climbs %}
<div class="climb card">
<h5 class="card-header">
- {{ climb.display_name() }}
+ {{ climb.display_name() | default(_("page.details.climbs.climb"), true) }}
{% if climb.category is not none %}
<div class="climb-category climb-category-{{ climb.category }}">
{% if climb.category == 0 %}