Skip to content

Commit

Permalink
fix black, pylint, ... warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
mampfes committed Jul 20, 2021
1 parent 22a422b commit e5dd44d
Showing 1 changed file with 35 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import datetime
import requests
import json
import logging

import requests
from waste_collection_schedule import Collection # type: ignore[attr-defined]

TITLE = "AWIDO"
Expand All @@ -13,22 +13,19 @@
"customer": "rmk",
"city": "Schorndorf",
"street": "Miedelsbacher Straße",
"housenumber": "30 /1"
"housenumber": "30 /1",
},
"Altomünster, Maisbrunn": {
"customer": "lra-dah",
"city": "Altomünster",
"street": "Maisbrunn"
},
"SOK-Alsmannsdorf": {
"customer": "zaso",
"city": "SOK-Alsmannsdorf"
"street": "Maisbrunn",
},
"SOK-Alsmannsdorf": {"customer": "zaso", "city": "SOK-Alsmannsdorf"},
"Kaufbeuren, Rehgrund": {
"customer": "kaufbeuren",
"city": "Kaufbeuren",
"street": "Rehgrund"
}
"street": "Rehgrund",
},
}

_LOGGER = logging.getLogger(__name__)
Expand All @@ -43,11 +40,13 @@ def __init__(self, customer, city, street=None, housenumber=None):

def fetch(self):
# Retrieve list of places
r = requests.get(f'https://awido.cubefour.de/WebServices/Awido.Service.svc/secure/getPlaces/client={self._customer}')
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}
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}")
Expand All @@ -56,11 +55,16 @@ def fetch(self):
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})
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}
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}")
Expand All @@ -69,37 +73,43 @@ def fetch(self):
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})
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}
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})
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"]}
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]
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']:
for fracitem in calitem["fr"]:
waste_type = fractions[fracitem]
entries.append(Collection(date, waste_type))
return entries

return entries

0 comments on commit e5dd44d

Please sign in to comment.