diff --git a/README.md b/README.md index c1821177..9eec4ba8 100644 --- a/README.md +++ b/README.md @@ -703,6 +703,7 @@ Waste collection schedules in the following formats and countries are supported. - [Nottingham City Council](/doc/source/nottingham_city_gov_uk.md) / nottinghamcity.gov.uk - [Oxford City Council](/doc/source/oxford_gov_uk.md) / oxford.gov.uk - [Peterborough City Council](/doc/source/peterborough_gov_uk.md) / peterborough.gov.uk +- [Portsmouth City Council](/doc/source/portsmouth_gov_uk.md) / portsmouth.gov.uk - [Reading Council](/doc/source/reading_gov_uk.md) / reading.gov.uk - [Reigate & Banstead Borough Council](/doc/source/reigatebanstead_gov_uk.md) / reigate-banstead.gov.uk - [Richmondshire District Council](/doc/source/richmondshire_gov_uk.md) / richmondshire.gov.uk diff --git a/custom_components/waste_collection_schedule/waste_collection_schedule/source/portsmouth_gov_uk.py b/custom_components/waste_collection_schedule/waste_collection_schedule/source/portsmouth_gov_uk.py new file mode 100644 index 00000000..f2f2b3ea --- /dev/null +++ b/custom_components/waste_collection_schedule/waste_collection_schedule/source/portsmouth_gov_uk.py @@ -0,0 +1,77 @@ +import logging +import requests +import time + +from datetime import datetime +from waste_collection_schedule import Collection + +TITLE = 'Portsmouth City Council' +DESCRIPTION = 'Source for waste collection services for Portsmouth City Council' +URL = 'https://www.portsmouth.gov.uk' +TEST_CASES = { + "Fawcett Road - number" : {"uprn": 1775027540}, + "Fawcett Road - string" : {"uprn": "1775027540"}, + "Westbourne Road - number" : {"uprn": 1775084532}, + "Westbourne Road - string" : {"uprn": "1775084532"} +} + +API_URLS = { + 'session': 'https://my.portsmouth.gov.uk/en/AchieveForms/?form_uri=sandbox-publish://AF-Process-26e27e70-f771-47b1-a34d-af276075cede/AF-Stage-cd7cc291-2e59-42cc-8c3f-1f93e132a2c9/definition.json&redirectlink=%2F&cancelRedirectLink=%2F', + 'auth': 'https://my.portsmouth.gov.uk/authapi/isauthenticated?uri=https%3A%2F%2Fmy.portsmouth.gov.uk%2Fen%2FAchieveForms%2F%3Fform_uri%3Dsandbox-publish%3A%2F%2FAF-Process-26e27e70-f771-47b1-a34d-af276075cede%2FAF-Stage-cd7cc291-2e59-42cc-8c3f-1f93e132a2c9%2Fdefinition.json%26redirectlink%3D%252F%26cancelRedirectLink%3D%252F&hostname=my.portsmouth.gov.uk&withCredentials=true', + 'schedule': 'https://my.portsmouth.gov.uk/apibroker/runLookup?id=5e81ed10c0241&repeat_against=&noRetry=true&getOnlyTokens=undefined&log_id=&app_name=AF-Renderer::Self&_=1682697046055&sid=93c73ba547e8c23e85a50a1de67a5ca7' +} + +HEADERS = { + "user-agent": "Mozilla/5.0", +} + +COOKIES = { +} + +_LOGGER = logging.getLogger(__name__) + +class Source: + def __init__(self, uprn: str): + self._uprn = str(uprn) + def fetch(self): + s = requests.Session() + + #This request sets up the cookies + r0 = s.get(API_URLS['session'], headers=HEADERS) + r0.raise_for_status() + + #This request gets the session key from the PHPSESSID (in the cookies) + authRequest = s.get(API_URLS['auth'], headers=HEADERS) + authData = authRequest.json() + sessionKey = authData['auth-session'] + now = time.time_ns() // 1_000_000 + + #now query using the uprn + payload = { + "formValues": { "Section 1": { "col_uprn": { "value": self._uprn } } } + } + scheduleRequest = s.post(API_URLS['schedule'] + '&_' + str(now) + '&sid=' + sessionKey , headers=HEADERS, json=payload) + data = scheduleRequest.json()['integration']['transformed']['rows_data']['0'] + + rubbishDates = data['listRefDatesHTML'].split('
') + recyclingDates = data['listRecDatesHTML'].split('
') + + entries = [] + + for date in rubbishDates: + if len(date) > 0: + entries.append(Collection( + date = datetime.strptime(date, '%A %d %B %Y').date(), + t = 'refuse bin', + icon = 'mdi:trash-can' + )) + + for date in recyclingDates: + if len(date) > 0: + entries.append(Collection( + date = datetime.strptime(date, '%A %d %B %Y').date(), + t = 'recycling bin', + icon = 'mdi:recycle' + )) + + return entries \ No newline at end of file diff --git a/doc/source/portsmouth_gov_uk.md b/doc/source/portsmouth_gov_uk.md new file mode 100644 index 00000000..f0372f0b --- /dev/null +++ b/doc/source/portsmouth_gov_uk.md @@ -0,0 +1,34 @@ +# Portsmouth City Council + +Support for schedules provided by [Portsmouth City Council](https://www.portsmouth.gov.uk/). + +If collection data is available for the address provided, it will return rubbish and recycling waste collection dates. + +## Configuration via configuration.yaml + +```yaml +waste_collection_schedule: + sources: + - name: portsmouth_gov_uk + args: + uprn: UPRN +``` + +### Configuration Variables + +**uprn** +*(string) (required)* + +## Examples + +```yaml +waste_collection_schedule: + sources: + - name: portsmouth_gov_uk + args: + uprn: 1775027540 +``` + +## How to find your UPRN + +An easy way to discover your Unique Property Reference Number (UPRN) is by going to [Find My Address](https://www.findmyaddress.co.uk/) and providng your address details. diff --git a/info.md b/info.md index 068867af..be276975 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 | Affärsverken, 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, Basildon Council, Basingstoke and Deane Borough Council, Bedford Borough Council, Binzone, Blackburn with Darwen Borough Council, Bracknell Forest Council, Bradford Metropolitan District Council, Braintree District Council, Breckland Council, Bristol City Council, Buckinghamshire Waste Collection - Former Chiltern, South Bucks or Wycombe areas, Cambridge City Council, Canterbury City Council, Central Bedfordshire Council, Cherwell District 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, Fareham Council, 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 Bexley, 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, Reading Council, Reigate & Banstead Borough 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, South Tyneside Council, Southampton City Council, Stevenage Borough Council, Stockport Council, Stockton-on-Tees Borough 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, Basildon Council, Basingstoke and Deane Borough Council, Bedford Borough Council, Binzone, Blackburn with Darwen Borough Council, Bracknell Forest Council, Bradford Metropolitan District Council, Braintree District Council, Breckland Council, Bristol City Council, Buckinghamshire Waste Collection - Former Chiltern, South Bucks or Wycombe areas, Cambridge City Council, Canterbury City Council, Central Bedfordshire Council, Cherwell District 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, Fareham Council, 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 Bexley, 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, Portsmouth City Council, Reading Council, Reigate & Banstead Borough 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, South Tyneside Council, Southampton City Council, Stevenage Borough Council, Stockport Council, Stockton-on-Tees Borough 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 Oklahoma City, City of Pittsburgh, Republic Services, Seattle Public Utilities |