diff --git a/custom_components/waste_collection_schedule/waste_collection_schedule/source/bsr_de.py b/custom_components/waste_collection_schedule/waste_collection_schedule/source/bsr_de.py index 6284e0b5..e0dfdfca 100644 --- a/custom_components/waste_collection_schedule/waste_collection_schedule/source/bsr_de.py +++ b/custom_components/waste_collection_schedule/waste_collection_schedule/source/bsr_de.py @@ -1,4 +1,5 @@ import urllib.parse +import datetime import requests from waste_collection_schedule import Collection # type: ignore[attr-defined] @@ -91,6 +92,22 @@ class Source: # parse ics file dates = self._ics.convert(r.text) + + now = datetime.datetime.now() + # in nov/dec already fetch a monthly ics for january + # as yearly ics isn't available until the 1. of january. + if now.month in [11, 12]: + args["tab_control"] = "Monat" + args["abf_selectmonth"] = "1 " + str(now.year + 1) + + # create url using private url encoding + encoded = map(lambda key: f"{key}={myquote(str(args[key]))}", args.keys()) + url = "https://www.bsr.de/abfuhrkalender_ajax.php?" + "&".join(encoded) + r = requests.get(url, cookies=cookies) + + # parse ics file + dates.extend (self._ics.convert(r.text) ) + entries = [] for d in dates: entries.append(Collection(d[0], d[1]))