From 5d5b1d9868598d8379dcc52f10a1f72796455551 Mon Sep 17 00:00:00 2001 From: tj551955 <74710010+tj551955@users.noreply.github.com> Date: Fri, 13 Dec 2024 11:44:09 +0100 Subject: [PATCH] Create sbazb_de.py This is the missing source file for SBAZV, Germany --- .../source/sbazb_de.py | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 custom_components/waste_collection_schedule/waste_collection_schedule/source/sbazb_de.py diff --git a/custom_components/waste_collection_schedule/waste_collection_schedule/source/sbazb_de.py b/custom_components/waste_collection_schedule/waste_collection_schedule/source/sbazb_de.py new file mode 100644 index 000000000..3d7126805 --- /dev/null +++ b/custom_components/waste_collection_schedule/waste_collection_schedule/source/sbazb_de.py @@ -0,0 +1,64 @@ +import logging +import requests +from waste_collection_schedule import Collection # type: ignore[attr-defined] +from waste_collection_schedule.service.ICS import ICS + +TITLE = "Südbrandenburgischer Abfallzweckverband" +DESCRIPTION = "SBAZV Brandenburg, Deutschland" +URL = "https://www.sbazv.de" +TEST_CASES = { + "Schönefeld": {"url": "https://fahrzeuge.sbazv.de/WasteManagementSuedbrandenburg/WasteManagementServiceServlet?ApplicationName=Calendar&SubmitAction=sync&StandortID=1385852001&AboID=23187&Fra=P;R;WB;L;GS"}, +} + +ICON_MAP = { + "Restmülltonnen": "mdi:trash-can", + "Laubsäcke": "mdi:leaf", + "Gelbe Säcke": "mdi:sack", + "Papiertonnen": "mdi:package-variant", + "Weihnachtsbäume": "mdi:pine-tree", +} + +_LOGGER = logging.getLogger(__name__) + +PARAM_TRANSLATIONS = {} +# "de": { +# "city": "Ort", +# "district": "Ortsteil", +# "street": "Straße", +# }, +#} + + +class Source: + def __init__(self, url): + self._url = url + self._ics = ICS() + + def fetch(self): + + # get ics file + # https://fahrzeuge.sbazv.de/WasteManagementSuedbrandenburg/WasteManagementServiceServlet?ApplicationName=Calendar&SubmitAction=sync&StandortID=1448170001&AboID=12386&Fra=P;R;WB;L;GS + # https://www.sbazv.de/entsorgungstermine/klein.ics?city=Wildau&district=Wildau&street=Miersdorfer+Str. + r = requests.get(self._url) + + # parse ics file + dates = self._ics.convert(r.text) + + entries = [] + for d in dates: + waste_type = d[1].strip() + next_pickup_date = d[0] + # remove duplicates + if any( + e.date == next_pickup_date and e.type == waste_type for e in entries + ): + continue + entries.append( + Collection( + date=next_pickup_date, + t=waste_type, + icon=ICON_MAP.get(waste_type), + ) + ) + + return entries