diff --git a/custom_components/waste_collection_schedule/waste_collection_schedule/source/huntingdonshire_gov_uk.py b/custom_components/waste_collection_schedule/waste_collection_schedule/source/huntingdonshire_gov_uk.py new file mode 100644 index 00000000..85b5b8ec --- /dev/null +++ b/custom_components/waste_collection_schedule/waste_collection_schedule/source/huntingdonshire_gov_uk.py @@ -0,0 +1,53 @@ +import json +from datetime import datetime + +import requests +from waste_collection_schedule import Collection # type: ignore[attr-defined] + +TITLE = "York.gov.uk" +DESCRIPTION = "Source for Huntingdonshire.gov.uk services for Huntingdonshire District Council." +URL = "https://york.gov.uk" +TEST_CASES = { + "Wells Close, Brampton": {"uprn": "100090123510"}, + "Inkerman Rise, St. Neots": {"uprn": "10000144271"}, +} + +ICONS = { + "Refuse": "mdi:trash-can", + "Recycling": "mdi:recycle", + "Garden": "mdi:leaf", +} + + +class Source: + def __init__(self, uprn): + self._uprn = uprn + + def fetch(self): + # get json file + r = requests.get( + f"https://servicelayer3c.azure-api.net/wastecalendar/collection/search/{self._uprn}?authority=HDC&take=20" + ) + + # extract data from json + data = json.loads(r.text) + + entries = [] + + collections = r.json()["collections"] + entries = [] + + for collection in collections: + for round_type in collection["roundTypes"]: + entries.append( + Collection( + date=datetime.strptime( + collection["date"], "%Y-%m-%dT%H:%M:%SZ" + ).date(), + t=round_type.title(), + icon=ICONS.get(round_type), + ) + ) + + + return entries diff --git a/doc/source/huntingdonshire_gov_uk.md b/doc/source/huntingdonshire_gov_uk.md new file mode 100644 index 00000000..924520de --- /dev/null +++ b/doc/source/huntingdonshire_gov_uk.md @@ -0,0 +1,32 @@ +# Huntingdonshire District Council + +Support for schedules provided by [Huntingdonshire District Council](https://www.huntingdonshire.gov.uk/refuse-calendar), serving Huntingdonshire, UK. + +## Configuration via configuration.yaml + +```yaml +waste_collection_schedule: + sources: + - name: huntingdonshire_gov_uk + args: + uprn: UPRN_CODE +``` + +### Configuration Variables + +**uprn**
+*(string) (required)* + +## Example + +```yaml +waste_collection_schedule: + sources: + - name: huntingdonshire_gov_uk + args: + uprn: "100050580641" +``` + +## How to get the source argument + +The UPRN code can be found in the network request when entering your postcode and selecting your address on the [Huntingdonshire Waste Collection Calendar page](https://www.huntingdonshire.gov.uk/refuse-calendar/). You should look for a request like `https://www.huntingdonshire.gov.uk/refuse-calendar/100090123510` the last segment is your UPRN code.