From 43ebcfcb6c4ec63e96b034550720589cb6460068 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Maier?= Date: Wed, 22 Dec 2021 18:16:57 +0100 Subject: [PATCH] Added lindau_ch --- .../source/lindau_ch.py | 61 +++++++++++++++++++ doc/source/lindau_ch.md | 54 ++++++++++++++++ 2 files changed, 115 insertions(+) create mode 100644 custom_components/waste_collection_schedule/waste_collection_schedule/source/lindau_ch.py create mode 100644 doc/source/lindau_ch.md diff --git a/custom_components/waste_collection_schedule/waste_collection_schedule/source/lindau_ch.py b/custom_components/waste_collection_schedule/waste_collection_schedule/source/lindau_ch.py new file mode 100644 index 00000000..c1991408 --- /dev/null +++ b/custom_components/waste_collection_schedule/waste_collection_schedule/source/lindau_ch.py @@ -0,0 +1,61 @@ +import json +from datetime import datetime +from bs4 import BeautifulSoup + +import requests +from waste_collection_schedule import Collection # type: ignore[attr-defined] + +TITLE = "Abfall Lindau" +DESCRIPTION = "Source for Lindau waste collection." +URL = "https://www.lindau.ch/abfalldaten" +TEST_CASES = { + "Tagelswangen": {"city": "Tagelswangen", "types": "kehricht, grungut, papier und karton, altmetalle, hackseldienst"}, + "Grafstal": {"city": "190", "types": "grungut, papier und karton"}, +} + + +class Source: + def __init__(self, city, types): + self._city = city + self._types = types + + def fetch(self): + + + response = requests.get("https://www.lindau.ch/abfalldaten") + + html = BeautifulSoup(response.text, 'html.parser') + + table = html.find('table', attrs={'id':'icmsTable-abfallsammlung'}) + data = json.loads(table.attrs['data-entities']) + + entries = [] + for item in data['data']: + + if self._city in item['abfallkreisIds'] or self._city in item['abfallkreisNameList']: + next_pickup = item['_anlassDate-sort'].split()[0] + next_pickup_date = datetime.fromisoformat(next_pickup).date() + + waste_type = BeautifulSoup(item['name'],'html.parser').text + waste_type_sorted = BeautifulSoup(item['name-sort'],'html.parser').text + + if waste_type_sorted == "kehricht" and waste_type_sorted in self._types: + icon = "mdi:trash-can" + entries.append(Collection(date=next_pickup_date, t=waste_type, icon=icon)) + elif waste_type_sorted == "grungut" and waste_type_sorted in self._types: + icon = "mdi:leaf" + entries.append(Collection(date=next_pickup_date, t=waste_type, icon=icon)) + elif waste_type_sorted == "hackseldienst" and waste_type_sorted in self._types: + icon = "mdi:leaf" + entries.append(Collection(date=next_pickup_date, t=waste_type, icon=icon)) + elif waste_type_sorted == "papier und karton" and waste_type_sorted in self._types: + icon = "mdi:package-variant" + entries.append(Collection(date=next_pickup_date, t=waste_type, icon=icon)) + elif waste_type_sorted == "altmetalle" and waste_type_sorted in self._types: + icon = "mdi:nail" + entries.append(Collection(date=next_pickup_date, t=waste_type, icon=icon)) + else: + icon = "mdi:trash-can" + entries.append(Collection(date=next_pickup_date, t=waste_type, icon=icon)) + + return entries diff --git a/doc/source/lindau_ch.md b/doc/source/lindau_ch.md new file mode 100644 index 00000000..1d92a539 --- /dev/null +++ b/doc/source/lindau_ch.md @@ -0,0 +1,54 @@ +# Abfallwirtschaft Zollernalbkreis + +Support for schedules provided by [https://www.lindau.ch/abfalldaten](https://www.lindau.ch/abfalldaten). + + + +## Configuration via configuration.yaml + +```yaml +waste_collection_schedule: + sources: + - name: lindau_ch + args: + city: Tagelswangen + types: + - "kehricht" + - "grungut" + - "papier und karton" + - "altmetalle" + - "hackseldienst" +``` + +### Configuration Variables + +**city**
+*(string) (required)*
+One of
+Names: Grafstal, Lindau, Tagelswangen, Winterberg
+or ID: 190, 192, 193, 191 + +**types**
+*(list of string) (required)* + +## Example + +```yaml +waste_collection_schedule: + sources: + - name: lindau_ch + args: + city: Tagelswangen + types: + - "kehricht" + - "grungut" + - "papier und karton" + - "altmetalle" + - "hackseldienst" +``` + +## How to get the source arguments + + + +