Skip to content

Commit

Permalink
fix: Vale of White Horse
Browse files Browse the repository at this point in the history
fix: #1156
  • Loading branch information
m26dvd committed Jan 16, 2025
1 parent 6a75f29 commit c43d47b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ def parse_data(self, page: str, **kwargs) -> dict:

data = {"bins": []}

current_year = datetime.now().year
next_year = current_year + 1

# Page has slider info side by side, which are two instances of this class
for bin in soup.find_all("div", {"class": "binextra"}):
bin_info = list(bin.stripped_strings)
Expand All @@ -63,27 +66,32 @@ def parse_data(self, page: str, **kwargs) -> dict:
if contains_date(bin_info[0]):
bin_date = get_next_occurrence_from_day_month(
datetime.strptime(
bin_info[0] + " " + datetime.today().strftime("%Y"),
"%A %d %B - %Y",
bin_info[0],
"%A %d %B -",
)
).strftime(date_format)
)
bin_type = str.capitalize(" ".join(bin_info[1:]))
# On exceptional collection schedule (e.g. around English Bank Holidays), date will be contained in the second stripped string
else:
bin_date = get_next_occurrence_from_day_month(
datetime.strptime(
bin_info[1] + " " + datetime.today().strftime("%Y"),
"%A %d %B - %Y",
bin_info[1],
"%A %d %B -",
)
).strftime(date_format)
)
str.capitalize(" ".join(bin_info[2:]))
except:
continue

if (datetime.now().month == 12) and (bin_date.month == 1):
bin_date = bin_date.replace(year=next_year)
else:
bin_date = bin_date.replace(year=current_year)

# Build data dict for each entry
dict_data = {
"type": bin_type,
"collectionDate": bin_date,
"collectionDate": bin_date.strftime(date_format),
}
data["bins"].append(dict_data)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ def parse_data(self, page: str, **kwargs) -> dict:

data = {"bins": []}

current_year = datetime.now().year
next_year = current_year + 1

# Page has slider info side by side, which are two instances of this class
for bin in soup.find_all("div", {"class": "bintxt"}):
try:
Expand All @@ -74,23 +77,31 @@ def parse_data(self, page: str, **kwargs) -> dict:
if contains_date(bin_date_info[0]):
bin_date = get_next_occurrence_from_day_month(
datetime.strptime(
bin_date_info[0] + " " + datetime.today().strftime("%Y"),
"%A %d %B - %Y",
bin_date_info[0],
"%A %d %B -",
)
).strftime(date_format)
)
# On exceptional collection schedule (e.g. around English Bank Holidays), date will be contained in the second stripped string
else:
bin_date = get_next_occurrence_from_day_month(
datetime.strptime(
bin_date_info[1] + " " + datetime.today().strftime("%Y"),
"%A %d %B - %Y",
bin_date_info[1],
"%A %d %B -",
)
).strftime(date_format)
)
except Exception as ex:
raise ValueError(f"Error parsing bin data: {ex}")

if (datetime.now().month == 12) and (bin_date.month == 1):
bin_date = bin_date.replace(year=next_year)
else:
bin_date = bin_date.replace(year=current_year)

# Build data dict for each entry
dict_data = {"type": bin_type, "collectionDate": bin_date}
dict_data = {
"type": bin_type,
"collectionDate": bin_date.strftime(date_format),
}
data["bins"].append(dict_data)

data["bins"].sort(
Expand Down

0 comments on commit c43d47b

Please sign in to comment.