Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion uk_bin_collection/tests/input.json
Original file line number Diff line number Diff line change
Expand Up @@ -2122,7 +2122,7 @@
"SouthGloucestershireCouncil": {
"skip_get_url": true,
"uprn": "566419",
"url": "https://beta.southglos.gov.uk/waste-and-recycling-collection-date",
"url": "https://api.southglos.gov.uk/wastecomp/GetCollectionDetails",
"wiki_name": "South Gloucestershire",
"wiki_note": "Provide your UPRN. You can find it using [FindMyAddress](https://www.findmyaddress.co.uk/search).",
"LAD24CD": "E06000025"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@

def format_bin_data(key: str, date: datetime):
formatted_date = date.strftime(date_format)

if re.match(r"^R\d+$", key) is not None:
# RX matches both general waste and recycling
return [
("General Waste (Black Bin)", formatted_date),
("Recycling & Food Waste", formatted_date),
]
elif re.match(r"^G\d+$", key) is not None:
servicename = key.get("hso_servicename")
print(servicename)
if re.match(r"^Recycl", servicename) is not None:
return [ ("Recycling", formatted_date) ]
elif re.match(r"^Refuse", servicename) is not None:
return [("General Waste (Black Bin)", formatted_date)]
elif re.match(r"^Garden", servicename) is not None:
return [("Garden Waste (Green Bin)", formatted_date)]
elif re.match(r"^C\d+$", key) is not None:
return [("Recycling & Food Waste", formatted_date)]
elif re.match(r"^Food", servicename) is not None:
return [("Food Waste", formatted_date)]
else:
return None

Expand All @@ -27,37 +26,34 @@ def parse_data(self, page: str, **kwargs) -> dict:
check_uprn(uprn)

api_url = (
f"https://webapps.southglos.gov.uk/Webservices/SGC.RefuseCollectionService/RefuseCollectionService"
f".svc/getCollections/{uprn}"
f"https://api.southglos.gov.uk/wastecomp/GetCollectionDetails"
f"?uprn={uprn}"
)

headers = {"content-type": "application/json"}

response = requests.get(api_url, headers=headers)

json_response = json.loads(response.content)
json_response = response.json()
if not json_response:
raise ValueError("No collection data found for provided UPRN.")

collection_data = json_response[0]
collection_data = json_response.get('value')

today = datetime.today()
eight_weeks = datetime.today() + timedelta(days=8 * 7)
data = {"bins": []}
collection_tuple = []

for key in collection_data:
if key == "CalendarName":
continue

item = collection_data[key]
for collection in collection_data:
print(collection)
item = collection.get('hso_nextcollection')

if item == "":
continue

collection_date = datetime.strptime(item, date_format)
collection_date = datetime.fromisoformat(item)
if today.date() <= collection_date.date() <= eight_weeks.date():
bin_data = format_bin_data(key, collection_date)
bin_data = format_bin_data(collection, collection_date)
if bin_data is not None:
for bin_date in bin_data:
collection_tuple.append(bin_date)
Expand Down
2 changes: 1 addition & 1 deletion wiki/Councils.md
Original file line number Diff line number Diff line change
Expand Up @@ -3344,7 +3344,7 @@ Note: Replace `XXXXXXXX` with your UPRN. You can find your UPRN using [FindMyAdd

### South Gloucestershire
```commandline
python collect_data.py SouthGloucestershireCouncil https://beta.southglos.gov.uk/waste-and-recycling-collection-date -s -u XXXXXXXX
python collect_data.py SouthGloucestershireCouncil https://api.southglos.gov.uk/wastecomp/GetCollectionDetails -s -u XXXXXXXX
```
Additional parameters:
- `-s` - skip get URL
Expand Down