Skip to content

Commit

Permalink
app_abfallplus_de make street and hnr optional if only one available …
Browse files Browse the repository at this point in the history
…anyway
  • Loading branch information
5ila5 committed May 4, 2024
1 parent b513f8f commit 00e9f04
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -647,10 +647,10 @@ def select_bezirk(self, bezirk=None) -> bool:
if bezirk["kommune_id"] is not None:
self._kommune_id = bezirk["kommune_id"]
self._bezirk_id = bezirk["id"]
if bezirk["finished"]:
if bezirk["finished"] or "street_id" in bezirk:
self._f_id_strasse = self._strasse_id = (
bezirk["street_id"]
if bezirk["street_id"] is not None
if bezirk.get("street_id") is not None
else bezirk["id"]
)
return bezirk["finished"]
Expand Down Expand Up @@ -692,6 +692,15 @@ def select_street(self, street=None):
if street:
self._strasse_search = street
streets = self.get_streets()
if self._strasse_search is None and len(streets) == 1:
self._strasse_search = streets[0]["name"]
if self._strasse_search is None and len(streets) == 0:
return
elif self._strasse_search is None:
raise Exception(
f"Street expected, available: {[s['name'] for s in streets]}"
)

for street in streets:
if compare(street["name"], self._strasse_search):
self._f_id_strasse = self._strasse_id = street["id"]
Expand All @@ -701,8 +710,9 @@ def select_street(self, street=None):
self._bezirk_id = street["id_beirk"]
self._hnrs = street["hrns"]
return
street_names = [s["name"] for s in streets]
raise Exception(
f"Street '{self._strasse_search}' not found., available: {streets}"
f"Street '{self._strasse_search}' not found. available: {street_names}"
)

def get_hrn_needed(self) -> bool:
Expand Down Expand Up @@ -737,7 +747,14 @@ def get_hnrs(self):
def select_hnr(self, hnr=None):
if hnr:
self._hnr_search = hnr
for hnr in self.get_hnrs():
hnrs = self.get_hnrs()
if self._hnr_search is None and len(hnrs) == 1:
self._hnr_search = hnrs[0]["name"]
elif self._hnr_search is None and len(hnrs) == 0:
return
elif self._hnr_search is None:
raise Exception(f"hnr expected, available: {[hnr['name'] for hnr in hnrs]}")
for hnr in hnrs:
if compare(hnr["name"], self._hnr_search, remove_space=True):
self._hnr = hnr["id"]
if hnr["f_id_strasse"] is not None:
Expand Down Expand Up @@ -894,7 +911,7 @@ def generate_calendar(self) -> list[dict[str, date | str]]:
finished = self.select_bezirk()
if not finished:
self.select_street()
if self._hnrs and self._hnr_search is not None:
if self._hnrs:
self.select_hnr()
self.select_all_waste_types()
self.validate()
Expand Down Expand Up @@ -958,7 +975,7 @@ def debug(self):
def generate_supported_services(suppoted_apps=SUPPORTED_APPS):
supported_services = {}
for index, app_id in enumerate(suppoted_apps):
print(f"starting {index+1}/{len(suppoted_apps)}: {app_id}")
print(f"starting {index + 1}/{len(suppoted_apps)}: {app_id}")
supported_services[app_id] = []
app = AppAbfallplusDe(app_id, "", "", "")
app.init_connection()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,13 @@
# "strasse": "Kornmarkt",
# "bezirk": "Osterode am Harz"
# }
# "de.k4systems.abfallscout Hammelburg Morlesau": {
# "app_id": "de.k4systems.abfallscout",
# "city": "Hammelburg",
# "bezirk": "Morlesau",
# # "strasse": "Alle Straßen", # OPTIONAL
# # "hnr": "Alle Hausnummern" # OPTIONAL
# }
}


Expand Down

0 comments on commit 00e9f04

Please sign in to comment.