From 2f3296199cc370a1e16b8e871f650cbd30bbef61 Mon Sep 17 00:00:00 2001 From: mampfes Date: Mon, 20 Mar 2023 09:02:10 +0100 Subject: [PATCH] refactor esch_lu --- README.md | 2 +- .../source/administration_esch_lu.py | 73 ------------------ .../source/esch_lu.py | 77 +++++++++++++++++++ doc/source/administration_esch_lu.md | 68 ---------------- doc/source/esch_lu.md | 36 +++++++++ info.md | 1 + update_docu_links.py | 4 + 7 files changed, 119 insertions(+), 142 deletions(-) delete mode 100644 custom_components/waste_collection_schedule/waste_collection_schedule/source/administration_esch_lu.py create mode 100644 custom_components/waste_collection_schedule/waste_collection_schedule/source/esch_lu.py delete mode 100644 doc/source/administration_esch_lu.md create mode 100644 doc/source/esch_lu.md diff --git a/README.md b/README.md index 58d0f9a1..e10c74db 100644 --- a/README.md +++ b/README.md @@ -269,7 +269,7 @@ Waste collection schedules in the following formats and countries are supported.
Luxembourg -- [Esch-sur-alzette](/doc/source/administration_esch_lu.md) / administration.esch.lu +- [Esch-sur-Alzette](/doc/source/esch_lu.md) / esch.lu
diff --git a/custom_components/waste_collection_schedule/waste_collection_schedule/source/administration_esch_lu.py b/custom_components/waste_collection_schedule/waste_collection_schedule/source/administration_esch_lu.py deleted file mode 100644 index fa2ee5c7..00000000 --- a/custom_components/waste_collection_schedule/waste_collection_schedule/source/administration_esch_lu.py +++ /dev/null @@ -1,73 +0,0 @@ -import datetime -from xml.etree.ElementTree import tostring -from waste_collection_schedule import Collection -import requests -from bs4 import BeautifulSoup - -TITLE = "Esch-sur-Alzette" # Title will show up in README.md and info.md -DESCRIPTION = "Source script for administration.esch.lu, communal website of the city of Esch-sur-Alzette in Luxembourg" # Describe your source -URL = "https://administration.esch.lu" # Insert url to service homepage. URL will show up in README.md and info.md -TEST_CASES = { # Insert arguments for test cases to be used by test_sources.py script - "Zone A": {"zone": 'A'}, - "Zone B": {"zone": 'B'} -} - -API_URL = "https://administration.esch.lu/dechets/?street=0&tour=" -ICON_MAP = { # Optional: Dict of waste types and suitable mdi icons - "Poubelle ménage": "mdi:trash-can", - "Papier": "mdi:newspaper", - "Organique": "mdi:leaf", - "Verre": "mdi:bottle-wine-outline", - "Valorlux": "mdi:recycle", - "Déchets toxiques": "mdi:skull-crossbones", - "Container ménage": "train-car-container" -} - -class Source: - def __init__(self, zone): # argX correspond to the args dict in the source configuration - zones = {'A':'1', - 'B':'2' - } - self._zone = zones[zone] - - def fetch(self): - - #locale.setlocale(locale.LC_ALL, 'fr_FR.UTF-8') # set the French locale to import the dates - response = requests.get(API_URL+str(self._zone)) - soup = BeautifulSoup(response.content, "html.parser") - - # Find the table containing the waste collection schedule - table = soup.find('table', {'id': 'garbage-table'}) - #locale.setlocale(locale.LC_TIME, 'en_US.utf8') # Switch back to English locale - months = { - "janvier": "January", - "février": "February", - "mars": "March", - "avril": "April", - "mai": "May", - "juin": "June", - "juillet": "July", - "août": "August", - "septembre": "September", - "octobre": "October", - "novembre": "November", - "décembre": "December", - } - entries = [] # List that holds collection schedule - for row in table.find_all('tr'): - cells = row.find_all('td') - if len(cells) == 3: - t = cells[1].text.strip() # Collection type - if t.startswith("Cartons en vrac"): - continue # Skip the cardboard collection for companies - if t.startswith("Déchets toxiques"): - t = "Déchets toxiques" # Remove collecting insrtuctions - #locale.setlocale(locale.LC_ALL, 'fr_FR.UTF-8') # set the French locale to import the dates - date_fr = cells[2].text.strip().split(', ')[1] - #print (date_fr) - day, month, year = date_fr.split() - month = months[month] - date = datetime.datetime.strptime(f"{day}-{month}-{year}","%d-%B-%Y").date() # Collection date - icon = ICON_MAP.get(t) - entries.append(Collection(date,t,icon)) - return entries diff --git a/custom_components/waste_collection_schedule/waste_collection_schedule/source/esch_lu.py b/custom_components/waste_collection_schedule/waste_collection_schedule/source/esch_lu.py new file mode 100644 index 00000000..7874a203 --- /dev/null +++ b/custom_components/waste_collection_schedule/waste_collection_schedule/source/esch_lu.py @@ -0,0 +1,77 @@ +import datetime + +from bs4 import BeautifulSoup +from waste_collection_schedule import Collection +# Include work around for SSL UNSAFE_LEGACY_RENEGOTIATION_DISABLED error +from waste_collection_schedule.service.SSLError import get_legacy_session + +TITLE = "Esch-sur-Alzette" +DESCRIPTION = "Source script for administration.esch.lu, communal website of the city of Esch-sur-Alzette in Luxembourg" +URL = "https://esch.lu" +TEST_CASES = {"Zone A": {"zone": "A"}, "Zone B": {"zone": "B"}} + +API_URL = "https://administration.esch.lu/dechets/?street=0&tour=" +ICON_MAP = { # Optional: Dict of waste types and suitable mdi icons + "Poubelle ménage": "mdi:trash-can", + "Papier": "mdi:newspaper", + "Organique": "mdi:leaf", + "Verre": "mdi:bottle-wine-outline", + "Valorlux": "mdi:recycle", + "Déchets toxiques": "mdi:skull-crossbones", + "Container ménage": "train-car-container", +} + +MONTH_NAMES = [ + "janvier", + "février", + "mars", + "avril", + "mai", + "juin", + "juillet", + "août", + "septembre", + "octobre", + "novembre", + "décembre", +] + + +class Source: + def __init__( + self, zone + ): # argX correspond to the args dict in the source configuration + zones = {"A": "1", "B": "2"} + self._zone = zones[zone] + + def fetch(self): + s = get_legacy_session() + + # locale.setlocale(locale.LC_ALL, 'fr_FR.UTF-8') # set the French locale to import the dates + params = { + "street": 0, + "tour": self._zone, + } + r = s.get("https://administration.esch.lu/dechets", params=params) + r.raise_for_status() + soup = BeautifulSoup(r.content, "html.parser") + + # Find the table containing the waste collection schedule + table = soup.find("table", {"id": "garbage-table"}) + + entries = [] # List that holds collection schedule + for row in table.find_all("tr"): + cells = row.find_all("td") + if len(cells) == 3: + t = cells[1].text.strip() # Collection type + if t.startswith("Cartons en vrac"): + continue # Skip the cardboard collection for companies + if t.startswith("Déchets toxiques"): + t = "Déchets toxiques" # Remove collecting instructions + date_fr = cells[2].text.strip().split(", ")[1] + day, month, year = date_fr.split() + date = datetime.datetime( + year=int(year), month=MONTH_NAMES.index(month) + 1, day=int(day) + ).date() + entries.append(Collection(date, t, icon=ICON_MAP.get(t))) + return entries diff --git a/doc/source/administration_esch_lu.md b/doc/source/administration_esch_lu.md deleted file mode 100644 index fde68ba0..00000000 --- a/doc/source/administration_esch_lu.md +++ /dev/null @@ -1,68 +0,0 @@ -# administration.esch.lu -Support for the Esch sur Alzette communal website in Luxembourg. - -## Configuration via configuration.yaml - -```yaml -waste_collection_schedule: - sources: - - name: administration_esch_lu - args: - zone: A -``` -### Configuration Variables - -There is currenly only one conficuration variable, which is *zone*, which accepts only two chars - A or B. - -**zone** -*(char) (required)* - -This variable indicates collection zone. The city is divided by two zones with different collection schedule. -One can identify their zone prior to configuring here: -https://administration.esch.lu/dechets/ - -## Sensor setup -There are following types of garbage parsed: -- Poubelle ménage -- Papier -- Organique -- Verre -- Valorlux -- Déchets toxiques -- Container ménage - -Here is the example of sensors in `configuration.yaml`: - -```yaml -sensor: - - platform: waste_collection_schedule - name: waste_organics - count: 2 - add_days_to: True - types: - - Organique - - platform: waste_collection_schedule - name: waste_glass - add_days_to: True - count: 2 - types: - - Verre - - platform: waste_collection_schedule - name: waste_valorlux - add_days_to: True - count: 2 - types: - - Valorlux - - platform: waste_collection_schedule - name: waste_paper - add_days_to: True - count: 2 - types: - - Papier - - platform: waste_collection_schedule - name: waste_household - add_days_to: True - count: 2 - types: - - Poubelle ménage -``` diff --git a/doc/source/esch_lu.md b/doc/source/esch_lu.md new file mode 100644 index 00000000..73f5034f --- /dev/null +++ b/doc/source/esch_lu.md @@ -0,0 +1,36 @@ +# Esch sur Alzette + +Support for the Esch sur Alzette communal website in Luxembourg. + +## Configuration via configuration.yaml + +```yaml +waste_collection_schedule: + sources: + - name: esch_lu + args: + zone: A +``` + +### Configuration Variables + +There is currently only one conficuration variable, which is *zone*, which accepts only two chars - A or B. + +**zone** +*(char) (required)* + +This variable indicates collection zone. The city is divided by two zones with different collection schedule. +One can identify their zone prior to configuring here: + + +## Sensor setup + +There are following types of garbage parsed: + +- Poubelle ménage +- Papier +- Organique +- Verre +- Valorlux +- Déchets toxiques +- Container ménage \ No newline at end of file diff --git a/info.md b/info.md index ffee392a..41178809 100644 --- a/info.md +++ b/info.md @@ -22,6 +22,7 @@ Waste collection schedules from service provider web sites are updated daily, de | Canada | City of Toronto | | Germany | Abfall Stuttgart, Abfall-Wirtschafts-Verband Nordschwaben, Abfall.IO / AbfallPlus, Abfallbewirtschaftung Ostalbkreis, Abfallkalender Offenbach am Main, Abfallkalender Würzburg, AbfallNavi (RegioIT.de), Abfalltermine Forchheim, Abfallwirtschaft Alb-Donau-Kreis, Abfallwirtschaft Germersheim, Abfallwirtschaft Isar-Inn, Abfallwirtschaft Lahn-Dill-Kreises, Abfallwirtschaft Landkreis Böblingen, Abfallwirtschaft Landkreis Freudenstadt, Abfallwirtschaft Landkreis Harburg, Abfallwirtschaft Landkreis Kitzingen, Abfallwirtschaft Landkreis Landsberg am Lech, Abfallwirtschaft Landkreis Wolfenbüttel, Abfallwirtschaft Neckar-Odenwald-Kreis, Abfallwirtschaft Nürnberger Land, Abfallwirtschaft Ortenaukreis, Abfallwirtschaft Rems-Murr, Abfallwirtschaft Rendsburg, Abfallwirtschaft Rheingau-Taunus-Kreis, Abfallwirtschaft Stadt Fürth, Abfallwirtschaft Stadt Nürnberg, Abfallwirtschaft Stadt Schweinfurt, Abfallwirtschaft Südholstein, Abfallwirtschaft Werra-Meißner-Kreis, Abfallwirtschaft Zollernalbkreis, Abfallwirtschafts-Zweckverband des Landkreises Hersfeld-Rotenburg, Abfallwirtschaftsbetrieb Bergisch Gladbach, Abfallwirtschaftsbetrieb Esslingen, Abfallwirtschaftsbetrieb Landkreis Ahrweiler, Abfallwirtschaftsbetrieb Landkreis Altenkirchen, Abfallwirtschaftsbetrieb Landkreis Augsburg, Abfallwirtschaftsbetrieb Landkreis Aurich, Abfallwirtschaftsverband Kreis Groß-Gerau, ALBA Berlin, ART Trier, ASO Abfall-Service Osterholz, AWA Entsorgungs GmbH, AWB Bad Kreuznach, AWB Köln, AWB Landkreis Bad Dürkheim, AWB Landkreis Fürstenfeldbruck, AWB Landkreis Göppingen, AWB Oldenburg, AWB Westerwaldkreis, AWG Kreis Warendorf, AWIDO Online, Bau & Service Oberursel, Bergischer Abfallwirtschaftverbund, Berlin Recycling, Berliner Stadtreinigungsbetriebe, Bielefeld, Bogenschütz Entsorgung, Bremer Stadtreinigung, Bürgerportal, C-Trace, CM City Media - Müllkalender, Dillingen Saar, Dinslaken, EAD Darmstadt, EGN Abfallkalender, EGST Steinfurt, EGW Westmünsterland, Entsorgungs- und Wirtschaftsbetrieb Landau in der Pfalz, Entsorgungsbetriebe Essen, Gemeinde Aschheim, Gemeinde Blankenheim, Gemeinde Bühlerzell, Gemeinde Deggenhausertal, Gemeinde Kalletal, Gemeinde Kappelrodeck, Gemeinde Kressbronn am Bodensee, Gemeinde Lindlar, Gemeinde Mittelbiberach, Gemeinde Oberstadion, Gemeinde Roetgen, Gemeinde Schutterwald, Gemeinde Senden (Westfalen), Gemeinde Unterhaching, Göttinger Entsorgungsbetriebe, Gütersloh, Halver, Hohenlohekreis, Jumomind, KAEV Niederlausitz, Kreis Coesfeld, Kreis Heinsberg, Kreis Pinneberg, Kreisstadt Dietzenbach, Kreisstadt St. Wendel, Kreiswirtschaftsbetriebe Goslar, KV Cochem-Zell, KWU Entsorgung Landkreis Oder-Spree, Landkreis Ansbach, Landkreis Aschaffenburg, Landkreis Bayreuth, Landkreis Berchtesgadener Land, Landkreis Calw, Landkreis Coburg, Landkreis Erding, Landkreis Erlangen-Höchstadt, Landkreis Fulda, Landkreis Gotha, Landkreis Günzburg, Landkreis Heilbronn, Landkreis Kelheim, Landkreis Kronach, Landkreis Limburg-Weilburg, Landkreis Nordwestmecklenburg, Landkreis Ostallgäu, Landkreis Rhön Grabfeld, Landkreis Rosenheim, Landkreis Rotenburg (Wümme), Landkreis Roth, Landkreis Schweinfurt, Landkreis Schwäbisch Hall, Landkreis Schwäbisch Hall, Landkreis Sigmaringen, Landkreis Südliche Weinstraße, Landkreis Tirschenreuth, Landkreis Tübingen, Landkreis Weißenburg-Gunzenhausen, Landkreis Wittmund, Landkreisbetriebe Neuburg-Schrobenhausen, Landratsamt Aichach-Friedberg, Landratsamt Dachau, Landratsamt Main-Tauber-Kreis, Landratsamt Traunstein, Landratsamt Unterallgäu, Ludwigshafen am Rhein, MZV Biedenkopf, MüllALARM / Schönmackers, Müllmax, Neunkirchen Siegerland, Neustadt a.d. Waldnaab, Pullach im Isartal, RegioEntsorgung Städteregion Aachen, Rhein-Hunsrück Entsorgung (RHE), Rhein-Neckar-Kreis, Sector 27 - Datteln, Marl, Oer-Erkenschwick, Stadt Aachen, Stadt Arnsberg, Stadt Bayreuth, Stadt Cottbus, Stadt Dorsten, Stadt Ehingen, Stadt Emden, Stadt Emmendingen, Stadt Fulda, Stadt Kaufbeuren, Stadt Kraichtal, Stadt Landshut, Stadt Memmingen, Stadt Messstetten, Stadt Norderstedt, Stadt Overath, Stadt Regensburg, Stadt Solingen, Stadt Unterschleißheim, Stadt Willich, Stadtreinigung Dresden, Stadtreinigung Hamburg, Stadtreinigung Leipzig, StadtService Brühl, STL Lüdenscheid, Städteservice Raunheim Rüsselsheim, Südbrandenburgischer Abfallzweckverband, WBO Wirtschaftsbetriebe Oberhausen, Wermelskirchen, WGV Recycling GmbH, Wolfsburger Abfallwirtschaft und Straßenreinigung, WZV Kreis Segeberg, ZAW Darmstadt-Dieburg, Zweckverband Abfallwirtschaft Saale-Orla, Zweckverband Abfallwirtschaft Schwalm-Eder-Kreis, Zweckverband München-Südost | | Lithuania | Kauno švara | +| Luxembourg | Esch-sur-Alzette | | Netherlands | ACV Group, Alpen an den Rijn, Area Afval, Avalex, Avri, Bar Afvalbeheer, 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, HVC Groep, Meerlanden, Mijn Blink, PreZero, Purmerend, RAD BV, Reinigingsbedrijf Midden Nederland, Reinis, Spaarne Landen, Stadswerk 072, Twente Milieu, Waardlanden, Ximmio, ZRD | | New Zealand | Auckland Council, Christchurch City Council, Gore, Invercargill & Southland, Horowhenua District Council, Waipa District Council, Wellington City Council | | Norway | Min Renovasjon, Movar IKS, Oslo Kommune, ReMidt Orkland muni, Stavanger Kommune | diff --git a/update_docu_links.py b/update_docu_links.py index 6b0dc207..2ee4cbe3 100755 --- a/update_docu_links.py +++ b/update_docu_links.py @@ -259,6 +259,10 @@ COUNTRYCODES = [ "code": "lt", "name": "Lithuania", }, + { + "code": "lu", + "name": "Luxembourg", + }, { "code": "nl", "name": "Netherlands",