Skip to content

Commit

Permalink
Merge pull request #451 from dp247/449-charnwood-patch
Browse files Browse the repository at this point in the history
fix: Charnwood BC issues
  • Loading branch information
OliverCullimore authored Dec 1, 2023
2 parents b6641e5 + 4f0e13e commit f6c9cb2
Showing 1 changed file with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
from uk_bin_collection.uk_bin_collection.get_bin_data import \
AbstractGetBinDataClass

from datetime import timedelta
from dateutil.relativedelta import relativedelta


# import the wonderful Beautiful Soup and the URL grabber
class CouncilClass(AbstractGetBinDataClass):
Expand All @@ -18,6 +21,7 @@ def parse_data(self, page: str, **kwargs) -> dict:
soup.prettify()

data = {"bins": []}
curr_date = datetime.today()

for bins in soup.find_all("ul", {"class": "refuse"}):
binCollection = bins.find_all("li")
Expand All @@ -27,11 +31,13 @@ def parse_data(self, page: str, **kwargs) -> dict:
collection_date = bin.find("strong", {"class": "date"}).contents[0].strip()
if collection_date.lower() == "today":
collection_date = datetime.now()
elif collection_date.lower() == "tomorrow":
collection_date = datetime.now() + timedelta(days=1)
else:
collection_date = datetime.strptime(
remove_ordinal_indicator_from_date_string(collection_date).strip(),
"%a %d %b"
)
collection_date = datetime.strptime(remove_ordinal_indicator_from_date_string(collection_date)
.strip(),"%a %d %b").replace(year=curr_date.year)
if curr_date.month == 12 and collection_date.month == 1:
bin_date = bin_date + relativedelta(years=1)
dict_data = {
"type": bin.find("a").contents[0],
"collectionDate": collection_date.strftime(date_format)
Expand Down

0 comments on commit f6c9cb2

Please sign in to comment.