diff --git a/custom_components/waste_collection_schedule/waste_collection_schedule/source/eth_erd_hu.py b/custom_components/waste_collection_schedule/waste_collection_schedule/source/eth_erd_hu.py index 18ea94b17..3b07e51e8 100644 --- a/custom_components/waste_collection_schedule/waste_collection_schedule/source/eth_erd_hu.py +++ b/custom_components/waste_collection_schedule/waste_collection_schedule/source/eth_erd_hu.py @@ -1,28 +1,17 @@ -import json -import requests import datetime +import json -from bs4 import BeautifulSoup -from waste_collection_schedule import Collection +import requests +from waste_collection_schedule import Collection # type: ignore[attr-defined] TITLE = "ÉTH (Érd, Diósd, Nagytarcsa, Sóskút, Tárnok)" DESCRIPTION = "Source script for www.eth-erd.hu" URL = "https://www.eth-erd.hu" COUNTRY = "hu" TEST_CASES = { - "Test_1": { - "city": "Diósd", - "street": "Diófasor", - "house_number": 10 - }, - "Test_2": { - "city": "Érd", - "street": "Hordó", - "house_number": 3 - }, - "Test_3": { - "city": "Sóskút" - } + "Test_1": {"city": "Diósd", "street": "Diófasor", "house_number": 10}, + "Test_2": {"city": "Érd", "street": "Hordó", "house_number": 3}, + "Test_3": {"city": "Sóskút"}, } API_URL = "https://www.eth-erd.hu/trashcalendarget" @@ -64,25 +53,31 @@ def fetch(self): session = requests.Session() city_id = CITY_MAP.get(self._city.lower()) - if city_id == None: raise Exception("City not found") + if city_id is None: + raise Exception("City not found") has_streets = city_id != CITY_MAP["sóskút"] if has_streets: r = session.post( API_URL + "streets", - data={ - "sid": city_id - }, + data={"sid": city_id}, headers={ "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8", "X-Requested-With": "XMLHttpRequest", - } + }, ) r.raise_for_status() streets = json.loads(r.text)["results"] available_streets = [item["text"] for item in streets] - try: street_id = [item for item in streets if item.get('text') == self._street][0]["id"] - except IndexError: raise Exception("Street not found, available streets: " + ", ".join(available_streets)) + try: + street_id = [ + item for item in streets if item.get("text") == self._street + ][0]["id"] + except IndexError: + raise Exception( + "Street not found, available streets: " + + ", ".join(available_streets) + ) r = session.post( API_URL, @@ -90,13 +85,15 @@ def fetch(self): "wctown": city_id, "wcstreet": street_id, "wchousenumber": self._house_number, - } if has_streets else { + } + if has_streets + else { "wctown": city_id, }, headers={ "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8", "X-Requested-With": "XMLHttpRequest", - } + }, ) r.raise_for_status() result: dict = json.loads(r.text) @@ -111,9 +108,9 @@ def fetch(self): for element in result["routelist"][trash_type_id]: entries.append( Collection( - date = datetime.datetime.strptime(element, "%Y-%m-%d").date(), - t = trash_name, - icon = trash_icon, + date=datetime.datetime.strptime(element, "%Y-%m-%d").date(), + t=trash_name, + icon=trash_icon, ) )