Skip to content

Commit

Permalink
licoln_gov_uk use actual collection frequency to populate furute bin …
Browse files Browse the repository at this point in the history
…collections
  • Loading branch information
5ila5 committed Oct 4, 2024
1 parent 9124816 commit f43ff81
Showing 1 changed file with 18 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import json
from datetime import datetime
from datetime import datetime, timedelta
from time import time_ns

import requests
Expand Down Expand Up @@ -30,9 +30,9 @@


BIN_TYPES = [
("refusenextdate", "Refuse"),
("recyclenextdate", "Recycling"),
("gardennextdate", "Garden"),
("refusenextdate", "Refuse", "refuse_freq"),
("recyclenextdate", "Recycling", "recycle_freq"),
("gardennextdate", "Garden", "garden_freq"),
]


Expand Down Expand Up @@ -100,17 +100,21 @@ def fetch(self):
for uprn, data in rowdata.items():
if uprn != self._uprn:
continue
bin_types = BIN_TYPES.copy()
if data["recyclenextdate"] != data["refusenextdate"]:
bin_types.append(("recyclenextdate", "Refuse"))
for key, bin_type in bin_types:
for key, bin_type, freq in BIN_TYPES:
if not data[key]:
continue
entries.append(
Collection(
t=bin_type,
date=datetime.strptime(data[key], "%Y-%m-%d").date(),
icon=ICON_MAP.get(bin_type),
offsets = [0]
if data[freq] == "fortnightly":
offsets.extend(list(range(14, 365, 14)))
elif data[freq] == "weekly":
offsets.extend(list(range(7, 365, 7)))
date = datetime.strptime(data[key], "%Y-%m-%d").date()
for offset in offsets:
entries.append(
Collection(
t=bin_type,
date=date + timedelta(days=offset),
icon=ICON_MAP.get(bin_type),
)
)
)
return entries

0 comments on commit f43ff81

Please sign in to comment.