New Source: Wokingham, UK (#1225)

* service wizard format, source .py initial, .md added

* tidy-up

* test cases added

* test cases refined

* .md added, .py tidy-up

* .md

* update_docu_links run

* url update

* payload 'op' format consistency

* helper script moved to wizards folder,  md updated

* script  updated with 'address' option

* typos

* .md updated

* comment removed

* md adding blank lines around headlines and lists
This commit is contained in:
dt215git
2023-09-05 16:44:42 +01:00
committed by GitHub
parent 08f0660e71
commit 2afa495aab
5 changed files with 231 additions and 1 deletions

View File

@@ -884,6 +884,7 @@ Waste collection schedules in the following formats and countries are supported.
- [Windsor and Maidenhead](/doc/source/rbwm_gov_uk.md) / my.rbwm.gov.uk
- [Wirral Council](/doc/source/wirral_gov_uk.md) / wirral.gov.uk
- [Woking Borough Council](/doc/source/jointwastesolutions_org.md) / woking.gov.uk
- [Wokingham Borough Council](/doc/source/wokingham_gov_uk.md) / wokingham.gov.uk
- [Wyre Forest District Council](/doc/source/wyreforestdc_gov_uk.md) / wyreforestdc.gov.uk
</details>

View File

@@ -0,0 +1,114 @@
from datetime import datetime
import requests
from bs4 import BeautifulSoup
from waste_collection_schedule import Collection # type: ignore[attr-defined]
TITLE = "Wokingham Borough Council"
DESCRIPTION = "Source for wokingham.gov.uk services for Wokingham, UK."
URL = "https://wokingham.gov.uk"
API_URL = (
"https://www.wokingham.gov.uk/rubbish-and-recycling/find-your-bin-collection-day"
)
TEST_CASES = {
"Test_001": {"postcode": "RG40 1GE", "property": "56199"},
"Test_002": {"postcode": "RG413BP", "property": "55588"},
"Test_003": {"postcode": "rg41 1ph", "property": 61541},
"Test_004": {"postcode": "RG40 2LW", "address": "16 Davy Close"},
}
ICON_MAP = {
"HOUSEHOLD WASTE AND RECYCLING": "mdi:trash-can",
"GARDEN WASTE": "mdi:leaf",
}
HEADERS = {
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/117.0",
"Content-Type": "application/x-www-form-urlencoded",
"Host": "www.wokingham.gov.uk",
"Origin": "https://www.wokingham.gov.uk",
"Referer": "https://www.wokingham.gov.uk/rubbish-and-recycling/find-your-bin-collection-day",
}
class Source:
def __init__(self, postcode=None, property=None, address=None):
self._postcode = postcode
self._property = property
self._address = address
def get_form_id(self, txt: str) -> str:
soup = BeautifulSoup(txt, "html.parser")
x = soup.find("input", {"name": "form_build_id"})
id = x.get("value")
return id
def match_address(self, lst: list, addr: str) -> str:
for item in lst:
if addr in item.text.replace(",", ""):
a = item.get("value")
return a
def fetch(self):
s = requests.Session()
# Load page to generate token needed for subsequent query
r = s.get(
API_URL,
)
form_id = self.get_form_id(r.text)
# Perform postcode search to generate token needed for following query
self._postcode = str(self._postcode.upper().strip().replace(" ", ""))
payload = {
"postcode_search": self._postcode,
"op": "Find address",
"form_build_id": form_id,
"form_id": "waste_collection_information",
}
r = s.post(
API_URL,
headers=HEADERS,
data=payload,
)
form_id = self.get_form_id(r.text)
# Use address to get an ID if property wasn't supplied. Assumes first match is correct.
if self._property is None:
soup = BeautifulSoup(r.text, "html.parser")
dropdown = soup.find("div", {"class": "form-item__dropdown"})
addresses = dropdown.find_all("option")
self._address = self._address.upper()
self._property = self.match_address(addresses, self._address)
else:
self._property = str(self._property)
# Now get the collection schedule
payload = {
"postcode_search": self._postcode,
"address_options": self._property,
"op": "Show collection dates",
"form_build_id": form_id,
"form_id": "waste_collection_information",
}
r = s.post(
API_URL,
headers=HEADERS,
data=payload,
)
soup = BeautifulSoup(r.text, "html.parser")
tables = soup.find_all("table", {"class": "table--non-responsive"})
# Extract the collection schedules
entries = []
for table in tables:
waste_type = table.find("th").text
waste_date = table.find_all("td")[-1].text
entries.append(
Collection(
date=datetime.strptime(waste_date, "%d/%m/%Y").date(),
t=waste_type,
icon=ICON_MAP.get(waste_type.upper()),
)
)
return entries

View File

@@ -0,0 +1,41 @@
import requests
from bs4 import BeautifulSoup
HEADERS = {
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/117.0",
"Content-Type": "application/x-www-form-urlencoded",
"Host": "www.wokingham.gov.uk",
"Origin": "https://www.wokingham.gov.uk",
"Referer": "https://www.wokingham.gov.uk/rubbish-and-recycling/find-your-bin-collection-day",
}
s = requests.Session()
postcode = input("Enter your postcode: ")
postcode = "".join(postcode.upper().strip().replace(" ", ""))
r = s.get(
"https://www.wokingham.gov.uk/rubbish-and-recycling/find-your-bin-collection-day",
)
soup = BeautifulSoup(r.text, "html.parser")
x = soup.find("input", {"name": "form_build_id"})
form_id = x.get("value")
payload = {
"postcode_search": postcode,
"op": "Find+Address",
"form_build_id": form_id,
"form_id": "waste_collection_information",
}
r = s.post(
"https://www.wokingham.gov.uk/rubbish-and-recycling/find-your-bin-collection-day",
headers=HEADERS,
data=payload,
)
soup = BeautifulSoup(r.text, "html.parser")
dropdown = soup.find("div", {"class": "form-item__dropdown"})
addresses = dropdown.find_all("option")
for item in addresses:
print(item.get("value"), "=", item.text.title().replace(",", ""))

View File

@@ -0,0 +1,74 @@
# Wokingham Borough Council
Support for schedules provided by [Wokingham Borough Council](https://www.wokingham.gov.uk/rubbish-and-recycling/find-your-bin-collection-day"), serving Wokingham, UK.
## Configuration via configuration.yaml
```yaml
waste_collection_schedule:
sources:
- name: wokingham_gov_uk
args:
postcode: POSTCODE
property: PROPERTY_REFERENCE_NUMBER
address: ADDRESS
```
### Configuration Variables
**postcode**
*(string) (required)*
**property**
*(string) (optional)*
**address**
*(string) (optional)*
There are two config options:
- Supply both the `postcode` and `address` args. The script tries to match you address within the results returned from the website and assume the first match it makes is your property.
- Supply both the `postcode` and `property` args. The `property` arg uniquely identified your property within the given postcode. See below for how to identify your property id.
## Example using `address` arg
```yaml
waste_collection_schedule:
sources:
- name: wokingham_gov_uk
args:
postcode: "RG40 2LW"
address: "16 Davy Close"
```
## Example using `property` arg
```yaml
waste_collection_schedule:
sources:
- name: wokingham_gov_uk
args:
postcode: "RG40 1GE"
property: "56199"
```
## How to find your Property Reference Number
When viewing your collection schedule on the [Wokingham](https://www.wokingham.gov.uk/rubbish-and-recycling/find-your-bin-collection-day") web site. Inspect the page source and search for your address. You should seem something like this:
`<option value="17033" selected="selected">16, DAVY CLOSE, WOKINGHAM</option>`
The number in the _value_ attribute should be used as the `property` arg.
Alternatively, you can run the [wokingham_uk](/custom_components/waste_collection_schedule/waste_collection_schedule/wizard/wokingham_uk.py) wizard script. For a given postcode, it will list addresses and associated Property Reference Number. For example:
```bash
Enter your postcode: RG40 1GE
56164 = 2 Samborne Drive Wokingham
56165 = 4 Samborne Drive Wokingham
56166 = 6 Samborne Drive Wokingham
...
56174 = 22 Samborne Drive Wokingham
56175 = 24 Samborne Drive Wokingham
56176 = 26 Samborne Drive Wokingham
```

View File

@@ -32,7 +32,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, 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, Allerdale Borough Council, Amber Valley Borough Council, Ashfield District Council, Ashford Borough Council, Aylesbury Vale District Council, Basildon Council, Basingstoke and Deane Borough Council, Bath & North East Somerset Council, Bedford Borough Council, Binzone, Blackburn with Darwen Borough Council, Borough Council of King's Lynn & West Norfolk, Bracknell Forest Council, Bradford Metropolitan District Council, Braintree District Council, Breckland Council, Bristol City Council, Broadland District Council, Broxtowe Borough Council, Buckinghamshire Waste Collection - Former Chiltern, South Bucks or Wycombe areas, Burnley Council, Cambridge City Council, Canterbury City Council, Cardiff 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, Crawley Borough Council (myCrawley), Croydon Council, Derby City Council, Dudley Metropolitan Borough Council, Durham County Council, East Cambridgeshire District Council, East Herts Council, East Northamptonshire and Wellingborough, East Renfrewshire Council, East Riding of Yorkshire Council, Eastbourne Borough Council, Elmbridge Borough Council, Environment First, Exeter City Council, Fareham Council, FCC Environment, Fenland District Council, Fife Council, Gateshead Council, Glasgow City Council, Guildford Borough Council, Gwynedd, Harborough District Council, Harlow Council, Herefordshire City Council, Highland, Horsham District Council, Huntingdonshire District Council, iTouchVision, Joint Waste Solutions, Kirklees Council, Leicester City Council, Lewes District Council, Lisburn and Castlereagh City Council, Liverpool City Council, London Borough of Bexley, London Borough of Bromley, London Borough of Camden, London Borough of Lewisham, London Borough of Merton, Maidstone Borough Council, Maldon District Council, Manchester City Council, Mendip District Council, Mid-Sussex District Council, Middlesbrough Council, Milton Keynes council, Newcastle City Council, Newcastle Under Lyme Borough Council, Newport City Council, North Herts Council, North Kesteven District Council, North Lincolnshire Council, North Somerset Council, North Yorkshire Council - Hambleton, Nottingham City Council, Oxford City Council, Peterborough City Council, Portsmouth City Council, Reading Council, Redbridge Council, Reigate & Banstead Borough 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, 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 Norfolk Council, South Oxfordshire District Council, South Somerset District Council, South Tyneside Council, Southampton City Council, Stevenage Borough Council, Stockport Council, Stockton-on-Tees Borough Council, Stoke-on-Trent, Stratford District Council, Surrey Heath Borough Council, Swindon Borough Council, Telford and Wrekin Council, Test Valley Borough 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, Warrington Borough Council, Waverley Borough Council, Wealden District Council, Welwyn Hatfield Borough Council, West Berkshire Council, West Devon Borough Council, West Dunbartonshire Council, Wigan Council, Wiltshire Council, Windsor and Maidenhead, Wirral Council, Woking Borough Council, Wyre Forest District Council |
| United Kingdom | Aberdeenshire Council, Allerdale Borough Council, Amber Valley Borough Council, Ashfield District Council, Ashford Borough Council, Aylesbury Vale District Council, Basildon Council, Basingstoke and Deane Borough Council, Bath & North East Somerset Council, Bedford Borough Council, Binzone, Blackburn with Darwen Borough Council, Borough Council of King's Lynn & West Norfolk, Bracknell Forest Council, Bradford Metropolitan District Council, Braintree District Council, Breckland Council, Bristol City Council, Broadland District Council, Broxtowe Borough Council, Buckinghamshire Waste Collection - Former Chiltern, South Bucks or Wycombe areas, Burnley Council, Cambridge City Council, Canterbury City Council, Cardiff 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, Crawley Borough Council (myCrawley), Croydon Council, Derby City Council, Dudley Metropolitan Borough Council, Durham County Council, East Cambridgeshire District Council, East Herts Council, East Northamptonshire and Wellingborough, East Renfrewshire Council, East Riding of Yorkshire Council, Eastbourne Borough Council, Elmbridge Borough Council, Environment First, Exeter City Council, Fareham Council, FCC Environment, Fenland District Council, Fife Council, Gateshead Council, Glasgow City Council, Guildford Borough Council, Gwynedd, Harborough District Council, Harlow Council, Herefordshire City Council, Highland, Horsham District Council, Huntingdonshire District Council, iTouchVision, Joint Waste Solutions, Kirklees Council, Leicester City Council, Lewes District Council, Lisburn and Castlereagh City Council, Liverpool City Council, London Borough of Bexley, London Borough of Bromley, London Borough of Camden, London Borough of Lewisham, London Borough of Merton, Maidstone Borough Council, Maldon District Council, Manchester City Council, Mendip District Council, Mid-Sussex District Council, Middlesbrough Council, Milton Keynes council, Newcastle City Council, Newcastle Under Lyme Borough Council, Newport City Council, North Herts Council, North Kesteven District Council, North Lincolnshire Council, North Somerset Council, North Yorkshire Council - Hambleton, Nottingham City Council, Oxford City Council, Peterborough City Council, Portsmouth City Council, Reading Council, Redbridge Council, Reigate & Banstead Borough 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, 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 Norfolk Council, South Oxfordshire District Council, South Somerset District Council, South Tyneside Council, Southampton City Council, Stevenage Borough Council, Stockport Council, Stockton-on-Tees Borough Council, Stoke-on-Trent, Stratford District Council, Surrey Heath Borough Council, Swindon Borough Council, Telford and Wrekin Council, Test Valley Borough 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, Warrington Borough Council, Waverley Borough Council, Wealden District Council, Welwyn Hatfield Borough Council, West Berkshire Council, West Devon Borough Council, West Dunbartonshire Council, Wigan Council, Wiltshire Council, Windsor and Maidenhead, Wirral Council, Woking Borough Council, Wokingham Borough Council, Wyre Forest District Council |
| United States of America | Albuquerque, New Mexico, USA, 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 |
<!--End of country section-->