New Source: Bexley, UK (#875)

* initial commit

* requests implemented, test cases added

* tidy-up

* bexley md added

* update_docu_link run

* uprn padding added

* initial session_request simplified
This commit is contained in:
dt215git
2023-04-13 21:19:03 +01:00
committed by GitHub
parent d74b4d1541
commit e5df071692
4 changed files with 114 additions and 1 deletions

View File

@@ -522,6 +522,7 @@ Waste collection schedules in the following formats and countries are supported.
- [Leicester City Council](/doc/source/biffaleicester_co_uk.md) / leicester.gov.uk
- [Lewes District Council](/doc/source/environmentfirst_co_uk.md) / lewes-eastbourne.gov.uk
- [Liverpool City Council](/doc/source/liverpool_gov_uk.md) / liverpool.gov.uk
- [London Borough of Bexley](/doc/source/bexley_gov_uk.md) / bexley.gov.uk
- [London Borough of Bromley](/doc/source/bromley_gov_uk.md) / bromley.gov.uk
- [London Borough of Lewisham](/doc/source/lewisham_gov_uk.md) / lewisham.gov.uk
- [London Borough of Merton](/doc/source/merton_gov_uk.md) / merton.gov.uk

View File

@@ -0,0 +1,80 @@
import json
import requests
from datetime import datetime
from time import time_ns
from waste_collection_schedule import Collection # type: ignore[attr-defined]
TITLE = "London Borough of Bexley"
DESCRIPTION = "Source for bexley.gov.uk services for the London Borough of Bexley, UK."
URL = "https://bexley.gov.uk"
TEST_CASES = {
"Test_001": {"uprn": "200001604426"},
"Test_002": {"uprn": 100020194783},
"Test_003": {"uprn": "100020195768"},
"Test_004": {"uprn": 100020200324},
}
HEADERS = {
"user-agent": "Mozilla/5.0",
}
ICON_MAP = {
"FOOD 23 LTR CADDY": "mdi:food",
"PLASTIC 55 LTR BOX": "mdi:recycle",
"PAPER & CARDBOARD & 55 LTR BOX": "mdi:newspaper",
"GLASS 55 LTR BOX": "mdi:glass-fragile",
"RESIDUAL 180 LTR BIN": "mdi:trash-can",
"PLASTICS & GLASS 240 LTR WHEELED BIN": "mdi:recycle",
"PAPER & CARD 180 LTR WHEELED BIN": "mdi:newspaper",
"GARDEN 240 LTR BIN": "mdi:leaf",
}
class Source:
def __init__(self, uprn):
self._uprn = str(uprn).zfill(12)
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://mybexley.bexley.gov.uk/apibroker/domain/mybexley.bexley.gov.uk?_={timestamp}",
headers=HEADERS,
)
# This request gets the session ID
sid_request = s.get(
"https://mybexley.bexley.gov.uk/authapi/isauthenticated?uri=https%3A%2F%2Fmybexley.bexley.gov.uk%2Fservice%2FWhen_is_my_collection_day&hostname=mybexley.bexley.gov.uk&withCredentials=true",
headers=HEADERS
)
sid_data = sid_request.json()
sid = sid_data['auth-session']
# This request retrieves the schedule
timestamp = time_ns() // 1_000_000 # epoch time in milliseconds
payload = {
"formValues": { "What is your address?": {"txtUPRN": {"value": self._uprn}}}
}
schedule_request = s.post(
f"https://mybexley.bexley.gov.uk/apibroker/runLookup?id=61320b2acf8a3&repeat_against=&noRetry=false&getOnlyTokens=undefined&log_id=&app_name=AF-Renderer::Self&_={timestamp}&sid={sid}",
headers=HEADERS,
json=payload
)
rowdata = json.loads(schedule_request.content)['integration']['transformed']['rows_data']
# Extract bin types and next collection dates
entries = []
for item in rowdata:
entries.append(
Collection(
t=rowdata[item]["ContainerName"],
date=datetime.strptime(
rowdata[item]["NextCollectionDate"], "%Y-%m-%dT%H:%M:%S"
).date(),
icon=ICON_MAP.get(rowdata[item]["ContainerName"].upper()),
)
)
return entries

View File

@@ -0,0 +1,32 @@
# London Borough of Bexley
Support for schedules provided by the [London Borough of Bexley](https://mybexley.bexley.gov.uk/service/When_is_my_collection_day), serving the London Borough of Bexley, UK.
## Configuration via configuration.yaml
```yaml
waste_collection_schedule:
sources:
- name: bexley_gov_uk
args:
uprn: UPRN_CODE
```
### Configuration Variables
**uprn**
*(string) (required)*
## Example
```yaml
waste_collection_schedule:
sources:
- name: bexley_gov_uk
args:
uprn: "100020194783"
```
## 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, 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, 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, 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, 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, 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 States of America | City of Oklahoma City, City of Pittsburgh, Republic Services, Seattle Public Utilities |
<!--End of country section-->