Added chiltern_gov_uk source (#837)

* Added chiltern.gov.uk source

* Fixed mismatch in date time format that was causing a failure in Home Assistant

* Updated info.md and Readme.md

* Added additional  testcase where uprn is an integer
This commit is contained in:
jkmuk
2023-04-05 12:13:16 +01:00
committed by GitHub
parent c417ed303f
commit 7b9d9ddf11
4 changed files with 109 additions and 1 deletions

View File

@@ -432,6 +432,7 @@ Waste collection schedules in the following formats and countries are supported.
- [Braintree District Council](/doc/source/braintree_gov_uk.md) / braintree.gov.uk
- [Breckland Council](/doc/source/breckland_gov_uk.md) / breckland.gov.uk/mybreckland
- [Bristol City Council](/doc/source/bristol_gov_uk.md) / bristol.gov.uk
- [Buckinghamshire Waste Collection - Former Chiltern, South Bucks or Wycombe areas](/doc/source/chiltern_gov_uk.md) / chiltern.gov.uk
- [Cambridge City Council](/doc/source/cambridge_gov_uk.md) / cambridge.gov.uk
- [Canterbury City Council](/doc/source/canterbury_gov_uk.md) / canterbury.gov.uk
- [Central Bedfordshire Council](/doc/source/centralbedfordshire_gov_uk.md) / centralbedfordshire.gov.uk

View File

@@ -0,0 +1,75 @@
import re
import base64
import json
import requests
from datetime import datetime
from bs4 import BeautifulSoup
from waste_collection_schedule import Collection
TITLE = "Buckinghamshire Waste Collection - Former Chiltern, South Bucks or Wycombe areas"
DESCRIPTION = "Source for chiltern.gov.uk services for parts of Buckinghamshire"
URL = "https://chiltern.gov.uk"
TEST_CASES = {
"Test_001": {"uprn": "200000811701"},
"Test_002": {"uprn": "100080550517"},
"Test_003": {"uprn": "100081091932"},
"Test_004": {"uprn": 10094593823},
}
ICON_MAP = {
"Domestic Refuse Collection": "mdi:trash-can",
"Domestic Food Collection": "mdi:food",
"Domestic Garden Collection": "mdi:leaf",
"Domestic Paper/Card Collection": "mdi:newspaper",
"Domestic Mixed Dry Recycling Collection": "mdi:glass-fragile",
"Communal Paper/Card Collection": "mdi:newspaper",
"Communal Mixed Dry Recycling Collection": "mdi:glass-fragile",
"Communal Refuse Collection": "mdi:trash-can",
}
class Source:
def __init__(self, uprn):
self._uprn = uprn
def fetch(self):
session = requests.Session()
# Start a session
r = session.get("https://chiltern.gov.uk/collection-dates")
r.raise_for_status()
soup = BeautifulSoup(r.text, features="html.parser")
# Extract form submission url
form = soup.find("form", attrs={"id": "COPYOFECHOCOLLECTIONDATES_FORM"})
form_url = form["action"]
# Submit form
form_data = {
"COPYOFECHOCOLLECTIONDATES_FORMACTION_NEXT": "COPYOFECHOCOLLECTIONDATES_ADDRESSSELECTION_NAV1",
"COPYOFECHOCOLLECTIONDATES_ADDRESSSELECTION_SELECTEDADDRESS": "dummy serverside validaiton only",
"COPYOFECHOCOLLECTIONDATES_ADDRESSSELECTION_UPRN": self._uprn,
}
r = session.post(form_url, data=form_data)
r.raise_for_status()
# Extract collection dates
pattern = r'var COPYOFECHOCOLLECTIONDATES_PAGE1_DATES2Data = JSON.parse\(helper\.utilDecode\(\'([^\']+)\'\)\);'
match = re.search (pattern,r.text)
if match:
decoded_jsonstr = base64.b64decode(match.group(1)).decode('utf-8')
servicedata = json.loads(decoded_jsonstr)
entries = []
#Loop through services and append to Collection
for service in servicedata['services']:
entries.append(
Collection(
date=datetime.strptime(service['nextDate'], '%d/%m/%Y').date(),
t=service['serviceName'],
icon=ICON_MAP.get(service['serviceName']),
)
)
return entries

View File

@@ -0,0 +1,32 @@
# Chiltern Area - Buckinghamshire Council
Support for schedules provided by former Chiltern, SouthBucks or Wycombe area, Council](https://chiltern.gov.uk/collection-dates) that covers High Wycombe.
## Configuration via configuration.yaml
```yaml
waste_collection_schedule:
sources:
- name: chiltern_gov_uk
args:
uprn: UPRN
```
### Configuration Variables
**uprn**
*(string) (required)*
## Examples
```yaml
waste_collection_schedule:
sources:
- name: chiltern_gov_uk
args:
uprn: 200000811701
```
## How to get the source argument
Search for your address on the [FindMyAddress service](https://www.findmyaddress.co.uk/) which displays the UPRN in the result.

View File

@@ -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, 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, 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 States of America | City of Pittsburgh, Republic Services, Seattle Public Utilities |
<!--End of country section-->