Skip to content

Commit

Permalink
fix recycleapp_be only trying one zip-code id even if one zipcode has…
Browse files Browse the repository at this point in the history
… multiple ids
  • Loading branch information
5ila5 committed Dec 26, 2024
1 parent 11e625f commit 6d640e5
Showing 1 changed file with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@
"street": "Th. De Beckerstraat",
"house_number": 1,
},
"9180 Lokeren, Abelendreef 1": {
"postcode": 9180,
"street": "Abelendreef",
"house_number": 1,
},
"8700 Abeelstraat 1": {
"postcode": 8700,
"street": "Abeelstraat",
"house_number": 1,
},
}

_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -68,8 +78,29 @@ def fetch(self):
items = r.json()["items"]
if len(items) == 0:
raise SourceArgumentNotFound("postcode", self._postcode)
zipcodeId = items[0]["id"]

for item in items:
error = None
if not item["available"]:
continue
zipcodeId = item["id"]
try:
entries = self._fetch_zipcode(zipcodeId, url, headers)
if entries:
return entries
except SourceArgumentNotFound as e:
error = e

if error:
raise error
raise Exception(
"No data found for the postcode"
+ (", tired multiple zipcode, entries" if len(items) > 1 else "")
)

def _fetch_zipcode(
self, zipcodeId: str, url: str, headers: dict[str, str]
) -> list[Collection]:
params = {"q": self._steet_search, "zipcodes": zipcodeId}
r = requests.post(f"{url}/streets", params=params, headers=headers)
r.raise_for_status()
Expand Down

0 comments on commit 6d640e5

Please sign in to comment.