Skip to content

Commit

Permalink
Refactor Nottingham City to pull only one date per bin type (#3353)
Browse files Browse the repository at this point in the history
* Refactor Nottingham City to pull only one date per bin type

Nottingham City API sometimes give multiple dates for bins, particularly just after collection date. Locally, it makes sense to only use the smallest of these dates as we want the NEXT collection only.

* Simplify second if statement into min and update comment

* Simplify checks to just filter out collecions further ahead than a year

* Minimize net changes
  • Loading branch information
TurnrDev authored Jan 8, 2025
1 parent 979c343 commit cd60780
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,19 @@ def fetch(self):

next_collections = data["nextCollections"]

# Sometimes the Nottingham City Council API returns collections
# far in the future, so let's only consider the next 12 months

for collection in next_collections:
bin_type = collection["collectionType"]

props = BINS[bin_type]

next_collection_date = datetime.datetime.fromisoformat(
collection["collectionDate"]
)

if next_collection_date > datetime.datetime.now() + datetime.timedelta(years=1):
continue

entries.append(
Collection(
date=next_collection_date.date(),
Expand Down

0 comments on commit cd60780

Please sign in to comment.