Skip to content

Commit

Permalink
jumomind_de fix event shows multiple times + get dates from same API …
Browse files Browse the repository at this point in the history
…as address
  • Loading branch information
5ila5 committed Apr 6, 2024
1 parent 97c357e commit 3c53abd
Showing 1 changed file with 24 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
"area_id": 3031,
},
# END DEPRECATED
"sbm Minden Meissener Str. 6a": {
"service_id": "sbm",
"city": "Minden",
"street": "Meissener Str.",
"house_number": "6A",
},
"Darmstaadt ": {"service_id": "mymuell", "city": "Darmstadt", "street": "Achatweg"},
"zaw Alsbach-Hähnlein Hähnleiner Str.": {
"service_id": "zaw",
Expand Down Expand Up @@ -54,8 +60,11 @@
"Restmüll": "mdi:trash-can",
"Glass": "mdi:bottle-soda",
"Biomüll": "mdi:leaf",
"Biotonne": "mdi:leaf",
"Papier": "mdi:package-variant",
"Papiertonne": "mdi:package-variant",
"Gelber": "mdi:recycle",
"Gelbe": "mdi:recycle",
"Schadstoffmobil": "mdi:truck-alert",
}

Expand Down Expand Up @@ -181,8 +190,8 @@ def EXTRA_INFO():
return extra_info


API_SEARCH_URL = "https://{provider}.jumomind.com/mmapp/api.php"
API_DATES_URL = "https://{provider}.jumomind.com/webservice.php"
API_URL = "https://{provider}.jumomind.com/mmapp/api.php"


LOGGER = logging.getLogger(__name__)

Expand All @@ -197,12 +206,11 @@ def __init__(
area_id=None,
house_number=None,
):
self._search_url: str = API_SEARCH_URL.format(provider=service_id)
self._dates_url: str = API_DATES_URL.format(provider=service_id)
self._api_url: str = API_URL.format(provider=service_id)
self._city: str | None = city.lower().strip() if city else None
self._street: str | None = street.lower().strip() if street else None
self._house_number: str | None = (
str(house_number).lower().strip() if house_number else None
str(house_number).lower().strip().lstrip("0") if house_number else None
)

self._service_id = service_id
Expand All @@ -220,7 +228,7 @@ def fetch(self):
if city_id is not None and self._city is not None:
raise Exception("City or city id is required. Do not use both")

r = session.get(self._search_url, params={"r": "cities_web"})
r = session.get(self._api_url, params={"r": "cities_web"})
r.raise_for_status()

cities = r.json()
Expand Down Expand Up @@ -250,7 +258,7 @@ def fetch(self):

if has_streets:
r = session.get(
self._search_url, params={"r": "streets", "city_id": city_id}
self._api_url, params={"r": "streets", "city_id": city_id}
)
r.raise_for_status()
streets = r.json()
Expand All @@ -266,7 +274,7 @@ def fetch(self):
if "houseNumbers" in street:
for house_number in street["houseNumbers"]:
if (
house_number[0].lower().strip()
house_number[0].lower().strip().lstrip("0")
== self._house_number
):
area_id = house_number[1]
Expand All @@ -281,9 +289,11 @@ def fetch(self):
)

# get names for bins

print({"r": "trash", "city_id": city_id, "area_id": area_id})
bin_name_map = {}
r = session.get(
self._search_url,
self._api_url,
params={"r": "trash", "city_id": city_id, "area_id": area_id},
)
r.raise_for_status()
Expand All @@ -294,15 +304,15 @@ def fetch(self):
bin_name_map[bin_type["_name"]] = bin_type["title"]

r = session.get(
self._dates_url,
params={"idx": "termins", "city_id": city_id, "area_id": area_id, "ws": 3},
self._api_url,
params={"r": "dates/0", "city_id": city_id, "area_id": area_id, "ws": 3},
)
r.raise_for_status()

entries = []
for event in r.json()[0]["_data"]:
bin_type = bin_name_map[event["cal_garbage_type"]]
date = datetime.datetime.strptime(event["cal_date"], "%Y-%m-%d").date()
for event in r.json():
bin_type = bin_name_map[event["trash_name"]]
date = datetime.datetime.strptime(event["day"], "%Y-%m-%d").date()
icon = ICON_MAP.get(bin_type.split(" ")[0]) # Collection icon
entries.append(Collection(date=date, t=bin_type, icon=icon))

Expand Down

0 comments on commit 3c53abd

Please sign in to comment.