diff --git a/custom_components/waste_collection_schedule/waste_collection_schedule/source/awb_oldenburg_de.py b/custom_components/waste_collection_schedule/waste_collection_schedule/source/awb_oldenburg_de.py index 8a95bfc10..70e22b7d2 100644 --- a/custom_components/waste_collection_schedule/waste_collection_schedule/source/awb_oldenburg_de.py +++ b/custom_components/waste_collection_schedule/waste_collection_schedule/source/awb_oldenburg_de.py @@ -1,8 +1,9 @@ import logging -import requests import urllib -from bs4 import BeautifulSoup from datetime import date + +import requests +from bs4 import BeautifulSoup from waste_collection_schedule import Collection # type: ignore[attr-defined] from waste_collection_schedule.service.ICS import ICS @@ -17,6 +18,7 @@ _LOGGER = logging.getLogger(__name__) + class Source: def __init__(self, street, house_number): self._street = street @@ -24,7 +26,6 @@ def __init__(self, street, house_number): self._ics = ICS(regex=r"(.*)\:\s*\!") def fetch(self): - street_idx = self.get_street_idx(self._street) if street_idx == -1: _LOGGER.error("Error: Street not found..") @@ -33,10 +34,10 @@ def fetch(self): args = { "tx_collectioncalendar_abfuhrkalender[action]": "exportIcs", - "tx_collectioncalendar_abfuhrkalender[controller]": "Frontend\Export", - "tx_collectioncalendar_abfuhrkalender[houseNumber]": str(self._house_number).encode( - "utf-8" - ), + "tx_collectioncalendar_abfuhrkalender[controller]": r"Frontend\Export", + "tx_collectioncalendar_abfuhrkalender[houseNumber]": str( + self._house_number + ).encode("utf-8"), "tx_collectioncalendar_abfuhrkalender[street]": str(street_idx).encode( "utf-8" ), @@ -45,7 +46,7 @@ def fetch(self): "tx_collectioncalendar_abfuhrkalender[wasteTypes][3]": 3, "tx_collectioncalendar_abfuhrkalender[wasteTypes][4]": 4, "tx_collectioncalendar_abfuhrkalender[wasteTypes][5]": 5, - "tx_collectioncalendar_abfuhrkalender[year]": year + "tx_collectioncalendar_abfuhrkalender[year]": year, } # use '%20' instead of '+' in API_URL @@ -62,20 +63,22 @@ def fetch(self): entries.append(Collection(d[0], d[1])) return entries - def get_street_mapping(self): # thanks @dt215git (https://github.com/mampfes/hacs_waste_collection_schedule/issues/539#issuecomment-1371413297) + def get_street_mapping( + self, + ): # thanks @dt215git (https://github.com/mampfes/hacs_waste_collection_schedule/issues/539#issuecomment-1371413297) s = requests.Session() r = s.get(API_URL) soup = BeautifulSoup(r.text, "html.parser") items = soup.find_all("option") - items = items[2:] # first two values are not street addresses so remove them + items = items[2:] # first two values are not street addresses so remove them streets = [] ids = [] for item in items: streets.append(item.text) # street name ids.append(item.attrs["value"]) # dropdown value - mapping = {k:v for (k,v) in zip(streets, ids)} + mapping = {k: v for (k, v) in zip(streets, ids)} return mapping diff --git a/custom_components/waste_collection_schedule/waste_collection_schedule/source/ks_boerde_de.py b/custom_components/waste_collection_schedule/waste_collection_schedule/source/ks_boerde_de.py index 5ae753017..1bf58d95c 100644 --- a/custom_components/waste_collection_schedule/waste_collection_schedule/source/ks_boerde_de.py +++ b/custom_components/waste_collection_schedule/waste_collection_schedule/source/ks_boerde_de.py @@ -1,4 +1,5 @@ import re + import requests from waste_collection_schedule import Collection # type: ignore[attr-defined] from waste_collection_schedule.service.ICS import ICS @@ -37,9 +38,7 @@ class Source: - def __init__( - self, village: str, street: str, house_number: str - ): + def __init__(self, village: str, street: str, house_number: str): self._village = village self._street = street self._house_number = house_number @@ -77,31 +76,32 @@ def get_from_proxy(self, village: int = 0, street: int = 0, input: str = ""): "str_id": street, "hidden_kalenderart": "privat", "url": 0 if village == 0 else 2 if street == 0 else 3, - "server": 0 + "server": 0, } - data = requests.post(DATA_URL, data=post_data).text - data = re.findall("