Skip to content

Commit

Permalink
fix: Swale Borough Council
Browse files Browse the repository at this point in the history
  • Loading branch information
m26dvd committed Jan 19, 2025
1 parent c43d47b commit 29922f1
Showing 1 changed file with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def parse_collection_date(date_string) -> datetime:

return parsed_date


class CouncilClass(AbstractGetBinDataClass):
"""
Concrete classes have to implement all abstract operations of the
Expand Down Expand Up @@ -84,6 +85,9 @@ def parse_data(self, page: str, **kwargs) -> dict:

data = {"bins": []}

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

next_collection_date = soup.find(
"strong", id="SBC-YBD-collectionDate"
).text.strip()
Expand All @@ -104,20 +108,27 @@ def parse_data(self, page: str, **kwargs) -> dict:
future_bins = [li.text.strip() for li in soup.select("#FirstFutureBins li")]

for bin in next_bins:
collection_date = datetime.strptime(next_collection_date, "%A, %d %B")
if (datetime.now().month == 12) and (collection_date.month == 1):
collection_date = collection_date.replace(year=next_year)
else:
collection_date = collection_date.replace(year=current_year)

dict_data = {
"type": bin,
"collectionDate": datetime.strptime(
next_collection_date, "%A, %d %B"
).strftime(date_format),
"collectionDate": collection_date.strftime(date_format),
}
data["bins"].append(dict_data)

for bin in future_bins:
collection_date = datetime.strptime(future_collection_date, "%A, %d %B")
if (datetime.now().month == 12) and (collection_date.month == 1):
collection_date = collection_date.replace(year=next_year)
else:
collection_date = collection_date.replace(year=current_year)
dict_data = {
"type": bin,
"collectionDate": datetime.strptime(
future_collection_date, "%A, %d %B"
).strftime(date_format),
"collectionDate": collection_date.strftime(date_format),
}
data["bins"].append(dict_data)

Expand Down

0 comments on commit 29922f1

Please sign in to comment.