mirror of
https://github.com/sascha-hemi/hacs_waste_collection_schedule.git
synced 2026-03-21 04:06:03 +01:00
geoport_nwm_de now supports all collection types from the website
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user