From ad4750e2d59dd1d0bfa114d7728657a71d8dd552 Mon Sep 17 00:00:00 2001 From: Richard Date: Mon, 22 Sep 2025 17:51:37 +0100 Subject: [PATCH] fix: #1566 South Gloucestershire Council --- uk_bin_collection/tests/input.json | 2 +- .../councils/SouthGloucestershireCouncil.py | 40 +++++++++---------- wiki/Councils.md | 2 +- 3 files changed, 20 insertions(+), 24 deletions(-) diff --git a/uk_bin_collection/tests/input.json b/uk_bin_collection/tests/input.json index dbb15183c8..27eda9109b 100755 --- a/uk_bin_collection/tests/input.json +++ b/uk_bin_collection/tests/input.json @@ -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" diff --git a/uk_bin_collection/uk_bin_collection/councils/SouthGloucestershireCouncil.py b/uk_bin_collection/uk_bin_collection/councils/SouthGloucestershireCouncil.py index 1b74c0c0f4..3058e74d20 100644 --- a/uk_bin_collection/uk_bin_collection/councils/SouthGloucestershireCouncil.py +++ b/uk_bin_collection/uk_bin_collection/councils/SouthGloucestershireCouncil.py @@ -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 @@ -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) diff --git a/wiki/Councils.md b/wiki/Councils.md index e04a39c6c8..d32e5aeee3 100644 --- a/wiki/Councils.md +++ b/wiki/Councils.md @@ -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