Adding reigate gov uk (#887)

* initial commit

mostly working with the tokenString now recevied from the API. Need to parse the final response still

* Update reigatebanstead_gov_uk.py

icons done
mostly working, just needs date config and tidying up

* Update reigatebanstead_gov_uk.py

min and max dates set correctly

* Delete Untitled-1.json

deleted unwanted test data file

* Update reigatebanstead_gov_uk.py

changed test uprns
added support for commercial refuse collections

* Update info.md

added back reigate after merge conflict

* Update reigatebanstead_gov_uk.md

changed example uprn
This commit is contained in:
JonReed
2023-04-23 12:05:49 +01:00
committed by GitHub
parent 5ec8226adc
commit f76ff10211
4 changed files with 147 additions and 1 deletions

View File

@@ -699,6 +699,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
- [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
- [Rotherham Metropolitan Borough Council](/doc/source/rotherham_gov_uk.md) / rotherham.gov.uk
- [Runnymede Borough Council](/doc/source/runnymede_gov_uk.md) / runnymede.gov.uk

View File

@@ -0,0 +1,113 @@
import json
import requests
import bs4
import xml.etree.ElementTree as ET
from datetime import datetime, timedelta
from time import time_ns
from waste_collection_schedule import Collection # type: ignore[attr-defined]
TITLE = "Reigate & Banstead Borough Council"
DESCRIPTION = "Source for reigate-banstead.gov.uk services for the Reigate & Banstead Borough, UK."
URL = "https://reigate-banstead.gov.uk"
TEST_CASES = {
"Test_001": {"uprn": 68110755},
"Test_002": {"uprn": "000068110755"},
"Test_003": {"uprn": "68101147"}, #commercial refuse collection
"Test_004": {"uprn": "000068101147"}, #commercial refuse collection
}
HEADERS = {
"user-agent": "Mozilla/5.0",
}
ICON_MAP = {
"FOOD WASTE": "mdi:food",
"MIXED RECYCLING": "mdi:recycle",
"GLASS": "mdi:recycle", #commercial
"MIXED CANS": "mdi:recycle", #commercial
"PLASTIC": "mdi:recycle", #commercial
"PAPER AND CARDBOARD": "mdi:newspaper",
"TRADE - PAPER AND CARDBOARD": "mdi:newspaper", #commercial
"REFUSE": "mdi:trash-can",
"TRADE - REFUSE": "mdi:trash-can", #commercial
"GARDEN WASTE": "mdi:leaf",
}
class Source:
def __init__(self, uprn):
self._uprn = str(uprn)
def fetch(self):
s = requests.Session()
# Set up session
timestamp = time_ns() // 1_000_000 # epoch time in milliseconds
session_request = s.get(
f"https://my.reigate-banstead.gov.uk/apibroker/domain/my.reigate-banstead.gov.uk?_={timestamp}",
headers=HEADERS,
)
# This request gets the session ID
sid_request = s.get(
"https://my.reigate-banstead.gov.uk/authapi/isauthenticated?uri=https%3A%2F%2Fmy.reigate-banstead.gov.uk%2Fservice%2FBins_and_recycling___collections_calendar&hostname=my.reigate-banstead.gov.uk&withCredentials=true",
headers=HEADERS
)
sid_data = sid_request.json()
sid = sid_data['auth-session']
# this request gets the 'tokenString' for use later
timestamp = time_ns() // 1_000_000 # epoch time in milliseconds
token_request = s.get(
f"https://my.reigate-banstead.gov.uk/apibroker/runLookup?id=595ce0f243541&repeat_against=&noRetry=true&getOnlyTokens=undefined&log_id=&app_name=AF-Renderer::Self&_={timestamp}&sid={sid}",
headers=HEADERS
)
token_data = token_request.json()
token_string = ET.fromstring(token_data['data'])[0][0][1][0][0].text
# This request retrieves the schedule
timestamp = time_ns() // 1_000_000 # epoch time in milliseconds
min_date = datetime.today().strftime("%Y-%m-%d") #today
max_date = datetime.today() + timedelta(days=28) # max of 28 days ahead
max_date = max_date.strftime("%Y-%m-%d")
payload = {
"formValues": { "Section 1": {"uprnPWB": {"value": self._uprn},
"minDate": {"value": min_date},
"maxDate": {"value": max_date},
"tokenString": {"value": token_string},
}
}
}
schedule_request = s.post(
f"https://my.reigate-banstead.gov.uk/apibroker/runLookup?id=609d41ca89251&repeat_against=&noRetry=true&getOnlyTokens=undefined&log_id=&app_name=AF-Renderer::Self&_={timestamp}&sid={sid}",
headers=HEADERS,
json=payload
)
# oh good, response in JSON... that contains XML... that contains HTML...
rowdata = json.loads(schedule_request.content)['data']
html_rowdata = ET.fromstring(rowdata)[0][0][1][0][0].text
rowdata = bs4.BeautifulSoup(html_rowdata, "html.parser")
datedata = rowdata.findAll("h3")
bindata = rowdata.findAll("ul")
# Extract bin types and next collection dates
x=0
entries = []
for item in bindata:
bin_date = datedata[x].text.strip()
x=x+1
bins = item.findAll('span')
for bin in bins:
bin_type=bin.text.strip()
entries.append(
Collection(
t=bin_type,
date=datetime.strptime(bin_date, "%A %d %B %Y").date(),
icon=ICON_MAP.get(bin.text.upper())
)
)
return entries

View File

@@ -0,0 +1,32 @@
# Reigate & Banstead Borough Council
Support for schedules provided by the [Reigate & Banstead Borough](https://my.reigate-banstead.gov.uk/en/service/Bins_and_recycling___collections_calendar), serving the Reigate & Banstead Borough, UK.
## Configuration via configuration.yaml
```yaml
waste_collection_schedule:
sources:
- name: reigatebanstead_gov_uk
args:
uprn: UPRN_CODE
```
### Configuration Variables
**uprn**
*(string) (required)*
## Example
```yaml
waste_collection_schedule:
sources:
- name: reigatebanstead_gov_uk
args:
uprn: "68110755"
```
## How to find your `UPRN`
An easy way to find your Unique Property Reference Number (UPRN) is by going to <https://www.findmyaddress.co.uk/> and entering your address details.

View File

@@ -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, 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, 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, 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, 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, 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, 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 |
<!--End of country section-->