mirror of
https://github.com/sascha-hemi/hacs_waste_collection_schedule.git
synced 2026-03-21 05:06:33 +01:00
fix awido_de for some regions
This commit is contained in:
@@ -3,6 +3,7 @@ import logging
|
||||
|
||||
import requests
|
||||
from waste_collection_schedule import Collection # type: ignore[attr-defined]
|
||||
from waste_collection_schedule.service.ICS import ICS
|
||||
|
||||
TITLE = "AWIDO Online"
|
||||
DESCRIPTION = "Source for AWIDO waste collection."
|
||||
@@ -255,17 +256,27 @@ TEST_CASES = {
|
||||
"city": "Spalt",
|
||||
"street": "Pflugsmühler Weg",
|
||||
},
|
||||
"Kissing Karwendelweg": {
|
||||
"customer": "aic-fdb",
|
||||
"city": "Kissing",
|
||||
"street": "Karwendelweg",
|
||||
},
|
||||
}
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class JSONNotSupported(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class Source:
|
||||
def __init__(self, customer, city, street=None, housenumber=None):
|
||||
self._customer = customer
|
||||
self._city = city
|
||||
self._street = street
|
||||
self._housenumber = None if housenumber is None else str(housenumber)
|
||||
self._ics = ICS()
|
||||
|
||||
def fetch(self):
|
||||
# Retrieve list of places
|
||||
@@ -333,12 +344,48 @@ class Source:
|
||||
|
||||
oid = hsnbr_to_oid[self._housenumber]
|
||||
|
||||
try:
|
||||
return self.get_json_data(oid)
|
||||
except JSONNotSupported:
|
||||
return self.get_ics_data(oid)
|
||||
|
||||
def get_ics_data(self, oid) -> list[Collection]:
|
||||
now = datetime.datetime.now()
|
||||
|
||||
entries: list[Collection] = []
|
||||
|
||||
for year in [now.year, now.year + 1] if now.month == 12 else [now.year]:
|
||||
r = requests.get(
|
||||
f"https://awido.cubefour.de/Customer/{self._customer}/KalenderICS.aspx",
|
||||
params={
|
||||
"oid": oid,
|
||||
"jahr": year,
|
||||
"fraktionen": "",
|
||||
"reminder": "-1.17:00",
|
||||
},
|
||||
)
|
||||
r.raise_for_status()
|
||||
ics_file = r.text
|
||||
|
||||
dates = self._ics.convert(ics_file)
|
||||
|
||||
entries = []
|
||||
for d in dates:
|
||||
# prevents duplicates
|
||||
if any(e.date == d[0] and e.type == d[1] for e in entries):
|
||||
continue
|
||||
entries.append(Collection(d[0], d[1]))
|
||||
|
||||
return entries
|
||||
|
||||
def get_json_data(self, oid) -> list[Collection]:
|
||||
# get calendar data
|
||||
r = requests.get(
|
||||
f"https://awido.cubefour.de/WebServices/Awido.Service.svc/secure/getData/{oid}",
|
||||
params={"fractions": "", "client": self._customer},
|
||||
)
|
||||
r.raise_for_status()
|
||||
if r.status_code != 200 or r.text.strip() == "":
|
||||
raise JSONNotSupported()
|
||||
cal_json = r.json()
|
||||
|
||||
# map fraction code to fraction name
|
||||
|
||||
Reference in New Issue
Block a user