Skip to content

Commit

Permalink
Fix: Wokingham, UK (#3324)
Browse files Browse the repository at this point in the history
* updated to handle xmas collection changes

* updated waste type description
  • Loading branch information
dt215git authored Dec 29, 2024
1 parent 3649cd7 commit 54b5035
Showing 1 changed file with 44 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,20 +93,52 @@ def fetch(self):
data=payload,
)
soup = BeautifulSoup(r.text, "html.parser")
cards = soup.find_all("div", {"class": "card--waste"})

# Extract the collection schedules
entries = []
for card in cards:
# Cope with Garden waste suffixed with (week 1) or (week 2)
waste_type = " ".join(card.find("h3").text.strip().split()[:2])
waste_date = card.find("span").text.strip().split()[-1]
entries.append(
Collection(
date=datetime.strptime(waste_date, "%d/%m/%Y").date(),
t=waste_type,
icon=ICON_MAP.get(waste_type.upper()),

# check for changed Christmas & New Year collections messages
christmas = soup.find_all(
"div", {"class": "waste-collection-information__christmas"}
)
if christmas: # just process info on changed collections
changes = christmas[0].find_all("p")
for change in changes:
span = change.find("span")
if span:
waste_type = (
span.get_text(strip=True)
.replace("Changes to ", "")
.replace(":", "")
)
waste_dates = [
date.strip()
for date in change.get_text()
.replace(".", "")
.split("The new collection date will be ")[1:]
]
for waste_date in waste_dates:
entries.append(
Collection(
date=datetime.strptime(
waste_date, "%A %d/%m/%Y"
).date(),
t=f"{waste_type} (Christmas Schedule)",
icon=ICON_MAP.get(waste_type.upper()),
)
)
else: # process info on regular collections
cards = soup.find_all("div", {"class": "card--waste"})
# Extract the collection schedules
for card in cards:
# Cope with Garden waste suffixed with (week 1) or (week 2)
waste_type = " ".join(card.find("h3").text.strip().split()[:2])
waste_date = card.find("span").text.strip().split()[-1]
entries.append(
Collection(
date=datetime.strptime(waste_date, "%d/%m/%Y").date(),
t=waste_type,
icon=ICON_MAP.get(waste_type.upper()),
)
)
)

return entries

0 comments on commit 54b5035

Please sign in to comment.