Skip to content

Commit

Permalink
feat: #1067 - Add garden bin collections where available for Norwich …
Browse files Browse the repository at this point in the history
…City Council
  • Loading branch information
dp247 committed Dec 18, 2024
1 parent c161f0d commit 53de600
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions uk_bin_collection/uk_bin_collection/councils/NorwichCityCouncil.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,13 @@ def parse_data(self, page: str, **kwargs) -> dict:
alternateCheck = False

strong = soup.find_all("strong")
collections = []

if alternateCheck:
bin_types = strong[2].text.strip().replace(".", "").split(" and ")
for bin in bin_types:
dict_data = {
"type": bin,
"collectionDate": strong[1].text.strip(),
}
bindata["bins"].append(dict_data)
collections.append((bin.capitalize(), datetime.strptime(strong[1].text.strip(), date_format)))

else:
p_tag = soup.find_all("p")
i = 1
Expand All @@ -65,11 +63,18 @@ def parse_data(self, page: str, **kwargs) -> dict:
p.text.split("Your ")[1].split(" is collected")[0].split(" and ")
)
for bin in bin_types:
dict_data = {
"type": bin,
"collectionDate": strong[i].text.strip(),
}
bindata["bins"].append(dict_data)
collections.append((bin.capitalize(), datetime.strptime(strong[1].text.strip(), date_format)))
i += 2

if len(strong) > 3:
collections.append(("Garden", datetime.strptime(strong[4].text.strip(), date_format)))

ordered_data = sorted(collections, key=lambda x: x[1])
for item in ordered_data:
dict_data = {
"type": item[0] + " bin",
"collectionDate": item[1].strftime(date_format),
}
bindata["bins"].append(dict_data)

return bindata

0 comments on commit 53de600

Please sign in to comment.