From ff89ab31b0bbf877729367cbd49d31898f62eaa9 Mon Sep 17 00:00:00 2001 From: 5ila5 <5ila5@users.noreply.github.com> Date: Thu, 30 Mar 2023 12:52:35 +0200 Subject: [PATCH] adding fife_gov_uk --- README.md | 1 + .../source/fife_gov_uk.py | 65 +++++++++++++++++++ doc/source/fife_gov_uk.md | 35 ++++++++++ info.md | 2 +- 4 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 custom_components/waste_collection_schedule/waste_collection_schedule/source/fife_gov_uk.py create mode 100644 doc/source/fife_gov_uk.md diff --git a/README.md b/README.md index d1db8a81..b0a9f500 100644 --- a/README.md +++ b/README.md @@ -450,6 +450,7 @@ Waste collection schedules in the following formats and countries are supported. - [Environment First](/doc/source/environmentfirst_co_uk.md) / environmentfirst.co.uk - [FCC Environment](/doc/source/fccenvironment_co_uk.md) / fccenvironment.co.uk - [Fenland District Council](/doc/source/fenland_gov_uk.md) / fenland.gov.uk +- [Fife Council](/doc/source/fife_gov_uk.md) / fife.gov.uk - [Gateshead Council](/doc/source/gateshead_gov_uk.md) / gateshead.gov.uk - [Glasgow City Council](/doc/source/glasgow_gov_uk.md) / glasgow.gov.uk - [Guildford Borough Council](/doc/source/guildford_gov_uk.md) / guildford.gov.uk diff --git a/custom_components/waste_collection_schedule/waste_collection_schedule/source/fife_gov_uk.py b/custom_components/waste_collection_schedule/waste_collection_schedule/source/fife_gov_uk.py new file mode 100644 index 00000000..906f96cb --- /dev/null +++ b/custom_components/waste_collection_schedule/waste_collection_schedule/source/fife_gov_uk.py @@ -0,0 +1,65 @@ +import requests +from waste_collection_schedule import Collection # type: ignore[attr-defined] +from datetime import datetime + +TITLE = "Fife Council" +DESCRIPTION = "Source for Fife Council." +URL = "https://www.fife.gov.uk" +TEST_CASES = { + "SANDYHILL ROAD, ST ANDREWS": {"uprn": 320069186}, + "CERES ROAD, PITSCOTTIE" : {"uprn": 320063641}, + "SHORE ROAD, BALMALCOLM": {"uprn": "320083539"}, + "CANMORE STREET, DUNFERMLINE": {"uprn": "320101510"}, +} + + +ICON_MAP = { + "Blue": "mdi:trash-can", + "Glass": "mdi:bottle-soda", + "Brown": "mdi:leaf", + "Grey": "mdi:package-variant", + "Green": "mdi:recycle", +} + + +API_URL = "https://www.fife.gov.uk/api/custom" + + +class Source: + def __init__(self, uprn: str | int): + self._uprn: str | int = str(uprn) + + def fetch(self): + session = requests.Session() + auth = session.get("https://www.fife.gov.uk/api/citizen?preview=false&locale=en").headers["Authorization"] + session.headers.update({"Authorization": auth}) + + args = { + "name": "bin_calendar", + "data": {"uprn": self._uprn}, + } + + params = { + "action": "powersuite_bin_calendar_collections", + "actionedby": "bin_calendar", + "loadform": True, + "access": "citizen", + "locale": "en", + } + + # get json file + r = session.post(API_URL, params=params, json=args) + r.raise_for_status() + + data = r.json()["data"] + if data["results_returned"] == "false": + raise Exception("No results returned") + + entries = [] + for d in data["tab_collections"]: + date = datetime.strptime(d["date"], "%A, %B %d, %Y").date() + icon = ICON_MAP.get(d["colour"]) # Collection icon + type = d["type"] + entries.append(Collection(date=date, t=type, icon=icon)) + + return entries diff --git a/doc/source/fife_gov_uk.md b/doc/source/fife_gov_uk.md new file mode 100644 index 00000000..ab7f40c4 --- /dev/null +++ b/doc/source/fife_gov_uk.md @@ -0,0 +1,35 @@ +# Fife Council + +Support for schedules provided by [Fife Council](https://www.fife.gov.uk), serving Fife Council, UK. + +## Configuration via configuration.yaml + +```yaml +waste_collection_schedule: + sources: + - name: fife_gov_uk + args: + uprn: "UPRN" + +``` + +### Configuration Variables + +**uprn** +*(String | Integer) (required)* + +## Example + +```yaml +waste_collection_schedule: + sources: + - name: fife_gov_uk + args: + uprn: "320069189" + +``` + +### How to find your `UPRN` + +An easy way to discover your Unique Property Reference Number (UPRN) is by going to and entering in your address details. +Otherwise you can inspect the web requests the Fife Council website makes when entering in your postcode and then selecting your address. diff --git a/info.md b/info.md index 4c1ad5c7..f38c845f 100644 --- a/info.md +++ b/info.md @@ -30,7 +30,7 @@ Waste collection schedules from service provider web sites are updated daily, de | Slovenia | Moji odpadki, Ljubljana | | Sweden | Jönköping - June Avfall & Miljö, Landskrona - Svalövs Renhållning, Lerum Vatten och Avlopp, Linköping - Tekniska Verken, Region Gotland, Ronneby Miljöteknik, Samverkan Återvinning Miljö (SÅM), SRV Återvinning, SSAM, Sysav Sophämntning, Uppsala Vatten och Avfall AB, VA Syd Sophämntning | | Switzerland | A-Region, Andwil, Appenzell, Berg, Bühler, Eggersriet, Gais, Gaiserwald, Goldach, Grosswangen, Grub, Heiden, Herisau, Horn, Hundwil, Häggenschwil, Lindau, Lutzenberg, Muolen, Mörschwil, Münchenstein, Rehetobel, Rorschach, Rorschacherberg, Schwellbrunn, Schönengrund, Speicher, Stein, Steinach, Teufen, Thal, Trogen, Tübach, Untereggen, Urnäsch, Wald, Waldkirch, Waldstatt, Wittenbach, Wolfhalden | -| United Kingdom | Amber Valley Borough Council, Ashfield District Council, Basingstoke and Deane Borough Council, Binzone, Blackburn with Darwen Borough Council, Bracknell Forest Council, Bradford Metropolitan District Council, Braintree District Council, Breckland Council, Bristol City Council, Cambridge City Council, Canterbury City Council, Central Bedfordshire Council, Cheshire East Council, Chesterfield Borough Council, Chichester District Council, City of Doncaster Council, City of York Council, Colchester City Council, Cornwall Council, Derby City Council, East Cambridgeshire District Council, East Herts Council, East Northamptonshire and Wellingborough, Eastbourne Borough Council, Elmbridge Borough Council, Environment First, FCC Environment, Fenland District Council, Gateshead Council, Glasgow City Council, Guildford Borough Council, Harborough District Council, Harlow Council, Herefordshire City Council, Horsham District Council, Huntingdonshire District Council, Leicester City Council, Lewes District Council, Liverpool City Council, London Borough of Bromley, London Borough of Lewisham, London Borough of Merton, Maldon District Council, Manchester City Council, Mid-Sussex District Council, Middlesbrough Council, Newcastle City Council, Newcastle Under Lyme Borough Council, Newport City Council, North Herts Council, North Lincolnshire Council, North Somerset Council, Nottingham City Council, Oxford City Council, Peterborough City Council, Richmondshire District Council, Rotherham Metropolitan Borough Council, Runnymede Borough Council, Rushmoor Borough Council, Salford City Council, Sheffield City Council, South Cambridgeshire District Council, South Derbyshire District Council, South Hams District Council, South Norfolk and Broadland Council, South Oxfordshire District Council, Southampton City Council, Stevenage Borough Council, Stockport Council, Swindon Borough Council, Telford and Wrekin Council, Tewkesbury Borough Council, The Royal Borough of Kingston Council, Tonbridge and Malling Borough Council, Uttlesford District Council, Vale of White Horse District Council, Walsall Council, Waverley Borough Council, West Berkshire Council, West Devon Borough Council, West Dunbartonshire Council, Wigan Council, Wiltshire Council, Wyre Forest District Council | +| United Kingdom | Amber Valley Borough Council, Ashfield District Council, Basingstoke and Deane Borough Council, Binzone, Blackburn with Darwen Borough Council, Bracknell Forest Council, Bradford Metropolitan District Council, Braintree District Council, Breckland Council, Bristol City Council, Cambridge City Council, Canterbury City Council, Central Bedfordshire Council, Cheshire East Council, Chesterfield Borough Council, Chichester District Council, City of Doncaster Council, City of York Council, Colchester City Council, Cornwall Council, Derby City Council, East Cambridgeshire District Council, East Herts Council, East Northamptonshire and Wellingborough, Eastbourne Borough Council, Elmbridge Borough Council, Environment First, FCC Environment, Fenland District Council, Fife Council, Gateshead Council, Glasgow City Council, Guildford Borough Council, Harborough District Council, Harlow Council, Herefordshire City Council, Horsham District Council, Huntingdonshire District Council, Leicester City Council, Lewes District Council, Liverpool City Council, London Borough of Bromley, London Borough of Lewisham, London Borough of Merton, Maldon District Council, Manchester City Council, Mid-Sussex District Council, Middlesbrough Council, Newcastle City Council, Newcastle Under Lyme Borough Council, Newport City Council, North Herts Council, North Lincolnshire Council, North Somerset Council, Nottingham City Council, Oxford City Council, Peterborough City Council, Richmondshire District Council, Rotherham Metropolitan Borough Council, Runnymede Borough Council, Rushmoor Borough Council, Salford City Council, Sheffield City Council, South Cambridgeshire District Council, South Derbyshire District Council, South Hams District Council, South Norfolk and Broadland Council, South Oxfordshire District Council, Southampton City Council, Stevenage Borough Council, Stockport Council, Swindon Borough Council, Telford and Wrekin Council, Tewkesbury Borough Council, The Royal Borough of Kingston Council, Tonbridge and Malling Borough Council, Uttlesford District Council, Vale of White Horse District Council, Walsall Council, Waverley Borough Council, West Berkshire Council, West Devon Borough Council, West Dunbartonshire Council, Wigan Council, Wiltshire Council, Wyre Forest District Council | | United States of America | City of Pittsburgh, Republic Services, Seattle Public Utilities |