geoport_nwm_de now supports all collection types from the website

This commit is contained in:
5ila5
2024-01-14 20:30:57 +01:00
committed by 5ila5
parent aa7c430342
commit 467640758a

View File

@@ -16,6 +16,8 @@ TEST_CASES = {
"kl. Bünsdorf": {"district": "Klein Bünsdorf"},
}
API_URL = "https://www.geoport-nwm.de/nwm-download/Abfuhrtermine/ICS/{year}/{arg}.ics"
class Source:
def __init__(self, district):
@@ -45,22 +47,35 @@ class Source:
def fetch_year(self, year):
arg = convert_to_arg(self._district)
r = requests.get(
f"https://www.geoport-nwm.de/nwm-download/Abfuhrtermine/ICS/{year}/{arg}.ics"
)
r = requests.get(API_URL.format(year=year, arg=arg))
r.raise_for_status()
return self._ics.convert(r.text)
entries = self._ics.convert(r.text)
for prefix in (
"Schadstoffmobil",
"Papiertonne_GER",
"Papiertonne_Gollan",
"Papiertonne_Veolia",
):
try:
r = requests.get(API_URL.format(year=year, arg=f"{prefix}_{arg}"))
r.raise_for_status()
new_entries = self._ics.convert(r.text)
entries.extend(new_entries)
except (ValueError, requests.exceptions.HTTPError):
pass
return entries
def convert_to_arg(district):
def convert_to_arg(district, prefix=""):
district = district.replace("(1.100 l Behälter)", "1100_l")
district = district.replace("ü", "ue")
district = district.replace("ö", "oe")
district = district.replace("ä", "ae")
district = district.replace("ß", "ss")
district = district.replace("/", "")
district = district.replace("- ", "-")
# district = district.replace("- ", "-") failed with Seefeld/ Testorf- Steinfort
district = district.replace(".", "")
district = district.replace(" ", "_")
arg = urllib.parse.quote("Ortsteil_" + district)
prefix = prefix + "_" if prefix else ""
arg = urllib.parse.quote(f"{prefix}Ortsteil_{district}")
return arg