From 1f6476c1f536a4e6c7e17510ca56e05f2b47f5ed Mon Sep 17 00:00:00 2001 From: 5ila5 <5ila5@users.noreply.github.com> Date: Thu, 18 Jul 2024 12:17:14 +0200 Subject: [PATCH] alw_wf_de improve city/street matching --- .../waste_collection_schedule/source/alw_wf_de.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/custom_components/waste_collection_schedule/waste_collection_schedule/source/alw_wf_de.py b/custom_components/waste_collection_schedule/waste_collection_schedule/source/alw_wf_de.py index 99b62ce8..223f3973 100644 --- a/custom_components/waste_collection_schedule/waste_collection_schedule/source/alw_wf_de.py +++ b/custom_components/waste_collection_schedule/waste_collection_schedule/source/alw_wf_de.py @@ -1,9 +1,9 @@ import datetime import json -import urllib3 import pytz import requests +import urllib3 from waste_collection_schedule import Collection # type: ignore[attr-defined] # With verify=True the POST fails due to a SSLCertVerificationError. @@ -24,6 +24,7 @@ TEST_CASES = { "strasse": "Kleingartenweg", }, "Dettum": {"ort": "Dettum", "strasse": "Egal!"}, + "Wolfbuttel Ahlumer Straße": {"ort": "wolfenbüttel", "strasse": "Ahlumer Straße"}, } API_URL = "https://abfallapp.alw-wf.de" @@ -45,7 +46,7 @@ BIN_TYPE_NORMAL = "0" class Source: def __init__(self, ort, strasse): self._ort = ort - self._strasse = strasse + self._strasse = strasse.lower().strip().replace("straße", "str.") def fetch(self): auth_params = json.dumps(AUTH_DATA) @@ -57,8 +58,8 @@ class Source: raise Exception(f"Error getting Orte: {orte['result'][0]['StatusMsg']}") orte = orte["result"][0]["result"] - orte = {i["Name"]: i["ID"] for i in orte} - ort_id = orte.get(self._ort, None) + orte = {i["Name"].lower().strip(): i["ID"] for i in orte} + ort_id = orte.get(self._ort.lower().strip(), None) if ort_id is None: raise Exception(f"Error finding Ort {self._ort}") @@ -75,7 +76,11 @@ class Source: for strasse in strassen: if strasse["OrtID"] != ort_id: continue - if strasse["Name"] == ALL_STREETS or strasse["Name"] == self._strasse: + if ( + strasse["Name"] == ALL_STREETS + or strasse["Name"].lower().strip().replace("straße", "str.") + == self._strasse + ): strasse_id = strasse["ID"] break continue