Skip to content

Commit

Permalink
fix: Merton Council
Browse files Browse the repository at this point in the history
  • Loading branch information
m26dvd committed Dec 13, 2024
1 parent 6f580b3 commit 8e70e6a
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions uk_bin_collection/uk_bin_collection/councils/MertonCouncil.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# This script pulls (in one hit) the data from Merton Council Bins Data
from bs4 import BeautifulSoup

from uk_bin_collection.uk_bin_collection.common import *
from uk_bin_collection.uk_bin_collection.get_bin_data import AbstractGetBinDataClass

Expand Down Expand Up @@ -33,16 +34,27 @@ def parse_data(self, page: str, **kwargs) -> dict:
),
)

possible_formats = [
"%d %B %Y",
"%A %d %B %Y",
]

# Loops the Rows
for row in rows:
# Get all the cells
cells = row.find_all("td")
# First cell is the bin_type
bin_type = cells[0].get_text().strip()
# Date is on the second cell, second paragraph, wrapped in p
collectionDate = datetime.strptime(
cells[1].select("p > b")[2].get_text(strip=True), "%d %B %Y"
)
collectionDate = None
for date_format in possible_formats:
try:
collectionDate = datetime.strptime(
cells[1].select("p > b")[2].get_text(strip=True), date_format
)
break # Exit the loop if parsing is successful
except ValueError:
continue

# Add each collection to the list as a tuple
collections.append((bin_type, collectionDate))
Expand Down

0 comments on commit 8e70e6a

Please sign in to comment.