diff --git a/custom_components/waste_collection_schedule/waste_collection_schedule/source/karlsruhe_de.py b/custom_components/waste_collection_schedule/waste_collection_schedule/source/karlsruhe_de.py index 91d6fa7fa..60e86b5d5 100644 --- a/custom_components/waste_collection_schedule/waste_collection_schedule/source/karlsruhe_de.py +++ b/custom_components/waste_collection_schedule/waste_collection_schedule/source/karlsruhe_de.py @@ -1,8 +1,9 @@ +import datetime +import re + import requests -from waste_collection_schedule import Collection # type: ignore[attr-defined] from bs4 import BeautifulSoup -import re -import datetime +from waste_collection_schedule import Collection # type: ignore[attr-defined] TITLE = "City of Karlsruhe" DESCRIPTION = "Source for City of Karlsruhe." @@ -10,16 +11,20 @@ TEST_CASES = { "Östliche Rheinbrückenstraße 1": { "street": "Östliche Rheinbrückenstraße", - "hnr": 1 + "hnr": 1, + }, + "Habichtweg 4": {"street": "Habichtweg", "hnr": "4"}, + "Machstraße 5": {"street": "Machstraße", "hnr": "5"}, + "Bernsteinstraße 10 ladeort 1": { + "street": "Bernsteinstraße", + "hnr": "10", + "ladeort": "1", }, - "Habichtweg 4": { - "street": "Habichtweg", - "hnr": "4" + "Bernsteinstraße 10 ladeort 2": { + "street": "Bernsteinstraße", + "hnr": 10, + "ladeort": 2, }, - "Machstraße 5": { - "street": "Machstraße", - "hnr": "5" - } } @@ -28,7 +33,7 @@ "Bioabfall": "mdi:leaf", "Papier": "mdi:package-variant", "Wertstoff": "mdi:recycle", - "Sperrmüllabholung": "mdi:wardrobe" + "Sperrmüllabholung": "mdi:wardrobe", } @@ -36,14 +41,16 @@ class Source: - def __init__(self, street: str, hnr: str | int): + def __init__(self, street: str, hnr: str | int, ladeort: int | None = None): self._street: str = street self._hnr: str | int = hnr + self._ladeort: int | None = ladeort def fetch(self): args = { "strasse_n": self._street, "hausnr": self._hnr, + "ladeort": self._ladeort, "anzeigen": "anzeigen", } @@ -60,7 +67,7 @@ def fetch(self): for row in rows: bin_type = row.find("div", class_="col_3-2") - if bin_type == None: + if bin_type is None: continue bin_type = bin_type.contents[0].text.split(",")[0].strip() @@ -68,10 +75,10 @@ def fetch(self): bin_type = bin_type[:-1].strip() pickup_col = row.find("div", class_="col_3-3") - if pickup_col == None or not pickup_col.contents: + if pickup_col is None or not pickup_col.contents: pickup_col = row.find("div", class_="col_4-3") - if pickup_col == None or not pickup_col.contents: + if pickup_col is None or not pickup_col.contents: continue for date in re.findall(r"\d{2}\.\d{2}\.\d{4}", pickup_col.text): diff --git a/doc/source/karlsruhe_de.md b/doc/source/karlsruhe_de.md index 88bca3923..3360dcbe9 100644 --- a/doc/source/karlsruhe_de.md +++ b/doc/source/karlsruhe_de.md @@ -11,6 +11,7 @@ waste_collection_schedule: args: street: STRAßE hnr: "HAUSNUMMER" + ladeort: LADEORT ``` @@ -22,9 +23,16 @@ waste_collection_schedule: **hnr** *(String | Integer) (required)* +**ladeort** +*(String | Integer) (optional)* +only needed for some very limited addresses + ## Example + +### without `ladeort` + ```yaml waste_collection_schedule: sources: @@ -34,6 +42,18 @@ waste_collection_schedule: hnr: 1 ``` +```yaml +waste_collection_schedule: + sources: + - name: karlsruhe_de + args: + street: Bernsteinstraße + hnr: 10 + ladeort: 2 +``` + ## How to get the source argument Find the parameter of your address using [https://web6.karlsruhe.de/service/abfall/akal/akal.php](https://web6.karlsruhe.de/service/abfall/akal/akal.php) and write them exactly like on the web page. + +`ladeort` is only required if the website prompts for a "Abholplatz". `ladeort` is the Number of the drop down element behind "Abholplatz" (e.g. 1 for the first element of the drop down menu, 2 for the second item of the drop down menu ...)