diff --git a/README.md b/README.md index 757660ce..5004ec10 100644 --- a/README.md +++ b/README.md @@ -667,6 +667,7 @@ Waste collection schedules in the following formats and countries are supported. - [Muolen](/doc/source/a_region_ch.md) / a-region.ch - [Mörschwil](/doc/source/a_region_ch.md) / a-region.ch - [Münchenstein](/doc/source/muenchenstein_ch.md) / muenchenstein.ch +- [Real Luzern](/doc/source/real_luzern_ch.md) / real-luzern.ch - [Rehetobel](/doc/source/a_region_ch.md) / a-region.ch - [Rorschach](/doc/source/a_region_ch.md) / a-region.ch - [Rorschacherberg](/doc/source/a_region_ch.md) / a-region.ch diff --git a/custom_components/waste_collection_schedule/waste_collection_schedule/source/real_luzern_ch.py b/custom_components/waste_collection_schedule/waste_collection_schedule/source/real_luzern_ch.py new file mode 100644 index 00000000..30e362bb --- /dev/null +++ b/custom_components/waste_collection_schedule/waste_collection_schedule/source/real_luzern_ch.py @@ -0,0 +1,84 @@ +import datetime +from waste_collection_schedule import Collection + +import requests +from bs4 import BeautifulSoup + +TITLE = "Real Luzern" +DESCRIPTION = "Source script for Real Luzern, Switzerland" +URL = "https://www.real-luzern.ch" + +TEST_CASES = { + "Luzern - Heimatweg": {"municipality_id": 13, "street_id": 766}, + "Luzern - Pliatusblick": {"municipality_id": 13, "street_id": 936}, + "Emmen": {"municipality_id": 6} +} + +ICON_MAP = { + "Kehricht": "mdi:trash-can", + "Grüngut": "mdi:leaf", + "Papier": "mdi:newspaper-variant-multiple", + "Karton": "mdi:package-variant", + "Altmetall": "mdi:clippy", + # "Altmetall": "mdi:engine", +} + +GERMAN_MONTH_STRING_TO_INT = { + "Januar": 1, + "Februar": 2, + "März": 3, + "April": 4, + "Mai": 5, + "Juni": 6, + "Juli": 7, + "August": 8, + "September": 9, + "Oktober": 10, + "November": 11, + "Dezember": 12, +} + + +API_URL = "https://www.real-luzern.ch/abfall/sammeldienst/abfallkalender/" + + +class Source: + def __init__(self, municipality_id, street_id=None): + self._municipality_id = municipality_id + self._street_id = street_id + + def fetch(self): + # make request + uri = f"{API_URL}?gemId={self._municipality_id}&strId={self._street_id}" + r = requests.get(uri) + r.raise_for_status() + soup = BeautifulSoup(r.text, features="html.parser") + + # extract entries + entries = [] + waste_type_containers = soup.find( + "div", class_='tab-content').findChildren('div', recursive=False) + for waste_type_container in waste_type_containers: + waste_type = waste_type_container.get('id') + years = [int(y.text) for y in waste_type_container.findChildren("h3", recursive=False)] + + dates_per_year = [c.text.replace(". ", ".").split( + ) for c in waste_type_container.find_all("div", class_='cols')] + + for (year, dates) in zip(years, dates_per_year): + for (day, month) in [split_german_date(date) for date in dates]: + entries.append( + Collection( + date=datetime.date(year, month, day), + t=waste_type, + icon=ICON_MAP.get(waste_type), + ) + ) + + return entries + + +def split_german_date(date_string): + day, month_string = date_string.strip().split(".") + month = GERMAN_MONTH_STRING_TO_INT[month_string] + return (int(day), month) diff --git a/doc/source/real_luzern_ch.md b/doc/source/real_luzern_ch.md new file mode 100644 index 00000000..c0a021c1 --- /dev/null +++ b/doc/source/real_luzern_ch.md @@ -0,0 +1,54 @@ +# Real, Switzerland + +Support for schedules provided by [real-luzern.ch](https://www.real-luzern.ch) + +## Configuration via configuration.yaml + +```yaml +waste_collection_schedule: + sources: + - name: real_luzern_ch + args: + municipality_id: YOUR_MUNICIPALITY_ID + street_id: YOUR_STREET_ID +``` + +### Configuration Variables + +**municipality_id** +_(number) (required)_ The id of your municipality + +**street_id** +_(number) (optional)_ +Larger municipalities (like Lucern) have a different schedule for every street. + +## How to get the IDs + +Open [Entsorgungsdaten Real](https://www.real-luzern.ch/abfall/sammeldienst/abfallkalender/). Select your municipality (and street if required). +The URL in your browser will change and add a query string in the form of `?gemId=1234&strId=5678`. + +- Use the value of `gemId` (in this example `1234`) to set the `municipality_id` +- Use the value of `strId` (in this example `5678`) to set the `street_id`. This value is only required if you had to select a street. + +## Examples + +Location `Emmen` without street: + +```yaml +waste_collection_schedule: + sources: + - name: real_luzern_ch + args: + municipality_id: 6 +``` + +Location `Luzern - Heimatweg` with street: + +```yaml +waste_collection_schedule: + sources: + - name: real_luzern_ch + args: + municipality_id: 13 + street_id: 766 +``` diff --git a/info.md b/info.md index 7e1da0e0..3181462e 100644 --- a/info.md +++ b/info.md @@ -29,7 +29,7 @@ Waste collection schedules from service provider web sites are updated daily, de | Poland | Ecoharmonogram, Poznań/Koziegłowy/Objezierze/Oborniki, Warsaw, Wrocław | | Slovenia | Moji odpadki, Ljubljana | | Sweden | Affärsverken, Jönköping - June Avfall & Miljö, Landskrona - Svalövs Renhållning, Lerum Vatten och Avlopp, Linköping - Tekniska Verken, Region Gotland, Ronneby Miljöteknik, Samverkan Återvinning Miljö (SÅM), SRV Återvinning, SSAM, Sysav Sophämntning, Uppsala Vatten och Avfall AB, VA Syd Sophämntning | -| Switzerland | A-Region, Andwil, Appenzell, Berg, Bühler, Eggersriet, Gais, Gaiserwald, Goldach, Grosswangen, Grub, Heiden, Herisau, Horn, Hundwil, Häggenschwil, Lindau, Lutzenberg, Muolen, Mörschwil, Münchenstein, Rehetobel, Rorschach, Rorschacherberg, Schwellbrunn, Schönengrund, Speicher, Stein, Steinach, Teufen, Thal, Trogen, Tübach, Untereggen, Urnäsch, Wald, Waldkirch, Waldstatt, Wittenbach, Wolfhalden | +| Switzerland | A-Region, Andwil, Appenzell, Berg, Bühler, Eggersriet, Gais, Gaiserwald, Goldach, Grosswangen, Grub, Heiden, Herisau, Horn, Hundwil, Häggenschwil, Lindau, Lutzenberg, Muolen, Mörschwil, Münchenstein, Real Luzern, Rehetobel, Rorschach, Rorschacherberg, Schwellbrunn, Schönengrund, Speicher, Stein, Steinach, Teufen, Thal, Trogen, Tübach, Untereggen, Urnäsch, Wald, Waldkirch, Waldstatt, Wittenbach, Wolfhalden | | United Kingdom | Aberdeenshire Council, Amber Valley Borough Council, Ashfield District Council, Basildon Council, Basingstoke and Deane Borough Council, Bedford Borough Council, Binzone, Blackburn with Darwen Borough Council, Bracknell Forest Council, Bradford Metropolitan District Council, Braintree District Council, Breckland Council, Bristol City Council, Buckinghamshire Waste Collection - Former Chiltern, South Bucks or Wycombe areas, Cambridge City Council, Canterbury City Council, Central Bedfordshire Council, Cherwell District Council, Cheshire East Council, Chesterfield Borough Council, Chichester District Council, City of Doncaster Council, City of York Council, Colchester City Council, Cornwall Council, Croydon Council, Derby City Council, East Cambridgeshire District Council, East Herts Council, East Northamptonshire and Wellingborough, Eastbourne Borough Council, Elmbridge Borough Council, Environment First, Exeter City Council, Fareham Council, FCC Environment, Fenland District Council, Fife Council, Gateshead Council, Glasgow City Council, Guildford Borough Council, Harborough District Council, Harlow Council, Herefordshire City Council, Horsham District Council, Huntingdonshire District Council, Kirklees Council, Leicester City Council, Lewes District Council, Lisburn and Castlereagh City Council, Liverpool City Council, London Borough of Bexley, London Borough of Bromley, London Borough of Lewisham, London Borough of Merton, Maldon District Council, Manchester City Council, Mid-Sussex District Council, Middlesbrough Council, Newcastle City Council, Newcastle Under Lyme Borough Council, Newport City Council, North Herts Council, North Lincolnshire Council, North Somerset Council, Nottingham City Council, Oxford City Council, Peterborough City Council, Portsmouth City Council, Reading Council, Reigate & Banstead Borough Council, Richmondshire District Council, Rotherham Metropolitan Borough Council, Runnymede Borough Council, Rushmoor Borough Council, Salford City Council, Sheffield City Council, South Cambridgeshire District Council, South Derbyshire District Council, South Gloucestershire Council, South Hams District Council, South Norfolk and Broadland Council, South Oxfordshire District Council, South Tyneside Council, Southampton City Council, Stevenage Borough Council, Stockport Council, Stockton-on-Tees Borough Council, Swindon Borough Council, Telford and Wrekin Council, Tewkesbury Borough Council, The Royal Borough of Kingston Council, Tonbridge and Malling Borough Council, Uttlesford District Council, Vale of White Horse District Council, Walsall Council, Waverley Borough Council, Welwyn Hatfield Borough Council, West Berkshire Council, West Devon Borough Council, West Dunbartonshire Council, Wigan Council, Wiltshire Council, Wirral Council, Wyre Forest District Council | | United States of America | City of Oklahoma City, City of Pittsburgh, Republic Services, Seattle Public Utilities |