Skip to content

Commit

Permalink
fix source erlangen_hoechstadt_de during year transition
Browse files Browse the repository at this point in the history
  • Loading branch information
mampfes committed Dec 24, 2022
1 parent 141f18b commit d80e74a
Showing 1 changed file with 19 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import requests
import datetime

import requests
from waste_collection_schedule import Collection # type: ignore[attr-defined]
from waste_collection_schedule.service.ICS import ICS

import urllib

TITLE = "Landkreis Erlangen-Höchstadt"
DESCRIPTION = "Source for Landkreis Erlangen-Höchstadt"
URL = "https://www.erlangen-hoechstadt.de/"
TEST_CASES = {
"Höchstadt": {"city": "Höchstadt", "street": "Böhmerwaldstraße"},
"Brand": {"city": "Eckental", "street": "Eckenhaid, Amselweg"},
"Ortsteile": {"city": "Wachenroth", "street": "Wachenroth Ort ink. aller Ortsteile"}
"Ortsteile": {"city": "Wachenroth", "street": "Ort inkl. aller Ortsteile"},
}


Expand All @@ -22,20 +21,25 @@ def __init__(self, city, street):
self._ics = ICS(split_at=" / ")

def fetch(self):
city = self._city.upper()
street = self._street
today = datetime.date.today()
year = today.year

payload = {"ort": city, "strasse": street,
"abfallart": "Alle", "jahr": year}
r = requests.get(
"https://www.erlangen-hoechstadt.de/komx/surface/dfxabfallics/GetAbfallIcs", params=payload
)
r.encoding = r.apparent_encoding
dates = self._ics.convert(r.text)
dates = self.fetch_year(today.year)
if today.month == 12:
dates.extend(self.fetch_year(today.year + 1))

entries = []
for d in dates:
entries.append(Collection(d[0], d[1]))
return entries

def fetch_year(self, year):
city = self._city.upper()
street = self._street

payload = {"ort": city, "strasse": street, "abfallart": "Alle", "jahr": year}
r = requests.get(
"https://www.erlangen-hoechstadt.de/komx/surface/dfxabfallics/GetAbfallIcs",
params=payload,
)
r.raise_for_status()
r.encoding = r.apparent_encoding
return self._ics.convert(r.text)

0 comments on commit d80e74a

Please sign in to comment.