mirror of
https://github.com/sascha-hemi/hacs_waste_collection_schedule.git
synced 2026-03-21 04:06:03 +01:00
fix sepan_remodis_pl returning wrong dates
This commit is contained in:
@@ -4,7 +4,7 @@ import logging
|
||||
import xml.etree.ElementTree
|
||||
|
||||
import requests
|
||||
from waste_collection_schedule import Collection
|
||||
from waste_collection_schedule import Collection # type: ignore[attr-defined]
|
||||
|
||||
TITLE = "Poznań/Koziegłowy/Objezierze/Oborniki"
|
||||
DESCRIPTION = "Source for Poznań/Koziegłowy/Objezierze/Oborniki city garbage collection"
|
||||
@@ -20,7 +20,7 @@ TEST_CASES = {
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
API_URL = "https://sepan.remondis.pl/harmonogram"
|
||||
API_URL = "https://sepan.remondis.pl/harmonogram{}"
|
||||
|
||||
NAME_MAP = {
|
||||
1: "Zmieszane odpady komunalne",
|
||||
@@ -50,7 +50,16 @@ class Source:
|
||||
self._street_number = street_number.upper()
|
||||
|
||||
def fetch(self):
|
||||
r = requests.get(f"{API_URL}/addresses/cities")
|
||||
try:
|
||||
return self.get_data(API_URL.format(datetime.datetime.now().year))
|
||||
except Exception:
|
||||
_LOGGER.debug(
|
||||
f"fetch failed for source {TITLE}: trying different API_URL ..."
|
||||
)
|
||||
return self.get_data(API_URL.format(""))
|
||||
|
||||
def get_data(self, api_url):
|
||||
r = requests.get(f"{api_url}/addresses/cities")
|
||||
r.raise_for_status()
|
||||
city_id = 0
|
||||
cities = json.loads(r.text)
|
||||
@@ -60,7 +69,7 @@ class Source:
|
||||
if city_id == 0:
|
||||
raise Exception("city not found")
|
||||
|
||||
r = requests.get(f"{API_URL}/addresses/streets/{city_id}")
|
||||
r = requests.get(f"{api_url}/addresses/streets/{city_id}")
|
||||
r.raise_for_status()
|
||||
street_id = 0
|
||||
streets = json.loads(r.text)
|
||||
@@ -70,7 +79,7 @@ class Source:
|
||||
if street_id == 0:
|
||||
raise Exception("street not found")
|
||||
|
||||
r = requests.get(f"{API_URL}/addresses/numbers/{city_id}/{street_id}")
|
||||
r = requests.get(f"{api_url}/addresses/numbers/{city_id}/{street_id}")
|
||||
r.raise_for_status()
|
||||
number_id = 0
|
||||
numbers = json.loads(r.text)
|
||||
@@ -80,7 +89,7 @@ class Source:
|
||||
if number_id == 0:
|
||||
raise Exception("number not found")
|
||||
|
||||
r = requests.get(f"{API_URL}/reports?type=html&id={number_id}")
|
||||
r = requests.get(f"{api_url}/reports?type=html&id={number_id}")
|
||||
r.raise_for_status()
|
||||
report = json.loads(r.text)
|
||||
if report["status"] != "success":
|
||||
|
||||
Reference in New Issue
Block a user