Add Source Müllabfuhr-Deutschland (#858)

* Add Source muellabfuhr-deutschland
This commit is contained in:
Benjamin
2023-04-09 14:40:17 +02:00
committed by GitHub
parent 599d397b5b
commit aa31d2217d
4 changed files with 123 additions and 1 deletions

View File

@@ -250,6 +250,7 @@ Waste collection schedules in the following formats and countries are supported.
- [Ludwigshafen am Rhein](/doc/source/abfall_io.md) / ludwigshafen.de
- [Lübeck Entsorgungsbetriebe](/doc/ics/luebeck_de.md) / luebeck.de
- [MZV Biedenkopf](/doc/source/buergerportal_de.md) / mzv-biedenkopf.de
- [Müllabfuhr Deutschland](/doc/source/muellabfuhr_de.md) / portal.muellabfuhr-deutschland.de
- [MüllALARM / Schönmackers](/doc/source/abfall_io.md) / schoenmackers.de
- [Müllmax](/doc/source/muellmax_de.md) / muellmax.de
- [Neunkirchen Siegerland](/doc/source/abfall_neunkirchen_siegerland_de.md) / neunkirchen-siegerland.de

View File

@@ -0,0 +1,81 @@
from datetime import datetime
import requests
from waste_collection_schedule import Collection # type: ignore[attr-defined]
TITLE = "Müllabfuhr Deutschland"
DESCRIPTION = "Source for Müllabfuhr, Germany"
URL = "https://portal.muellabfuhr-deutschland.de/"
TEST_CASES = {
"TestcaseI": {
"client": "Landkreis Hildburghausen",
"city": "Gompertshausen",
},
}
ICON_MAP = {
"Restabfall": "mdi:trash-can",
"gelbe Tonne/Leichtverpackungen": "mdi:recycle",
"Papier":"mdi:package-variant",
"Biomüll": "mdi:leaf",
}
class Source:
def __init__(self, client, city):
self._client = client
self._city = city
def fetch(self):
clientid = None
configid = None
cityid = None
#get Client
url = URL + "/api-portal/mandators"
r = requests.get(url)
r.raise_for_status()
clients = r.json()
for client in clients:
if self._client == client["name"]:
clientid = client["id"]
if clientid is None:
raise Exception("Sorry, no client found")
#get client config
url = URL + "api-portal/mandators/" + clientid + "/config"
r = requests.get(url)
r.raise_for_status()
config = r.json()
configid = config["calendarRootLocationId"]
#get city list
url = URL + "api-portal/mandators/" + clientid + "/cal/location/" + configid + "?includeChildren=true"
r = requests.get(url)
r.raise_for_status()
cities = r.json()
for city in cities["children"]:
if self._city == city["name"]:
cityid = city["id"]
if cityid is None:
raise Exception("Sorry, no city found")
#get pickups
url = URL + "/api-portal/mandators/" + clientid + "/cal/location/" + cityid + "/pickups"
r = requests.get(url)
r.raise_for_status()
pickups = r.json()
entries = []
for pickup in pickups:
d = datetime.strptime(pickup["date"], "%Y-%m-%d").date()
entries.append(
Collection(d, pickup["fraction"]["name"], icon=ICON_MAP.get(pickup["fraction"]["name"]))
)
return entries

View File

@@ -0,0 +1,40 @@
# Müllabfuhr-Deutschland
Support for schedules provided by [muellabfuhr-deutschland](https://portal.muellabfuhr-deutschland.de/).
## Configuration via configuration.yaml
```yaml
waste_collection_schedule:
sources:
- name: muellabfuhr_de
args:
client: CLIENT_NAME
city: CITY_NAME
```
### Configuration Variables
**client**
*(string) (required)*
**city**
*(string) (optional)*
## Example
```yaml
waste_collection_schedule:
sources:
- name: muellabfuhr_de
args:
client: "Landkreis Hildburghausen"
city: "Gompertshausen"
```
## How to get the source arguments
goto [muellabfuhr-deutschland](https://portal.muellabfuhr-deutschland.de/)
first copy the name of the client.
second copy the name of the city or area

File diff suppressed because one or more lines are too long