From 467e99ac8198e324a33692c15f724fc6d0414177 Mon Sep 17 00:00:00 2001 From: Dean Kannenberg Date: Mon, 6 Jan 2025 17:35:20 +0100 Subject: [PATCH] Adding PreZero Bad Oeynhausen as new source --- README.md | 1 + .../waste_collection_schedule/sources.json | 6 +++ .../translations/de.json | 22 +++++++++ .../translations/en.json | 22 +++++++++ .../translations/it.json | 22 +++++++++ .../source/prezero_bad_oeynhausen.py | 47 +++++++++++++++++++ doc/source/prezero_bad_oeynhausen.md | 36 ++++++++++++++ 7 files changed, 156 insertions(+) create mode 100644 custom_components/waste_collection_schedule/waste_collection_schedule/source/prezero_bad_oeynhausen.py create mode 100644 doc/source/prezero_bad_oeynhausen.md diff --git a/README.md b/README.md index 17f5ca65d..91883bf91 100644 --- a/README.md +++ b/README.md @@ -1228,6 +1228,7 @@ If your service provider is not listed, feel free to open a [source request issu - [Ostprignitz-Ruppin](/doc/source/app_abfallplus_de.md) / Abfall+ App: app - [Plettenberg](/doc/source/lobbe_app.md) / lobbe.app - [Potsdam](/doc/source/potsdam_de.md) / potsdam.de +- [PreZero Bad Oeynhausen](/doc/source/prezero_bad_oeynhausen.md) / abfallkalender.prezero.network/bad-oeynhausen - [Prignitz](/doc/source/app_abfallplus_de.md) / Abfall+ App: abfallwecker - [Prignitz](/doc/source/app_abfallplus_de.md) / Abfall+ App: unterallgaeu - [Prignitz](/doc/source/app_abfallplus_de.md) / Abfall+ App: willkommen diff --git a/custom_components/waste_collection_schedule/sources.json b/custom_components/waste_collection_schedule/sources.json index 141011df3..58c9bf5cd 100644 --- a/custom_components/waste_collection_schedule/sources.json +++ b/custom_components/waste_collection_schedule/sources.json @@ -7945,6 +7945,12 @@ "default_params": {}, "id": "potsdam_de" }, + { + "title": "PreZero Bad Oeynhausen", + "module": "prezero_bad_oeynhausen", + "default_params": {}, + "id": "prezero_bad_oeynhausen" + }, { "title": "Prignitz", "module": "app_abfallplus_de", diff --git a/custom_components/waste_collection_schedule/translations/de.json b/custom_components/waste_collection_schedule/translations/de.json index 0ca7723cd..d90fdf1d5 100644 --- a/custom_components/waste_collection_schedule/translations/de.json +++ b/custom_components/waste_collection_schedule/translations/de.json @@ -10849,6 +10849,28 @@ "voivodeship": "Voivodeship" }, "data_description": {} + }, + "args_prezero_bad_oeynhausen": { + "title": "Quelle konfigurieren", + "description": "Konfiguriere deinen Service Provider. Mehr details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/prezero_bad_oeynhausen.md", + "data": { + "calendar_title": "Kalender Titel", + "street": "street", + "houseNo": "houseNo" + }, + "data_description": { + "calendar_title": "Ein lesbarerer oder benutzerfreundlicherer Name für den Müllkalender. Wenn nichts angegeben wird, wird der Name der Quelle verwendet." + } + }, + "reconfigure_prezero_bad_oeynhausen": { + "title": "Quelle Neu Konfigurieren", + "description": "Konfiguriere deinen Service Provider. Mehr details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/prezero_bad_oeynhausen.md", + "data": { + "calendar_title": "Kalender Titel", + "street": "street", + "houseNo": "houseNo" + }, + "data_description": {} }, "args_pronatura_bydgoszcz_pl": { "title": "Quelle konfigurieren", diff --git a/custom_components/waste_collection_schedule/translations/en.json b/custom_components/waste_collection_schedule/translations/en.json index ada2c07c6..3a231bacd 100644 --- a/custom_components/waste_collection_schedule/translations/en.json +++ b/custom_components/waste_collection_schedule/translations/en.json @@ -10881,6 +10881,28 @@ }, "data_description": {} }, + "args_prezero_bad_oeynhausen": { + "title": "Configure Source", + "description": "Configure your service provider. More details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/prezero_bad_oeynhausen.md", + "data": { + "calendar_title": "Kalender Title", + "street": "street", + "houseNo": "houseNo" + }, + "data_description": { + "calendar_title": "A more readable, or user-friendly, name for the waste calendar. If nothing is provided, the name returned by the source will be used." + } + }, + "reconfigure_prezero_bad_oeynhausen": { + "title": "Reconfigure Source", + "description": "Configure your service provider. More details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/prezero_bad_oeynhausen.md", + "data": { + "calendar_title": "Kalender Title", + "street": "street", + "houseNo": "houseNo" + }, + "data_description": {} + }, "args_pronatura_bydgoszcz_pl": { "title": "Configure Source", "description": "Configure your service provider. More details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/pronatura_bydgoszcz_pl.md.", diff --git a/custom_components/waste_collection_schedule/translations/it.json b/custom_components/waste_collection_schedule/translations/it.json index 9c46d49ae..6777c046e 100644 --- a/custom_components/waste_collection_schedule/translations/it.json +++ b/custom_components/waste_collection_schedule/translations/it.json @@ -10811,6 +10811,28 @@ }, "data_description": {} }, + "args_prezero_bad_oeynhausen": { + "title": "Configurazione Sorgente", + "description": "Compila i campi per ottenere le informazioni sul tuo servizio di raccolta. Per maggiori informazioni: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/prezero_bad_oeynhausen.md", + "data": { + "calendar_title": "Nome Calendario", + "street": "street", + "houseNo": "houseNo" + }, + "data_description": { + "calendar_title": "Puoi cambiare il nome del calendario della raccolta dei rifiuti, altrimenti di default verra' utilizzato il nome del tuo fornitore di servizi." + } + }, + "reconfigure_prezero_bad_oeynhausen": { + "title": "Riconfigurazione Sorgente", + "description": "Compila i campi per ottenere le informazioni sul tuo servizio di raccolta. Per maggiori informazioni: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/prezero_bad_oeynhausen.md", + "data": { + "calendar_title": "Nome Calendario", + "street": "street", + "houseNo": "houseNo" + }, + "data_description": {} + }, "args_pronatura_bydgoszcz_pl": { "title": "Configurazione Sorgente", "description": "Compila i campi per ottenere le informazioni sul tuo servizio di raccolta. Maggiori informazioni: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/pronatura_bydgoszcz_pl.md.", diff --git a/custom_components/waste_collection_schedule/waste_collection_schedule/source/prezero_bad_oeynhausen.py b/custom_components/waste_collection_schedule/waste_collection_schedule/source/prezero_bad_oeynhausen.py new file mode 100644 index 000000000..818090caa --- /dev/null +++ b/custom_components/waste_collection_schedule/waste_collection_schedule/source/prezero_bad_oeynhausen.py @@ -0,0 +1,47 @@ +import requests +from waste_collection_schedule import Collection # type: ignore[attr-defined] +from waste_collection_schedule.service.ICS import ICS +from bs4 import BeautifulSoup + +TITLE = "Abfallkalender Stadt Bad Oeynhausen" +DESCRIPTION = "Waste collection schedule for Bad Oeynhausen." +URL = "https://abfallkalender.prezero.network/bad-oeynhausen" +TEST_CASES = { + "street": "Eidingsen", + "houseNo": "6" +} + +class Source: + def __init__(self, street, houseNo): + self._street = street + self._houseNo = houseNo + self._ics = ICS() + + def fetch(self): + args = {"street": self._street, "houseNo": self._houseNo} + + response = requests.post(URL, data=args, verify=False) + + if response.status_code == 200: + soup = BeautifulSoup(response.text, 'html.parser') + + ical_form = soup.find('form', {'action': True, 'class': 'ical'}) + if not ical_form: + raise ValueError("iCal form not found on the page.") + + ical_url = "https://abfallkalender.prezero.network" + ical_form['action'] + + ical_response = requests.post(ical_url, data=args, verify=False) + if ical_response.status_code != 200: + raise ValueError(f"Failed to download iCal. Status code: {ical_response.status_code}") + + ical_data = ical_response.content.decode('utf-8') + + dates = self._ics.convert(ical_data) + entries = [] + for d in dates: + entries.append(Collection(d[0], d[1])) + + return entries + else: + raise ValueError(f"Failed to fetch calendar page. Status code: {response.status_code}") diff --git a/doc/source/prezero_bad_oeynhausen.md b/doc/source/prezero_bad_oeynhausen.md new file mode 100644 index 000000000..a83a9cecd --- /dev/null +++ b/doc/source/prezero_bad_oeynhausen.md @@ -0,0 +1,36 @@ +# PreZero Bad Oeynhausen + +Add support for schedules provided by [PreZero Bad Oeynhausen](https://abfallkalender.prezero.network/bad-oeynhausen). + +## Configuration via configuration.yaml + +```yaml +waste_collection_schedule: + sources: + - name: prezero_bad_oeynhausen + args: + street: "Eidingsen" + houseNo: "2" +``` + +### Configuration Variables + +**street** +*(string) (required)* + +**houseNo** +*(string) (required)* + +## Example + +```yaml +waste_collection_schedule: + sources: + - name: prezero_bad_oeynhausen + args: + street: "Eidingsen" +``` + +## How to get the source arguments + +Just add your Street Name and House Number and add your iCal.