diff --git a/README.md b/README.md
index b3679c319..96a461765 100644
--- a/README.md
+++ b/README.md
@@ -1417,7 +1417,7 @@ Waste collection schedules in the following formats and countries are supported.
- [South Tyneside Council](/doc/source/southtyneside_gov_uk.md) / southtyneside.gov.uk
- [Southampton City Council](/doc/source/southampton_gov_uk.md) / southampton.gov.uk
- [Stafford Borough Council](/doc/source/staffordbc_gov_uk.md) / staffordbc.gov.uk
-- [Stevenage Borough Council](/doc/source/stevenage_gov_uk.md) / stevenage.gov.uk
+- [Stevenage](/doc/source/stevenage_gov_uk.md) / stevenage.gov.uk
- [Stirling.gov.uk](/doc/source/stirling_uk.md) / stirling.gov.uk
- [Stockport Council](/doc/source/stockport_gov_uk.md) / stockport.gov.uk
- [Stockton-on-Tees Borough Council](/doc/source/stockton_gov_uk.md) / stockton.gov.uk
diff --git a/custom_components/waste_collection_schedule/sources.json b/custom_components/waste_collection_schedule/sources.json
index 11f0c6d87..63883a41a 100644
--- a/custom_components/waste_collection_schedule/sources.json
+++ b/custom_components/waste_collection_schedule/sources.json
@@ -5108,6 +5108,11 @@
"module": "lund_se",
"default_params": {}
},
+ {
+ "title": "Norrtalje Vatten & Avfall",
+ "module": "nvaa_se",
+ "default_params": {}
+ },
{
"title": "North / Middle Bohusl\u00e4n - Rambo AB",
"module": "rambo_se",
@@ -6256,7 +6261,7 @@
"default_params": {}
},
{
- "title": "Stevenage Borough Council",
+ "title": "Stevenage",
"module": "stevenage_gov_uk",
"default_params": {}
},
diff --git a/custom_components/waste_collection_schedule/waste_collection_schedule/source/stevenage_gov_uk.py b/custom_components/waste_collection_schedule/waste_collection_schedule/source/stevenage_gov_uk.py
index eff1a1c25..1bcf5b627 100644
--- a/custom_components/waste_collection_schedule/waste_collection_schedule/source/stevenage_gov_uk.py
+++ b/custom_components/waste_collection_schedule/waste_collection_schedule/source/stevenage_gov_uk.py
@@ -1,108 +1,110 @@
-import json
-import requests
-import urllib3
-from datetime import datetime
+import datetime
+import time
+import requests
from waste_collection_schedule import Collection # type: ignore[attr-defined]
-# With verify=True the POST fails due to a SSLCertVerificationError.
-# Using verify=False works, but is not ideal. The following links may provide a better way of dealing with this:
-# https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings
-# https://urllib3.readthedocs.io/en/1.26.x/user-guide.html#ssl
-# This line suppresses the InsecureRequestWarning when using verify=False
-urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
-
-
-TITLE = "Stevenage Borough Council"
-DESCRIPTION = "Source for stevenage.gov.uk services for Stevenage, UK."
-URL = "https://stevenage.gov.uk"
+TITLE = "Stevenage"
+DESCRIPTION = "Source for Stevenage."
+URL = "https://www.stevenage.gov.uk/"
TEST_CASES = {
- "Coopers Close schedule": {"road": "Coopers Close", "postcode": "SG2 9TL"},
- "Wansbeck Close schedule": {"road": "Wansbeck Close", "postcode": "SG1 6AA"},
- "Chepstow Close schedule": {"road": "Chepstow Close", "postcode": "SG1 5TT"},
+ "Chepstow Close": {"uprn": "100080879233"},
+ "Rectory Lane": {"uprn": "100081137566"},
+ "Neptune Gate": {"uprn": "200000585910"},
}
-SEARCH_URLS = {
- "round_search": "https://services.stevenage.gov.uk/~?a=find&v=1&p=P1&c=P1_C33_&act=P1_A43_",
- "collection_search": "https://services.stevenage.gov.uk/~?a=find&v=1&p=P1&c=P1_C37_&act=P1_A64_",
-}
ICON_MAP = {
- "REFUSE": "mdi:trash-can",
- "RECYCLING": "mdi:recycle",
+ "general waste": "mdi:trash-can",
+ "recycling": "mdi:recycle",
}
-COLLECTIONS = {"Rubbish", "Recycling"}
+
+SESSION_URL = "https://stevenage-self.achieveservice.com/authapi/isauthenticated?uri=https%3A%2F%2Fstevenage-self.achieveservice.com%2Fen%2Fservice%2FCheck_your_household_bin_collection_days&hostname=stevenage-self.achieveservice.com&withCredentials=true"
+TOKEN_URL = (
+ "https://stevenage-self.achieveservice.com/apibroker/runLookup?id=5e55337a540d4"
+)
+API_URL = "https://stevenage-self.achieveservice.com/apibroker/runLookup"
class Source:
- def __init__(self, road, postcode):
- self._road = road
- self._postcode = postcode
+ def __init__(self, uprn):
+ self._uprn = str(uprn)
def fetch(self):
+ data = {
+ "formValues": {
+ "Section 1": {
+ "token": {"value": ""},
+ "LLPGUPRN": {
+ "value": self._uprn,
+ },
+ "MinimumDateLookAhead": {
+ "value": time.strftime("%Y-%m-%d"),
+ },
+ "MaximumDateLookAhead": {
+ "value": str(int(time.strftime("%Y")) + 1)
+ + time.strftime("-%m-%d"),
+ },
+ }
+ }
+ }
- s = requests.Session()
-
- # Get Round ID and Round Code
- # Don't fully understand significance of all of the fields, but API borks if they are not present
- roundData = {
- "data": {
- "fields": ["P1_C31_", "P1_C31_", "P1_C105_", "P1_C105_"],
- "rows": [[self._road, self._road, self._postcode, self._postcode]],
- },
- "sequence": 1,
+ headers = {
+ "Content-Type": "application/json",
+ "Accept": "application/json",
+ "User-Agent": "Mozilla/5.0",
+ "X-Requested-With": "XMLHttpRequest",
+ "Referer": "https://stevenage-self.achieveservice.com/fillform/?iframe_id=fillform-frame-1&db_id=",
}
+ s = requests.session()
+ r = s.get(SESSION_URL)
+ r.raise_for_status()
+ session_data = r.json()
+ sid = session_data["auth-session"]
- headers = {"Content-type": "application/json", "Accept": "text/plain"}
- roundRequest = s.post(
- SEARCH_URLS["round_search"], data=json.dumps(roundData), headers=headers, verify=False
- )
- roundJson = json.loads(roundRequest.text)
+ t = s.get(TOKEN_URL)
+ t.raise_for_status()
+ token_data = t.json()
+ data["formValues"]["Section 1"]["token"]["value"] = token_data["integration"][
+ "transformed"
+ ]["rows_data"]["0"]["token"]
- # Get collection info
- collectionData = {
- "data": {
- "fields": [
- "P1_C37_.selectedRowData.id",
- "P1_C37_.selectedRowData.roundCode",
- ],
- "rows": [[roundJson["rows"][0][0], roundJson["rows"][0][2]]],
- },
- "sequence": 1,
- "childQueries": [
- {
- "data": {
- "fields": ["P1_C37_.selectedRowData.id"],
- "rows": [[roundJson["rows"][0][0]]],
- },
- "index": 0,
- }
- ],
+ params = {
+ "id": "64ba8cee353e6",
+ "repeat_against": "",
+ "noRetry": "false",
+ "getOnlyTokens": "undefined",
+ "log_id": "",
+ "app_name": "AF-Renderer::Self",
+ # unix_timestamp
+ "_": str(int(time.time() * 1000)),
+ "sid": sid,
}
- collectionRequest = s.post(
- SEARCH_URLS["collection_search"],
- data=json.dumps(collectionData),
- headers=headers,verify=False
- )
- collectionJson = json.loads(collectionRequest.text)
+ r = s.post(API_URL, json=data, headers=headers, params=params)
+ r.raise_for_status()
+ data = r.json()
+ rows_data = data["integration"]["transformed"]["rows_data"]
+ if not isinstance(rows_data, dict):
+ raise ValueError("Invalid data returned from API")
entries = []
- for collection in collectionJson["rows"]:
- if collection[2] == "Recycling collection":
- entries.append(
- Collection(
- date=datetime.strptime(collection[1], "%d/%m/%Y").date(),
- t="Recycling",
- icon=ICON_MAP.get("RECYCLING"),
- )
- )
- elif collection[2] == "Refuse collection":
- entries.append(
- Collection(
- date=datetime.strptime(collection[1], "%d/%m/%Y").date(),
- t="Refuse",
- icon=ICON_MAP.get("REFUSE"),
- )
+ for key in rows_data:
+ value = rows_data[key]
+ bin_type = value["bintype"].strip()
+
+ try:
+ date = datetime.datetime.strptime(
+ value["collectiondate"], "%A %d %B %Y"
+ ).date()
+ except ValueError:
+ continue
+
+ entries.append(
+ Collection(
+ date=date,
+ t=bin_type,
+ icon=ICON_MAP.get(bin_type.lower()),
)
+ )
return entries
diff --git a/doc/source/stevenage_gov_uk.md b/doc/source/stevenage_gov_uk.md
index 106b94fa4..eebbe5e74 100644
--- a/doc/source/stevenage_gov_uk.md
+++ b/doc/source/stevenage_gov_uk.md
@@ -1,6 +1,6 @@
# Stevenage Borough Council
-Support for schedules provided by [Stevenage Borough Council](https://www.stevenage.gov.uk/waste-and-recycling/your-bin-collections).
+Support for schedules provided by [Stevenage Borough Council](https://stevenage-self.achieveservice.com/service/my_bin_collection_schedule).
## Configuration via configuration.yaml
@@ -9,21 +9,24 @@ waste_collection_schedule:
sources:
- name: stevenage_gov_uk
args:
- postcode: POST_CODE
- road: ROAD
+ uprn: UPRN
```
### Configuration Variables
-**postcode**
+**uprn**
*(string) (required)*
-Postcode of property. This is required. Stevenage Borough Council API does not support UKPRN. Single space between 1st and 2nd part of postcode is optional.
+Unique property reference. This is required. To obtain this value, visit https://stevenage-self.achieveservice.com/service/my_bin_collection_schedule, enter your postcode and Inspect the Select address field. The value of the option associated with your address is your uprn.
-**road**
-*(string) (required)*
-
-Name of road property is in. This is required.
+For example, the UPRN in this example for 100 High Street is **200000586516**
+```html
+
+
+
+
+...
+```
## Example
@@ -32,6 +35,5 @@ waste_collection_schedule:
sources:
- name: stevenage_gov_uk
args:
- postcode: SG2 9TL
- road: Coopers Close
+ uprn: 100080879233
```
diff --git a/info.md b/info.md
index 760446f61..0a3bb2ce6 100644
--- a/info.md
+++ b/info.md
@@ -36,7 +36,7 @@ Waste collection schedules from service provider web sites are updated daily, de
| Slovenia | Moji odpadki, Ljubljana |
| Sweden | Affärsverken, Gästrike Återvinnare, Jönköping - June Avfall & Miljö, Landskrona - Svalövs Renhållning, Lerum Vatten och Avlopp, Linköping - Tekniska Verken, Lund Waste Collection, Norrtalje Vatten & Avfall, North / Middle Bohuslän - Rambo AB, 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, VIVAB Sophämtning |
| Switzerland | A-Region, Alchenstorf, Andwil, Appenzell, Berg, Bühler, Canton of Zürich, Eggersriet, Gais, Gaiserwald, Goldach, Grosswangen, Grub, Heiden, Herisau, Horn, Hundwil, Häggenschwil, Lindau, Lutzenberg, Muolen, Mörschwil, Münchenstein, Münsingen BE, Switzerland, Real Luzern, Rehetobel, Rorschach, Rorschacherberg, Schwellbrunn, Schönengrund, Speicher, Stein, Steinach, Teufen, Thal, Trogen, Tübach, Untereggen, Urnäsch, Wald, Waldkirch, Waldstatt, Wittenbach, Wolfhalden |
-| United Kingdom | Aberdeenshire Council, Adur & Worthing Councils, Allerdale Borough Council, Amber Valley Borough Council, Anglesey, Ards and North Down Borough Council, Ashfield District Council, Ashford Borough Council, Aylesbury Vale District Council, Barnsley Metropolitan Borough Council, Basildon Council, Basingstoke and Deane Borough Council, Bath & North East Somerset Council, BCP Council, Bedford Borough Council, Binzone, Birmingham City Council, Blackburn with Darwen Borough Council, Blackpool Council, Borough Council of King's Lynn & West Norfolk, Borough of Broxbourne Council, Bracknell Forest Council, Bradford Metropolitan District Council, Braintree District Council, Breckland Council, Bristol City Council, Broadland District Council, Bromsgrove City Council, Broxtowe Borough Council, Buckinghamshire Waste Collection - Former Chiltern, South Bucks or Wycombe areas, Burnley Council, Bury Council, Cambridge City Council, Canterbury City Council, Cardiff Council, Central Bedfordshire Council, Cherwell District Council, Cheshire East Council, Cheshire West and Chester Council, Chesterfield Borough Council, Chichester District Council, City of Doncaster Council, City Of Lincoln Council, City of York Council, Colchester City Council, Conwy County Borough Council, Cornwall Council, Crawley Borough Council (myCrawley), Croydon Council, Darlington Borough Council, Denbighshire County Council, Denbighshire County Council, Derby City Council, Dudley Metropolitan Borough Council, Durham County Council, East Ayrshire Council, East Cambridgeshire District Council, East Devon District Council, East Herts Council, East Northamptonshire and Wellingborough, East Renfrewshire Council, East Riding of Yorkshire Council, Eastbourne Borough Council, Eastleigh Borough Council, Elmbridge Borough Council, Environment First, Exeter City Council, Falkirk, Fareham Borough Council, FCC Environment, Fenland District Council, Fife Council, Flintshire, Fylde Council, Gateshead Council, Gedling Borough Council (unofficial), Glasgow City Council, Guildford Borough Council, Gwynedd, Harborough District Council, Haringey Council, Harlow Council, Hart District Council, Herefordshire City Council, Highland, Horsham District Council, Hull City Council, Huntingdonshire District Council, iTouchVision, Joint Waste Solutions, Kirklees Council, Lancaster City Council, Leicester City Council, Lewes District Council, Lichfield District Council, Lisburn and Castlereagh City Council, Liverpool City Council, London Borough of Barking and Dagenham, London Borough of Bexley, London Borough of Bromley, London Borough of Camden, London Borough of Harrow, London Borough of Hounslow, London Borough of Lewisham, London Borough of Merton, London Borough of Newham, Maidstone Borough Council, Maldon District Council, Manchester City Council, Mansfield District Council, Mendip District Council, Mid-Sussex District Council, Middlesbrough Council, Milton Keynes council, Moray Council, Newcastle City Council, Newcastle Under Lyme Borough Council, Newport City Council, North Ayrshire Council, North Herts Council, North Kesteven District Council, North Lincolnshire Council, North Northamptonshire council, North Somerset Council, North West Leicestershire District Council, North Yorkshire Council - Hambleton, North Yorkshire Council - Harrogate, North Yorkshire Council - Scarborough, North Yorkshire Council - Selby, Nottingham City Council, Oxford City Council, Peterborough City Council, Portsmouth City Council, Reading Council, Redbridge Council, Reigate & Banstead Borough Council, Renfrewshire Council, Rhondda Cynon Taf County Borough Council, Richmondshire District Council, Rotherham Metropolitan Borough Council, Runnymede Borough Council, Rushcliffe Brough Council, Rushmoor Borough Council, Salford City Council, Sedgemoor District Council, Sheffield City Council, Shropshire Council, Somerset Council, Somerset County Council, Somerset West & Taunton District Council, South Cambridgeshire District Council, South Derbyshire District Council, South Gloucestershire Council, South Hams District Council, South Holland District Council, South Kesteven District Council, South Norfolk Council, South Oxfordshire District Council, South Somerset District Council, South Tyneside Council, Southampton City Council, Stafford Borough Council, Stevenage Borough Council, Stirling.gov.uk, Stockport Council, Stockton-on-Tees Borough Council, Stoke-on-Trent, Stratford District Council, Surrey Heath Borough Council, Sutton Council, London, Swansea Council, Swindon Borough Council, Tameside Metropolitan Borough Council, Telford and Wrekin Council, Test Valley Borough Council, Tewkesbury Borough Council, The Royal Borough of Kingston Council, Tonbridge and Malling Borough Council, Tunbridge Wells, UK Bin Collection Schedule (UKBCD) project, Uttlesford District Council, Vale of Glamorgan Council, Vale of White Horse District Council, Walsall Council, Warrington Borough Council, Warwick District Council, Waverley Borough Council, Wealden District Council, Welwyn Hatfield Borough Council, West Berkshire Council, West Devon Borough Council, West Dunbartonshire Council, West Northamptonshire council, West Suffolk Council, Westmorland & Furness Council, Barrow area, Westmorland & Furness Council, South Lakeland area, Wigan Council, Wiltshire Council, Windsor and Maidenhead, Wirral Council, Woking Borough Council, Wokingham Borough Council, Wychavon District Council, Wyre Forest District Council |
+| United Kingdom | Aberdeenshire Council, Adur & Worthing Councils, Allerdale Borough Council, Amber Valley Borough Council, Anglesey, Ards and North Down Borough Council, Ashfield District Council, Ashford Borough Council, Aylesbury Vale District Council, Barnsley Metropolitan Borough Council, Basildon Council, Basingstoke and Deane Borough Council, Bath & North East Somerset Council, BCP Council, Bedford Borough Council, Binzone, Birmingham City Council, Blackburn with Darwen Borough Council, Blackpool Council, Borough Council of King's Lynn & West Norfolk, Borough of Broxbourne Council, Bracknell Forest Council, Bradford Metropolitan District Council, Braintree District Council, Breckland Council, Bristol City Council, Broadland District Council, Bromsgrove City Council, Broxtowe Borough Council, Buckinghamshire Waste Collection - Former Chiltern, South Bucks or Wycombe areas, Burnley Council, Bury Council, Cambridge City Council, Canterbury City Council, Cardiff Council, Central Bedfordshire Council, Cherwell District Council, Cheshire East Council, Cheshire West and Chester Council, Chesterfield Borough Council, Chichester District Council, City of Doncaster Council, City Of Lincoln Council, City of York Council, Colchester City Council, Conwy County Borough Council, Cornwall Council, Crawley Borough Council (myCrawley), Croydon Council, Darlington Borough Council, Denbighshire County Council, Denbighshire County Council, Derby City Council, Dudley Metropolitan Borough Council, Durham County Council, East Ayrshire Council, East Cambridgeshire District Council, East Devon District Council, East Herts Council, East Northamptonshire and Wellingborough, East Renfrewshire Council, East Riding of Yorkshire Council, Eastbourne Borough Council, Eastleigh Borough Council, Elmbridge Borough Council, Environment First, Exeter City Council, Falkirk, Fareham Borough Council, FCC Environment, Fenland District Council, Fife Council, Flintshire, Fylde Council, Gateshead Council, Gedling Borough Council (unofficial), Glasgow City Council, Guildford Borough Council, Gwynedd, Harborough District Council, Haringey Council, Harlow Council, Hart District Council, Herefordshire City Council, Highland, Horsham District Council, Hull City Council, Huntingdonshire District Council, iTouchVision, Joint Waste Solutions, Kirklees Council, Lancaster City Council, Leicester City Council, Lewes District Council, Lichfield District Council, Lisburn and Castlereagh City Council, Liverpool City Council, London Borough of Barking and Dagenham, London Borough of Bexley, London Borough of Bromley, London Borough of Camden, London Borough of Harrow, London Borough of Hounslow, London Borough of Lewisham, London Borough of Merton, London Borough of Newham, Maidstone Borough Council, Maldon District Council, Manchester City Council, Mansfield District Council, Mendip District Council, Mid-Sussex District Council, Middlesbrough Council, Milton Keynes council, Moray Council, Newcastle City Council, Newcastle Under Lyme Borough Council, Newport City Council, North Ayrshire Council, North Herts Council, North Kesteven District Council, North Lincolnshire Council, North Northamptonshire council, North Somerset Council, North West Leicestershire District Council, North Yorkshire Council - Hambleton, North Yorkshire Council - Harrogate, North Yorkshire Council - Scarborough, North Yorkshire Council - Selby, Nottingham City Council, Oxford City Council, Peterborough City Council, Portsmouth City Council, Reading Council, Redbridge Council, Reigate & Banstead Borough Council, Renfrewshire Council, Rhondda Cynon Taf County Borough Council, Richmondshire District Council, Rotherham Metropolitan Borough Council, Runnymede Borough Council, Rushcliffe Brough Council, Rushmoor Borough Council, Salford City Council, Sedgemoor District Council, Sheffield City Council, Shropshire Council, Somerset Council, Somerset County Council, Somerset West & Taunton District Council, South Cambridgeshire District Council, South Derbyshire District Council, South Gloucestershire Council, South Hams District Council, South Holland District Council, South Kesteven District Council, South Norfolk Council, South Oxfordshire District Council, South Somerset District Council, South Tyneside Council, Southampton City Council, Stafford Borough Council, Stevenage, Stirling.gov.uk, Stockport Council, Stockton-on-Tees Borough Council, Stoke-on-Trent, Stratford District Council, Surrey Heath Borough Council, Sutton Council, London, Swansea Council, Swindon Borough Council, Tameside Metropolitan Borough Council, Telford and Wrekin Council, Test Valley Borough Council, Tewkesbury Borough Council, The Royal Borough of Kingston Council, Tonbridge and Malling Borough Council, Tunbridge Wells, UK Bin Collection Schedule (UKBCD) project, Uttlesford District Council, Vale of Glamorgan Council, Vale of White Horse District Council, Walsall Council, Warrington Borough Council, Warwick District Council, Waverley Borough Council, Wealden District Council, Welwyn Hatfield Borough Council, West Berkshire Council, West Devon Borough Council, West Dunbartonshire Council, West Northamptonshire council, West Suffolk Council, Westmorland & Furness Council, Barrow area, Westmorland & Furness Council, South Lakeland area, Wigan Council, Wiltshire Council, Windsor and Maidenhead, Wirral Council, Woking Borough Council, Wokingham Borough Council, Wychavon District Council, Wyre Forest District Council |
| United States of America | Albuquerque, New Mexico, USA, City of Austin, TX, City of Bloomington, City of Cambridge, City of Gastonia, NC, City of Georgetown, TX, City of Oklahoma City, City of Pittsburgh, Louisville, Kentucky, USA, Newark, Delaware, USA, Olympia, Washington, USA, ReCollect, Recycle Coach, Republic Services, Seattle Public Utilities, Tucson, Arizona, USA |