From 73916ab1244cb5c178b7b47e5611b863b61d543b Mon Sep 17 00:00:00 2001 From: szyszkowink <103653472+szyszkowink@users.noreply.github.com> Date: Wed, 18 Sep 2024 13:34:54 +0200 Subject: [PATCH] add Eko tom pl (#2703) * Add files via upload * Add files via upload * Add files via upload * reformatting + remove carrier returns * ./update_docu_links.py --------- Co-authored-by: 5ila5 <5ila5@users.noreply.github.com> Co-authored-by: 5ila5 <38183212+5ila5@users.noreply.github.com> --- README.md | 1 + .../waste_collection_schedule/sources.json | 6 + .../translations/de.json | 24 ++++ .../translations/en.json | 24 ++++ .../translations/it.json | 24 ++++ .../source/eko_tom_pl.py | 103 ++++++++++++++++++ doc/source/eko_tom_pl.md | 52 +++++++++ info.md | 2 +- 8 files changed, 235 insertions(+), 1 deletion(-) create mode 100644 custom_components/waste_collection_schedule/waste_collection_schedule/source/eko_tom_pl.py create mode 100644 doc/source/eko_tom_pl.md diff --git a/README.md b/README.md index 8d783039..60d7abeb 100644 --- a/README.md +++ b/README.md @@ -1455,6 +1455,7 @@ If your service provider is not listed, feel free to open a [source request issu - [App Moje Odpady](/doc/source/moje_odpady_pl.md) / moje-odpady.pl - [Bydgoszcz Pronatura](/doc/source/pronatura_bydgoszcz_pl.md) / pronatura.bydgoszcz.pl +- [Czerwonak, Murowana Goślina, Oborniki](/doc/source/eko_tom_pl.md) / eko-tom.pl - [Ecoharmonogram](/doc/source/ecoharmonogram_pl.md) / ecoharmonogram.pl - [Gmina Miękinia](/doc/source/gmina_miekinia_pl.md) / api.skycms.com.pl - [Koziegłowy/Objezierze/Oborniki](/doc/source/sepan_remondis_pl.md) / sepan.remondis.pl diff --git a/custom_components/waste_collection_schedule/sources.json b/custom_components/waste_collection_schedule/sources.json index aeb907f6..40e5e5ba 100644 --- a/custom_components/waste_collection_schedule/sources.json +++ b/custom_components/waste_collection_schedule/sources.json @@ -9387,6 +9387,12 @@ "default_params": {}, "id": "pronatura_bydgoszcz_pl" }, + { + "title": "Czerwonak, Murowana Go\u015blina, Oborniki", + "module": "eko_tom_pl", + "default_params": {}, + "id": "eko_tom_pl" + }, { "title": "Ecoharmonogram", "module": "ecoharmonogram_pl", diff --git a/custom_components/waste_collection_schedule/translations/de.json b/custom_components/waste_collection_schedule/translations/de.json index 48d867c0..435d09ad 100644 --- a/custom_components/waste_collection_schedule/translations/de.json +++ b/custom_components/waste_collection_schedule/translations/de.json @@ -15523,6 +15523,30 @@ "green_seasonal": "Ankreuzen, wenn die Grünen Tonnen nur saisonal geleert werden", "municipality": "Name der Gemeinde, sollte mit dem Namen auf https://www.abfall-lro.de/de/abfuhrtermine/ übereinstimmen (einschließlich Unterregion in Klammern)" } + }, + "args_eko_tom_pl": { + "title": "Quelle konfigurieren", + "description": "Konfiguriere deinen Service Provider. Mehr details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/eko_tom_pl.md", + "data": { + "calendar_title": "Kalender Titel", + "city": "Stadt", + "nr": "Nr", + "street": "Straße" + }, + "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_eko_tom_pl": { + "title": "Quelle Neu Konfigurieren", + "description": "Konfiguriere deinen Service Provider. Mehr details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/eko_tom_pl.md", + "data": { + "calendar_title": "Kalender Titel", + "city": "Stadt", + "nr": "Nr", + "street": "Straße" + }, + "data_description": {} } }, "error": { diff --git a/custom_components/waste_collection_schedule/translations/en.json b/custom_components/waste_collection_schedule/translations/en.json index be6371cb..bb7b00a6 100644 --- a/custom_components/waste_collection_schedule/translations/en.json +++ b/custom_components/waste_collection_schedule/translations/en.json @@ -15523,6 +15523,30 @@ "green_seasonal": "Check if the green bins are only collected seasonally", "municipality": "Name of the municipality, should match the name shown https://www.abfall-lro.de/de/abfuhrtermine/ (including sub region in bracktes)" } + }, + "args_eko_tom_pl": { + "title": "Configure Source", + "description": "Configure your service provider. More details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/eko_tom_pl.md.", + "data": { + "calendar_title": "Calendar Title", + "city": "City", + "nr": "Nr", + "street": "Street" + }, + "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_eko_tom_pl": { + "title": "Reconfigure Source", + "description": "Configure your service provider. More details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/eko_tom_pl.md.", + "data": { + "calendar_title": "Calendar Title", + "city": "City", + "nr": "Nr", + "street": "Street" + }, + "data_description": {} } }, "error": { diff --git a/custom_components/waste_collection_schedule/translations/it.json b/custom_components/waste_collection_schedule/translations/it.json index 175a3766..e984c97d 100644 --- a/custom_components/waste_collection_schedule/translations/it.json +++ b/custom_components/waste_collection_schedule/translations/it.json @@ -15498,6 +15498,30 @@ "municipality": "Municipality" }, "data_description": {} + }, + "args_eko_tom_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/eko_tom_pl.md.", + "data": { + "calendar_title": "Nome Calendario", + "city": "Città", + "nr": "Nr", + "street": "Strada" + }, + "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_eko_tom_pl": { + "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/eko_tom_pl.md.", + "data": { + "calendar_title": "Nome Calendario", + "city": "Città", + "nr": "Nr", + "street": "Strada" + }, + "data_description": {} } }, "error": { diff --git a/custom_components/waste_collection_schedule/waste_collection_schedule/source/eko_tom_pl.py b/custom_components/waste_collection_schedule/waste_collection_schedule/source/eko_tom_pl.py new file mode 100644 index 00000000..f3c49f56 --- /dev/null +++ b/custom_components/waste_collection_schedule/waste_collection_schedule/source/eko_tom_pl.py @@ -0,0 +1,103 @@ +# This source uses the already existing API for c_trace but with some name changes and it does not use the ical file, so it got its own source file. + +import datetime +import logging + +import requests as req +from bs4 import BeautifulSoup +from waste_collection_schedule import Collection # type: ignore[attr-defined] + +_LOOGGER = logging.getLogger(__name__) + +TITLE = "Czerwonak, Murowana Goślina, Oborniki" +DESCRIPTION = ( + "Source for eko-tom.pl. Municipalities: Czerwonak, Murowana Goślina, Oborniki" +) +URL = "https://www.eko-tom.pl" + +TEST_CASES = { + "Czerwonak": {"city": "Czerwonak", "street": "Źródlana", "nr": "39"}, + "BIAŁĘŻYN": {"city": "BIAŁĘŻYN", "street": "BIAŁĘŻYN", "nr": "1/A"}, +} + +API_URL = "https://web.c-trace.de/zmgoappoznan-abfallkalender/(S(y4svzozvtdtmjsfx4szqhvc5))/kalendarzodpadow/abc?Ort={city}&Strasse={street}&Hausnr={nr}" + +ICON_MAP = { + "Zmieszane": "mdi:trash-can", # Mixed + "Tworzywa": "mdi:recycle", # Plastic + "BIO": "mdi:leaf", # Organic + "Papier": "mdi:file-outline", # Paper + "Szkło": "mdi:glass-fragile", # Glass + "Gabaryty": "mdi:dump-truck", # Bulky Waste +} + + +class Source: + def __init__(self, street, city, nr): + self._city = city + self._street = street + self._nr = nr + + def fetch(self): + address = API_URL.format(city=self._city, street=self._street, nr=self._nr) + response = req.get(address) + + if response.status_code != 200: + print(f"Error fetching data from {address}: {response.status_code}") + return [] + + soup = BeautifulSoup(response.text, "html.parser") + + entries = [] + + waste_types = { + "plan rest clear": "Zmieszane", + "glas": "Szkło", + "plastik": "Tworzywa", + "bio": "BIO", + "papier": "Papier", + "plan sperr clear": "Gabaryty", + } + + for waste_class, waste_type in waste_types.items(): + try: + for li in soup.find(class_=waste_class).find_all("li"): + date_text = li.text.strip() + date_format = "%d.%m.%Y" + cleaned_date_text = ( + date_text.replace("\r", "") + .replace("\n", "") + .replace("pon.,", "") + .replace("wt.,", "") + .replace("sr.,", "") + .replace("śr.,", "") + .replace("czw.,", "") + .replace("pt.,", "") + .replace("sob.,", "") + .replace("nie.,", "") + .strip() + ) + date_str = str( + datetime.datetime.strptime( + cleaned_date_text, date_format + ).date() + ) + + try: + entries.append( + Collection( + date=datetime.datetime.strptime( + date_str, "%Y-%m-%d" + ).date(), + t=waste_type, + icon=ICON_MAP.get(waste_type), + ) + ) + + except ValueError: + _LOOGGER.debug(f"Error converting date string: {date_text}") + + except AttributeError: + _LOOGGER.debug(f"No data found for waste type: {waste_type}") + + return entries diff --git a/doc/source/eko_tom_pl.md b/doc/source/eko_tom_pl.md new file mode 100644 index 00000000..72dff7ca --- /dev/null +++ b/doc/source/eko_tom_pl.md @@ -0,0 +1,52 @@ +# eko-tom.pl + +Support for schedules provided by [eko-tom.pl](https://eko-tom.pl/) + +## Configuration via configuration.yaml + +```yaml +waste_collection_schedule: + sources: + - name: eko_tom_pl + args: + city: Czerwonak # Enter the name of your city or village + street: Źródlana # If there is no street, enter the village name + nr: 39 # Enter the house number, check the correct nr of your home at eko-tom.pl/harmonogramy-odbiorow/ +``` + +### Configuration Variables + +**city** +*(string) (required)* + +**street** +*(string) (required)* + +**nr** +*(string) (required)* + +## Examples + +```yaml +waste_collection_schedule: + sources: + - name: eko_tom_pl + args: + city: MUROWANA GOŚLINA + street: MODRZEWIOWA + nr: 1/, 2, 3, 4, 5, 6, 7, 8, 9, 10 +``` + +```yaml +waste_collection_schedule: + sources: + - name: eko_tom_pl + args: + city: BIAŁĘŻYN + street: BIAŁĘŻYN + nr: 1/A +``` + +## How to get the source argument + +Open [eko-tom.pl](https://eko-tom.pl/harmonogramy-odbiorow/) and select your address from the dropdown menu. "Typ Lokalizacji:" and "Typ Zabudowy:" are pointless. diff --git a/info.md b/info.md index fde084c0..45e629ba 100644 --- a/info.md +++ b/info.md @@ -32,7 +32,7 @@ Waste collection schedules from service provider web sites are updated daily, de | Netherlands | 's-Hertogenbosch, ACV Group, Afvalstoffendienst.nl, Alpen an den Rijn, Altena, Area Afval, Avalex, Avri, Bar Afvalbeheer, Bernheze, Circulus, Cyclus NV, Dar, Den Haag, GAD, Gemeente Almere, Gemeente Berkelland, Gemeente Cranendonck, Gemeente Hellendoorn, Gemeente Lingewaard, Gemeente Meppel, Gemeente Middelburg + Vlissingen, Gemeente Peel en Maas, Gemeente Schouwen-Duiveland, Gemeente Sudwest-Fryslan, Gemeente Venray, Gemeente Voorschoten, Gemeente Waalre, Gemeente Westland, Goes, Heusden, HVC Groep, Meerlanden, Mijn Blink, Oisterwijk, PreZero, Purmerend, RAD BV, Rd4, Reinis, Spaarnelanden, Twente Milieu, Vught, Waardlanden, Ximmio, ZRD, Ôffalkalinder van Noardeast-Fryslân & Dantumadiel | | New Zealand | Auckland Council, Christchurch City Council, Dunedin District Council, Gore, Invercargill & Southland, Hamilton City Council, Horowhenua District Council, Hutt City Council, Napier City Council, Porirua City, Rotorua Lakes Council, Tauranga City Council, Waipa District Council, Wellington City Council | | Norway | BIR (Bergensområdets Interkommunale Renovasjonsselskap), Fosen Renovasjon, IRiS, Min Renovasjon, Movar IKS, Oslo Kommune, ReMidt Orkland muni, Sandnes Kommune, Stavanger Kommune, Trondheim | -| Poland | App Moje Odpady, Bydgoszcz Pronatura, Ecoharmonogram, Gmina Miękinia, Koziegłowy/Objezierze/Oborniki, MPGK Katowice, Poznań, Warsaw, Wrocław | +| Poland | App Moje Odpady, Bydgoszcz Pronatura, Czerwonak, Murowana Goślina, Oborniki, Ecoharmonogram, Gmina Miękinia, Koziegłowy/Objezierze/Oborniki, MPGK Katowice, Poznań, Warsaw, Wrocław | | Slovenia | Moji odpadki, Ljubljana | | Sweden | Affärsverken, Boden, Borås Energi och Miljö, EDPEvent - Multi Source, Gästrike Återvinnare, Jönköping - June Avfall & Miljö, Kretslopp Sydost, Landskrona - Svalövs Renhållning, Lerum Vatten och Avlopp, Linköping - Tekniska Verken, Luleå, Lund Waste Collection, Mölndal, Norrtalje Vatten & Avfall, North / Middle Bohuslän - Rambo AB, Region Gotland, Ronneby Miljöteknik, Roslagsvatten, Samverkan Återvinning Miljö (SÅM), Skellefteå, SRV Återvinning, SSAM (Deprecated), SSAM Södra Smalånds Avfall & Miljö, Sysav Sophämntning, Uppsala Vatten, Uppsala Vatten och Avfall AB (Deprecated), VA Syd Sophämntning, VIVAB Sophämtning, Västervik Miljö & Energi | | Switzerland | A-Region, Alchenstorf, Andwil, Appenzell, Berg, Bühler, Canton of Zürich, Eggersriet, Gais, Gaiserwald, Gasel, Goldach, Grosswangen, Grub, Heiden, Herisau, Horn, Hundwil, Häggenschwil, Köniz, Köniz, Liebefeld, Lindau, Lutzenberg, Mittelhäusern, Muolen, Mörschwil, Münchenstein, Münsingen BE, Switzerland, Nieder-/Oberscherli, Niederwangen, Oberwangen, Rapperswil, Real Luzern, Real Luzern, Rehetobel, Rorschach, Rorschacherberg, Sammelkalender.ch, Schliern, Schwellbrunn, Schönengrund, Speicher, Spiegel, Stadt Bülach, Stein, Steinach, Teufen, Thal, Thörishaus, Trogen, Tübach, Untereggen, Urnäsch, Wabern, Wald, Waldkirch, Waldstatt, Winterthur, Wittenbach, Wolfhalden, ZAKU Entsorgung, Zeba, ZKRI |