forked from mampfes/hacs_waste_collection_schedule
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request mampfes#61 from mampfes/awido
add source awido_de
- Loading branch information
Showing
4 changed files
with
205 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
custom_components/waste_collection_schedule/waste_collection_schedule/source/awido_de.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
import datetime | ||
import json | ||
import logging | ||
|
||
import requests | ||
from waste_collection_schedule import Collection # type: ignore[attr-defined] | ||
|
||
TITLE = "AWIDO" | ||
DESCRIPTION = "Source for AWIDO waste collection." | ||
URL = "https://www.awido-online.de/" | ||
TEST_CASES = { | ||
"Schorndorf, Miedelsbacher Straße 30 /1": { | ||
"customer": "rmk", | ||
"city": "Schorndorf", | ||
"street": "Miedelsbacher Straße", | ||
"housenumber": "30 /1", | ||
}, | ||
"Altomünster, Maisbrunn": { | ||
"customer": "lra-dah", | ||
"city": "Altomünster", | ||
"street": "Maisbrunn", | ||
}, | ||
"SOK-Alsmannsdorf": {"customer": "zaso", "city": "SOK-Alsmannsdorf"}, | ||
"Kaufbeuren, Rehgrund": { | ||
"customer": "kaufbeuren", | ||
"city": "Kaufbeuren", | ||
"street": "Rehgrund", | ||
}, | ||
} | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
class Source: | ||
def __init__(self, customer, city, street=None, housenumber=None): | ||
self._customer = customer | ||
self._city = city | ||
self._street = street | ||
self._housenumber = housenumber | ||
|
||
def fetch(self): | ||
# Retrieve list of places | ||
r = requests.get( | ||
f"https://awido.cubefour.de/WebServices/Awido.Service.svc/secure/getPlaces/client={self._customer}" | ||
) | ||
places = json.loads(r.text) | ||
|
||
# create city to key map from retrieved places | ||
city_to_oid = {place["value"].strip(): place["key"] for (place) in places} | ||
|
||
if self._city not in city_to_oid: | ||
_LOGGER.error(f"city not found: {self._city}") | ||
return [] | ||
|
||
oid = city_to_oid[self._city] | ||
|
||
if self._street is not None: | ||
r = requests.get( | ||
f"https://awido.cubefour.de/WebServices/Awido.Service.svc/secure/getGroupedStreets/{oid}", | ||
params={"client": self._customer}, | ||
) | ||
streets = json.loads(r.text) | ||
|
||
# create street to key map from retrieved places | ||
street_to_oid = { | ||
street["value"].strip(): street["key"] for (street) in streets | ||
} | ||
|
||
if self._street not in street_to_oid: | ||
_LOGGER.error(f"street not found: {self._street}") | ||
return [] | ||
|
||
oid = street_to_oid[self._street] | ||
|
||
if self._housenumber is not None: | ||
r = requests.get( | ||
f"https://awido.cubefour.de/WebServices/Awido.Service.svc/secure/getStreetAddons/{oid}", | ||
params={"client": self._customer}, | ||
) | ||
hsnbrs = json.loads(r.text) | ||
|
||
# create housenumber to key map from retrieved places | ||
hsnbr_to_oid = { | ||
hsnbr["value"].strip(): hsnbr["key"] for (hsnbr) in hsnbrs | ||
} | ||
|
||
if self._housenumber not in hsnbr_to_oid: | ||
_LOGGER.error(f"housenumber not found: {self._housenumber}") | ||
return [] | ||
|
||
oid = hsnbr_to_oid[self._housenumber] | ||
|
||
# get calendar data | ||
r = requests.get( | ||
f"https://awido.cubefour.de/WebServices/Awido.Service.svc/secure/getData/{oid}", | ||
params={"fractions": "", "client": self._customer}, | ||
) | ||
cal_json = json.loads(r.text) | ||
|
||
# map fraction code to fraction name | ||
fractions = {fract["snm"]: fract["nm"] for (fract) in cal_json["fracts"]} | ||
|
||
# calendar also contains public holidays. In this case, 'ad' is None | ||
calendar = [item for item in cal_json["calendar"] if item["ad"] is not None] | ||
|
||
entries = [] | ||
for calitem in calendar: | ||
date = datetime.datetime.strptime(calitem["dt"], "%Y%m%d").date() | ||
|
||
# add all fractions for this date | ||
for fracitem in calitem["fr"]: | ||
waste_type = fractions[fracitem] | ||
entries.append(Collection(date, waste_type)) | ||
|
||
return entries |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
# AWIDO based services | ||
|
||
Cubefour AWIDO is a platform for waste schedules, which has several German cities and districts as customers. The homepage of the company is https://www.awido-online.de/. | ||
|
||
## Configuration via configuration.yaml | ||
|
||
```yaml | ||
waste_collection_schedule: | ||
sources: | ||
- name: awido_de | ||
args: | ||
customer: customer | ||
city: city | ||
street: street | ||
housenumber: 2 | ||
``` | ||
### Configuration Variables | ||
**customer**<br> | ||
*(string) (required)* | ||
**city**<br> | ||
*(string) (required)* | ||
**street**<br> | ||
*(integer) (optinal, depends on customer)* | ||
**housenumber**<br> | ||
*(integer) (optional, depends on customer)* | ||
## Example | ||
```yaml | ||
waste_collection_schedule: | ||
sources: | ||
- name: awido_de | ||
args: | ||
customer: rmk | ||
city: Waiblingen | ||
street: Benzstr. | ||
housenumber: 14 | ||
``` | ||
## How to get the source arguments | ||
### customer | ||
List of customers (2021-07-09): | ||
- `rmk`: AWG des Rems-Murr-Kreises mbH | ||
- `lra-schweinfurt`: Landkreis Schweinfurt | ||
- `gotha`: Landkreis Gotha | ||
- `zaso`: Zweckverband Abfallwirtschaft Saale-Orla | ||
- `unterhaching`: Gemeinde Unterhaching | ||
- `kaufbeuren`: Stadt Kaufbeuren | ||
- `bgl`: Landkreis Berchtesgadener Land | ||
- `pullach`: Pullach im Isartal | ||
- `ffb`: Landkreis Fürstenfeldbruck | ||
- `unterschleissheim`: Stadt Unterschleißheim | ||
- `kreis-tir`: Landkreis Tirschenreuth | ||
- `rosenheim`: Landkreis Rosenheim | ||
- `tuebingen`: Landkreis Tübingen | ||
- `kronach`: Landkreis Kronach | ||
- `erding`: Landkreis Erding | ||
- `zv-muc-so`: Zweckverband München-Südost | ||
- `coburg`: Landkreis Coburg | ||
- `ansbach`: Landkreis Ansbach | ||
- `awb-duerkheim`: AWB Landkreis Bad Dürkheim | ||
- `aic-fdb`: Landratsamt Aichach-Friedberg | ||
- `wgv`: WGV Recycling GmbH | ||
- `neustadt`: Neustadt a.d. Waldnaab | ||
- `kelheim`: Landkreis Kelheim | ||
- `kaw-guenzburg`: Landkreis Günzburg | ||
- `memmingen`: Stadt Memmingen | ||
- `eww-suew`: Landkreis Südliche Weinstraße | ||
- `lra-dah`: Landratsamt Dachau | ||
- `landkreisbetriebe`: Landkreisbetriebe Neuburg-Schrobenhausen | ||
- `awb-ak`: Abfallwirtschaftsbetrieb Landkreis Altenkirchen | ||
- `awld`: Abfallwirtschaft des Lahn-Dill-Kreises | ||
- `azv-hef-rof`: Abfallwirtschafts-Zweckverband des Landkreises Hersfeld-Rotenburg | ||
- `awv-nordschwaben`: Abfall-Wirtschafts-Verband Nordschwaben | ||
|
||
### city, street, house number | ||
|
||
- Go to your calender at `https://awido.cubefour.de/Customer/<customer>/v2/Calendar2.aspx`. Replace `<customer>` with the one of the keys listed above. | ||
- Enter your city name from the first page into the `city` field, except for single-city customers, then the parameter `city` is the city. | ||
- If you have to enter a street or district, enter the name into the street` field. | ||
- If you have to enter a house number, enter the house number into the `housenumber` field. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters