From bb49ada4c3cd17fe963857895021bc580c75c584 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20Tacza=C5=82a?= Date: Thu, 28 Nov 2024 18:59:18 +0100 Subject: [PATCH] Use house addresses if no street present. --- .../service/Blisko_searcher.py | 15 ++++++++++++++- .../waste_collection_schedule/source/blisko.py | 4 +++- doc/source/blisko.md | 4 ++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/custom_components/waste_collection_schedule/waste_collection_schedule/service/Blisko_searcher.py b/custom_components/waste_collection_schedule/waste_collection_schedule/service/Blisko_searcher.py index 676243023..8e4497575 100644 --- a/custom_components/waste_collection_schedule/waste_collection_schedule/service/Blisko_searcher.py +++ b/custom_components/waste_collection_schedule/waste_collection_schedule/service/Blisko_searcher.py @@ -12,6 +12,17 @@ def all_houses_per_street(regionId: int, streetId: str): return r.json()['data'] +def all_houses_per_city_no_streets(regionId: int, townId: str): + url = "https://gateway.sisms.pl/akun/api/owners/{region}/townAddresses/list?townId={formattedTOWN_ID}" + r = requests.get(url.format(region=regionId, formattedTOWN_ID=townId)) + + if r.status_code != 200: + return + + data = r.json()['data'] + return data + + def all_street_per_city(regionId: int, cityId: str): url = "https://gateway.sisms.pl/akun/api/owners/{region}/streets/list?townId={formattedTOWN_ID}" r = requests.get(url.format(region=regionId, formattedTOWN_ID=cityId)) @@ -77,8 +88,10 @@ def main(): if streets_json: print(streets_json) else: - print("No streets for region {} and cityId {}".format( + print("No streets for region {} and cityId {}. Dumping house addresses".format( args.region, args.city)) + print(all_houses_per_city_no_streets(args.region, args.city)) + return if args.region: diff --git a/custom_components/waste_collection_schedule/waste_collection_schedule/source/blisko.py b/custom_components/waste_collection_schedule/waste_collection_schedule/source/blisko.py index a1287ed12..25d940f78 100644 --- a/custom_components/waste_collection_schedule/waste_collection_schedule/source/blisko.py +++ b/custom_components/waste_collection_schedule/waste_collection_schedule/source/blisko.py @@ -14,7 +14,9 @@ "Gmina Dobra/Grzepnica/Rezydencka": {"regionId": "112", "formattedId": "32:11:01:2:0774204:42719:32"}, "Gmina Topólka/Bielki": {"regionId": "40", - "formattedId": "02:17:04:3:0880283:00157:1"} + "formattedId": "02:17:04:3:0880283:00157:1"}, + "Gmina Topólka/Bielki": {"regionId": "40", + "formattedId": "04:11:07:2:0870362::1"} } API_URL = "https://abc.com/search/" diff --git a/doc/source/blisko.md b/doc/source/blisko.md index ae43d75b1..46591bb7b 100644 --- a/doc/source/blisko.md +++ b/doc/source/blisko.md @@ -190,6 +190,10 @@ $ python custom_components/waste_collection_schedule/waste_collection_schedule/s $ python custom_components/waste_collection_schedule/waste_collection_schedule/service/Blisko_searcher.py --region 112 --city 32:11:01:2:0774204 ``` +If there is no streets for given city `Blisko_searcher.py` will dump house numbers. Use its id as `formattedId`. ( `04:11:07:2:0870362::1` for example). + + + 3) Dump all houses number for street: ```