From 7923cded427bf987476fa0b01b116700cc61506a Mon Sep 17 00:00:00 2001 From: m26dvd <31007572+m26dvd@users.noreply.github.com> Date: Thu, 12 Dec 2024 23:49:32 +0000 Subject: [PATCH] fix: Merton Council (cherry picked from commit 8e70e6aaffa19c6916c96f48af990e3ebe4da462) --- .../councils/MertonCouncil.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/uk_bin_collection/uk_bin_collection/councils/MertonCouncil.py b/uk_bin_collection/uk_bin_collection/councils/MertonCouncil.py index b7b994983d..0912ce3aee 100644 --- a/uk_bin_collection/uk_bin_collection/councils/MertonCouncil.py +++ b/uk_bin_collection/uk_bin_collection/councils/MertonCouncil.py @@ -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 @@ -33,6 +34,11 @@ 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 @@ -40,9 +46,15 @@ def parse_data(self, page: str, **kwargs) -> dict: # 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))