Skip to content

Commit

Permalink
Merge pull request #61 from mampfes/awido
Browse files Browse the repository at this point in the history
add source awido_de
  • Loading branch information
mampfes authored Jul 20, 2021
2 parents 5484b95 + e5dd44d commit 0d63db1
Show file tree
Hide file tree
Showing 4 changed files with 205 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ Currently the following service providers are supported:
- [AbfallNavi.de (RegioIT.de)](./doc/source/abfallnavi_de.md)
- [Abfallwirtschaft Stuttgart](./doc/source/stuttgart_de.md)
- [AWBKoeln.de](./doc/source/awbkoeln_de.md)
- [AWIDO-online.de](./doc/source/awido_de.md)
- [BSR.de / Berliner Stadtreinigungsbetriebe](./doc/source/bsr_de.md)
- [Jumomind.de](./doc/source/jumomind_de.md)
- [Muellmax.de](./doc/source/muellmax_de.md)
Expand Down
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
88 changes: 88 additions & 0 deletions doc/source/awido_de.md
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.
1 change: 1 addition & 0 deletions info.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Currently the following service providers are supported:
- [AbfallNavi.de (RegioIT.de)](https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/abfallnavi_de.md)
- [Abfallwirtschaft Stuttgart](https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/stuttgart_de.md)
- [AWBKoeln.de](https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/awbkoeln_de.md)
- [AWIDO-online.de](./doc/source/awido_de.md)
- [BSR.de / Berliner Stadtreinigungsbetriebe](https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/bsr_de.md)
- [Jumomind.de](https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/jumomind_de.md)
- [Muellmax.de](https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/muellmax_de.md)
Expand Down

0 comments on commit 0d63db1

Please sign in to comment.