diff --git a/README.md b/README.md index 1bd1f6d1..b9cfe4e0 100644 --- a/README.md +++ b/README.md @@ -571,7 +571,7 @@ Waste collection schedules in the following formats and countries are supported. - [Abfall Stuttgart](/doc/source/stuttgart_de.md) / service.stuttgart.de - [Abfall-Wirtschafts-Verband Nordschwaben](/doc/source/awido_de.md) / awv-nordschwaben.de - [Abfall.IO / AbfallPlus](/doc/source/abfall_io.md) / abfallplus.de -- [Abfallbehandlungsgesellschaft Havelland mbH (abh)](/doc/ics/abfall_havelland_de.md) / abfall-havelland.de +- [Abfallbehandlungsgesellschaft Havelland mbH (abh)](/doc/source/abfall_havelland_de.md) / abfall-havelland.de - [Abfallbewirtschaftung Ostalbkreis](/doc/source/abfall_io.md) / goa-online.de - [Abfallentsorgung Kreis Kassel](/doc/ics/abfall_kreis_kassel_de.md) / abfall-kreis-kassel.de - [Abfallkalender Hattingen](/doc/source/insert_it_de.md) / insert-it.de/BmsAbfallkalenderHattingen diff --git a/custom_components/waste_collection_schedule/waste_collection_schedule/source/abfall_havelland_de.py b/custom_components/waste_collection_schedule/waste_collection_schedule/source/abfall_havelland_de.py new file mode 100644 index 00000000..2bd7d5fa --- /dev/null +++ b/custom_components/waste_collection_schedule/waste_collection_schedule/source/abfall_havelland_de.py @@ -0,0 +1,61 @@ +# There was an ICS source but the ICS file was not stored permanently and would be removed after a few days. +import requests +from bs4 import BeautifulSoup, Tag +from waste_collection_schedule import Collection # type: ignore[attr-defined] +from waste_collection_schedule.service.ICS import ICS + +TITLE = "Abfallbehandlungsgesellschaft Havelland mbH (abh)" +DESCRIPTION = "Source for Abfallbehandlungsgesellschaft Havelland mbH." +URL = "https://abfall-havelland.de/" +TEST_CASES = { + "Wustermark Drosselgasse": { + "ort": "Wustermark", + "strasse": "Drosselgasse", + }, + "Milow Friedhofstr.": {"ort": "Milow", "strasse": "Friedhofstr."}, +} + + +ICON_MAP = { + "mülltonne": "mdi:trash-can", + "bio-tonne": "mdi:leaf", + "papier": "mdi:package-variant", + "gelbe": "mdi:recycle", +} + + +API_URL = "https://www.abfall-havelland.de//groups/public/modules/ajax_tourenplan.php" +BASE_URL = "https://www.abfall-havelland.de/" + + +class Source: + def __init__(self, ort: str, strasse: str): + self._ort: str = ort + self._strasse: str = strasse + self._ics = ICS(split_at=", ") + + def fetch(self) -> list[Collection]: + args = {"city": self._ort, "street": self._strasse} + + # get json file + r = requests.get(API_URL, params=args) + r.raise_for_status() + soup = BeautifulSoup(r.text, "html.parser") + ics_link_tag = soup.find("a", id="ical") + if not isinstance(ics_link_tag, Tag): + raise Exception("No ics link found") + ics_link = ics_link_tag.attrs["onclick"].split("'")[1] + if not isinstance(ics_link, str): + raise Exception("No ics link found") + r = requests.get(BASE_URL + ics_link) + r.raise_for_status() + r.encoding = "utf-8" + dates = self._ics.convert(r.text) + entries = [] + for d in dates: + bin_type = d[1].replace(" - Abholtermin", "") + entries.append( + Collection(d[0], bin_type, ICON_MAP.get(bin_type.split()[0].lower())) + ) + + return entries diff --git a/doc/ics/abfall_havelland_de.md b/doc/ics/abfall_havelland_de.md deleted file mode 100644 index 8885cb63..00000000 --- a/doc/ics/abfall_havelland_de.md +++ /dev/null @@ -1,22 +0,0 @@ -# Abfallbehandlungsgesellschaft Havelland mbH (abh) - -Abfallbehandlungsgesellschaft Havelland mbH (abh) is supported by the generic [ICS](/doc/source/ics.md) source. For all available configuration options, please refer to the source description. - - -## How to get the configuration arguments - -- Goto and select your location. -- Click on `Export der Kalenderdaten` to download the .ics file, then copy the download link of the downloaded file. If your browser does not support to directly copy the download url you can use the developer tools there you can find the path of the file in the onklick section of the a tag for the download button. -- Replace the `url` in the example configuration with this link. - -## Examples - -### Brieselang, Am Nest - -```yaml -waste_collection_schedule: - sources: - - name: ics - args: - url: https://www.abfall-havelland.de/UserFiles/Files/Abfuhrtermine%20Am%20Nest%20Brieselang.ics -``` diff --git a/doc/ics/yaml/abfall_havelland_de.yaml b/doc/ics/yaml/abfall_havelland_de.yaml deleted file mode 100644 index 0484fd00..00000000 --- a/doc/ics/yaml/abfall_havelland_de.yaml +++ /dev/null @@ -1,9 +0,0 @@ -title: Abfallbehandlungsgesellschaft Havelland mbH (abh) -url: https://www.abfall-havelland.de/ -howto: | - - Goto and select your location. - - Click on `Export der Kalenderdaten` to download the .ics file, then copy the download link of the downloaded file. If your browser does not support to directly copy the download url you can use the developer tools there you can find the path of the file in the onklick section of the a tag for the download button. - - Replace the `url` in the example configuration with this link. -test_cases: - Brieselang, Am Nest: - url: "https://www.abfall-havelland.de/UserFiles/Files/Abfuhrtermine%20Am%20Nest%20Brieselang.ics" diff --git a/doc/source/abfall_havelland_de.md b/doc/source/abfall_havelland_de.md new file mode 100644 index 00000000..ed4511e2 --- /dev/null +++ b/doc/source/abfall_havelland_de.md @@ -0,0 +1,39 @@ +# Abfallbehandlungsgesellschaft Havelland mbH + +Support for schedules provided by [Abfallbehandlungsgesellschaft Havelland mbH](https://abfall-havelland.de/), serving Havelland, Germany. + +## Configuration via configuration.yaml + +```yaml +waste_collection_schedule: + sources: + - name: abfall_havelland_de + args: + ort: ORT + strasse: STRAßE + +``` + +### Configuration Variables + +**ort** +*(String) (required)* + +**strasse** +*(String) (required)* + +## Example + +```yaml +waste_collection_schedule: + sources: + - name: abfall_havelland_de + args: + ort: Wustermark + strasse: Drosselgasse + +``` + +## How to get the source argument + +Find the parameter of your address using [https://www.abfall-havelland.de/index.php?page_id=543](https://www.abfall-havelland.de/index.php?page_id=543) and write them exactly like on the web page. diff --git a/doc/source/ics.md b/doc/source/ics.md index dce9dfc4..cbbd9903 100644 --- a/doc/source/ics.md +++ b/doc/source/ics.md @@ -153,7 +153,6 @@ This source has been successfully tested with the following service providers: - [Aballwirtschaft Ludwigslust-Parchim AöR](/doc/ics/alp_lup_de.md) / alp-lup.de - [Abfall App](/doc/ics/abfall_app_net.md) / abfall-app.net - [Abfall IO ICS Version](/doc/ics/abfall_io_ics.md) / abfallplus.de -- [Abfallbehandlungsgesellschaft Havelland mbH (abh)](/doc/ics/abfall_havelland_de.md) / abfall-havelland.de - [Abfallentsorgung Kreis Kassel](/doc/ics/abfall_kreis_kassel_de.md) / abfall-kreis-kassel.de - [Abfallwirtschaft Dithmarschen (AWD)](/doc/ics/awd_online_de.md) / awd-online.de - [Abfallwirtschaft Enzkreis](/doc/ics/entsorgung_regional_de.md) / entsorgung-regional.de