diff --git a/README.md b/README.md index 0f2f58c5..25eda163 100644 --- a/README.md +++ b/README.md @@ -80,6 +80,7 @@ Currently the following service providers are supported: - [Abfallwirtschaft Südholstein](./doc/source/awsh_de.md) - [Abfallwirtschaft Zollernalbkreis](./doc/source/abfall_zollernalbkreis_de.md) - [AWB Bad Kreuznach](./doc/source/awb_bad_kreuznach_de.md) +- [AWB Oldenburg](./doc/source/awb_oldenburg_de.md) - [AWBKoeln.de](./doc/source/awbkoeln_de.md) - [AWIDO-online.de](./doc/source/awido_de.md) - [Berlin-Recycling.de](./doc/source/berlin_recycling_de.md) diff --git a/custom_components/waste_collection_schedule/waste_collection_schedule/source/awb_oldenburg_de.py b/custom_components/waste_collection_schedule/waste_collection_schedule/source/awb_oldenburg_de.py new file mode 100755 index 00000000..eb0aa5c6 --- /dev/null +++ b/custom_components/waste_collection_schedule/waste_collection_schedule/source/awb_oldenburg_de.py @@ -0,0 +1,54 @@ +import requests +from waste_collection_schedule import Collection # type: ignore[attr-defined] + +import urllib +import icalendar + + +TITLE = "AWB Oldenburg" +DESCRIPTION = "Source for 'Abfallwirtschaftsbetrieb Stadt Oldenburg (Oldb)'." +URL = "https://services.oldenburg.de/index.php" +TEST_CASES = { + "Polizeiinspektion Oldenburg": {"street": "Friedhofsweg", "house_number": 30} +} + + +class Source: + def __init__(self, street, house_number): + self._street = street + self._house_number = house_number + + def fetch(self): + + args = { + 'id': 430, + 'tx_citkoabfall_abfallkalender[strasse]': self._street.encode('utf-8'), + 'tx_citkoabfall_abfallkalender[hausnummer]': self._house_number.encode('utf-8'), + 'tx_citkoabfall_abfallkalender[abfallarten][0]': 61, + 'tx_citkoabfall_abfallkalender[abfallarten][1]': 60, + 'tx_citkoabfall_abfallkalender[abfallarten][2]': 59, + 'tx_citkoabfall_abfallkalender[abfallarten][3]': 58, + 'tx_citkoabfall_abfallkalender[action]': 'ics', + 'tx_citkoabfall_abfallkalender[controller]': 'FrontendIcs' + } + + # use '%20' instead of '+' in URL + # https://stackoverflow.com/questions/21823965/use-20-instead-of-for-space-in-python-query-parameters + args = urllib.parse.urlencode(args, quote_via=urllib.parse.quote) + + # post request + reply = requests.get(URL, params=args) + + # create calender from reply + gcal = icalendar.Calendar.from_ical(reply.text) + + # iterate over events and add to waste collection + entries = [] + for component in gcal.walk(): + if component.name == "VEVENT": + type = component.get('summary') + start_date = component.get('dtstart').dt + + entries.append(Collection(start_date, type)) + + return entries diff --git a/doc/source/awb_oldenburg_de.md b/doc/source/awb_oldenburg_de.md new file mode 100644 index 00000000..127b877a --- /dev/null +++ b/doc/source/awb_oldenburg_de.md @@ -0,0 +1,33 @@ +# Abfallwirtschaftsbetrieb Stadt Oldenburg (Oldb) + +Support for schedules provided by [services.oldenburg.de](https://services.oldenburg.de/index.php?id=430). + +## Configuration via configuration.yaml + +```yaml +waste_collection_schedule: + sources: + - name: awb_oldenburg_de + args: + street: STREET + house_number: HOUSE_NUMBER +``` + +### Configuration Variables + +**street**
+*(string) (required)* + +**house_number**
+*(string) (required)* + +## Example + +```yaml +waste_collection_schedule: + sources: + - name: awb_oldenburg_de + args: + street: 'Friedhofsweg' + house_number: 30 +``` diff --git a/info.md b/info.md index e6eb2bb8..deaccb46 100644 --- a/info.md +++ b/info.md @@ -66,6 +66,7 @@ Currently the following service providers are supported: - [Abfallwirtschaft Südholstein](https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/awsh_de.md) - [Abfallwirtschaft Zollernalbkreis](https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/abfall_zollernalbkreis_de.md) - [AWB Bad Kreuznach](https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/awb_bad_kreuznach_de.md) +- [AWB Oldenburg](https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/awb_oldenburg_de.md) - [AWBKoeln.de](https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/awbkoeln_de.md) - [AWIDO-online.de](https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/awido_de.md) - [Berlin-Recycling.de](https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/berlin_recycling_de.md)