Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Wokingham, UK #3324

Merged
merged 2 commits into from
Dec 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading