mirror of
https://github.com/sascha-hemi/hacs_waste_collection_schedule.git
synced 2026-03-21 03:04:09 +01:00
add east_renfrewshire_gov_uk (#1179)
* add east_renfrewshire_gov_uk * reformatting (@5ila5)
This commit is contained in:
@@ -766,6 +766,7 @@ Waste collection schedules in the following formats and countries are supported.
|
||||
- [East Cambridgeshire District Council](/doc/source/eastcambs_gov_uk.md) / eastcambs.gov.uk
|
||||
- [East Herts Council](/doc/source/eastherts_gov_uk.md) / eastherts.gov.uk
|
||||
- [East Northamptonshire and Wellingborough](/doc/source/east_northamptonshire_gov_uk.md) / east-northamptonshire.gov.uk
|
||||
- [East Renfrewshire Council](/doc/source/east_renfrewshire_gov_uk.md) / eastrenfrewshire.gov.uk
|
||||
- [East Riding of Yorkshire Council](/doc/source/eastriding_gov_uk.md) / eastriding.gov.uk
|
||||
- [Eastbourne Borough Council](/doc/source/environmentfirst_co_uk.md) / lewes-eastbourne.gov.uk
|
||||
- [Elmbridge Borough Council](/doc/source/elmbridge_gov_uk.md) / elmbridge.gov.uk
|
||||
|
||||
@@ -0,0 +1,129 @@
|
||||
import base64
|
||||
import json
|
||||
import re
|
||||
from urllib.parse import parse_qs, urlparse
|
||||
|
||||
import requests
|
||||
from bs4 import BeautifulSoup
|
||||
from dateutil import parser
|
||||
from waste_collection_schedule import Collection # type: ignore[attr-defined]
|
||||
|
||||
TITLE = "East Renfrewshire Council"
|
||||
DESCRIPTION = "Source for eastrenfrewshire.gov.uk services for East Renfrewshire"
|
||||
URL = "https://www.eastrenfrewshire.gov.uk"
|
||||
|
||||
TEST_CASES = {
|
||||
"Test_001": {"postcode": "G78 2TJ", "uprn": "131016859"},
|
||||
"Test_002": {"postcode": "g775ar", "uprn": 131019331},
|
||||
"Test_003": {"postcode": "g78 3er", "uprn": "000131020112"},
|
||||
}
|
||||
|
||||
ICON_MAP = {
|
||||
"Grey": "mdi:trash-can",
|
||||
"Brown": "mdi:leaf",
|
||||
"Green": "mdi:glass-fragile",
|
||||
"Blue": "mdi:note",
|
||||
}
|
||||
|
||||
|
||||
class Source:
|
||||
def __init__(self, postcode, uprn):
|
||||
self._postcode = postcode
|
||||
self._uprn = str(uprn).zfill(12)
|
||||
|
||||
def fetch(self):
|
||||
session = requests.Session()
|
||||
address_page = self.__get_address_page(session, self._postcode)
|
||||
bin_collection_info_page = self.__get_bin_collection_info_page(
|
||||
session, address_page, self._uprn
|
||||
)
|
||||
bin_collection_info = self.__get_bin_collection_info(bin_collection_info_page)
|
||||
return self.__generate_collection_entries(bin_collection_info)
|
||||
|
||||
def __generate_collection_entries(self, bin_collection_info):
|
||||
collection_results = bin_collection_info["residualWasteResponse"]["value"][
|
||||
"collectionResults"
|
||||
]
|
||||
entries = []
|
||||
for collection in collection_results["binsOrderingArray"]:
|
||||
for collection_date in collection["collectionDates"]:
|
||||
entries.append(
|
||||
Collection(
|
||||
date=parser.parse(collection_date).date(),
|
||||
t=collection["color"],
|
||||
icon=ICON_MAP.get(collection["color"]),
|
||||
)
|
||||
)
|
||||
return entries
|
||||
|
||||
def __get_bin_collection_info(self, bin_collection_info_page):
|
||||
serialized_collection_info_pattern = re.compile(
|
||||
r'var RESIDUALWASTEV2SerializedVariables = "(.*?)";$',
|
||||
re.MULTILINE | re.DOTALL,
|
||||
)
|
||||
soup = BeautifulSoup(bin_collection_info_page, "html.parser")
|
||||
script = soup.find("script", text=serialized_collection_info_pattern)
|
||||
if not script:
|
||||
raise Exception(
|
||||
"no script tag cannot find RESIDUALWASTEV2SerializedVariables"
|
||||
)
|
||||
match = serialized_collection_info_pattern.search(script.text)
|
||||
if not match:
|
||||
raise Exception("no match cannot find RESIDUALWASTEV2SerializedVariables")
|
||||
serialized_collection_info = match.group(1)
|
||||
collection_info = json.loads(base64.b64decode(serialized_collection_info))
|
||||
return collection_info
|
||||
|
||||
def __get_bin_collection_info_page(self, session, address_page, uprn):
|
||||
soup = BeautifulSoup(address_page, "html.parser")
|
||||
form = soup.find(id="RESIDUALWASTEV2_FORM")
|
||||
goss_ids = self.__get_goss_form_ids(form["action"])
|
||||
r = session.post(
|
||||
form["action"],
|
||||
data={
|
||||
"RESIDUALWASTEV2_PAGESESSIONID": goss_ids["page_session_id"],
|
||||
"RESIDUALWASTEV2_SESSIONID": goss_ids["session_id"],
|
||||
"RESIDUALWASTEV2_NONCE": goss_ids["nonce"],
|
||||
"RESIDUALWASTEV2_VARIABLES": "e30=",
|
||||
"RESIDUALWASTEV2_PAGENAME": "PAGE2",
|
||||
"RESIDUALWASTEV2_PAGEINSTANCE": "1",
|
||||
"RESIDUALWASTEV2_PAGE2_FIELD201": "true",
|
||||
"RESIDUALWASTEV2_PAGE2_UPRN": uprn,
|
||||
"RESIDUALWASTEV2_FORMACTION_NEXT": "RESIDUALWASTEV2_PAGE2_FIELD206",
|
||||
"RESIDUALWASTEV2_PAGE2_FIELD202": "false",
|
||||
"RESIDUALWASTEV2_PAGE2_FIELD203": "false",
|
||||
},
|
||||
)
|
||||
r.raise_for_status()
|
||||
return r.text
|
||||
|
||||
def __get_address_page(self, s, postcode):
|
||||
r = s.get("https://www.eastrenfrewshire.gov.uk/bin-days")
|
||||
r.raise_for_status()
|
||||
soup = BeautifulSoup(r.text, "html.parser")
|
||||
form = soup.find(id="RESIDUALWASTEV2_FORM")
|
||||
goss_ids = self.__get_goss_form_ids(form["action"])
|
||||
r = s.post(
|
||||
form["action"],
|
||||
data={
|
||||
"RESIDUALWASTEV2_PAGESESSIONID": goss_ids["page_session_id"],
|
||||
"RESIDUALWASTEV2_SESSIONID": goss_ids["session_id"],
|
||||
"RESIDUALWASTEV2_NONCE": goss_ids["nonce"],
|
||||
"RESIDUALWASTEV2_VARIABLES": "e30=",
|
||||
"RESIDUALWASTEV2_PAGENAME": "PAGE1",
|
||||
"RESIDUALWASTEV2_PAGEINSTANCE": "0",
|
||||
"RESIDUALWASTEV2_PAGE1_POSTCODE": postcode,
|
||||
"RESIDUALWASTEV2_FORMACTION_NEXT": "RESIDUALWASTEV2_PAGE1_FIELD199",
|
||||
},
|
||||
)
|
||||
r.raise_for_status()
|
||||
return r.text
|
||||
|
||||
def __get_goss_form_ids(self, url):
|
||||
parsed_form_url = urlparse(url)
|
||||
form_url_values = parse_qs(parsed_form_url.query)
|
||||
return {
|
||||
"page_session_id": form_url_values["pageSessionId"][0],
|
||||
"session_id": form_url_values["fsid"][0],
|
||||
"nonce": form_url_values["fsn"][0],
|
||||
}
|
||||
37
doc/source/east_renfrewshire_gov_uk.md
Normal file
37
doc/source/east_renfrewshire_gov_uk.md
Normal file
@@ -0,0 +1,37 @@
|
||||
# East Renfrewshire Council
|
||||
|
||||
Support for schedules provided by [East Renfrewshire Council](https://www.eastrenfrewshire.gov.uk/bin-days).
|
||||
|
||||
## Configuration via configuration.yaml
|
||||
|
||||
```yaml
|
||||
waste_collection_schedule:
|
||||
sources:
|
||||
- name: east_renfrewshire_gov_uk
|
||||
args:
|
||||
postcode: POSTCODE
|
||||
uprn: UNIQUE_PROPERTY_REFERENCE_NUMBER
|
||||
```
|
||||
|
||||
### Configuration Variables
|
||||
|
||||
**postcode**
|
||||
*(string) (required)*
|
||||
|
||||
**uprn**
|
||||
*(string) (required)*
|
||||
|
||||
## Example
|
||||
|
||||
```yaml
|
||||
waste_collection_schedule:
|
||||
sources:
|
||||
- name: east_renfrewshire_gov_uk
|
||||
args:
|
||||
postcode: "G78 2TJ"
|
||||
uprn: "131016859"
|
||||
```
|
||||
|
||||
## 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.
|
||||
2
info.md
2
info.md
@@ -31,7 +31,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, 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, East Cambridgeshire District Council, East Herts Council, East Northamptonshire and Wellingborough, 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, 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 Lewisham, London Borough of Merton, Maidstone Borough Council, Maldon District Council, Manchester City Council, Mendip District Council, Mid-Sussex District Council, Middlesbrough 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, Nottingham City Council, Oxford City Council, Peterborough City Council, Portsmouth City Council, Reading Council, Redbridge Council, Reigate & Banstead 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, 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, 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, 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 Lewisham, London Borough of Merton, Maidstone Borough Council, Maldon District Council, Manchester City Council, Mendip District Council, Mid-Sussex District Council, Middlesbrough 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, Nottingham City Council, Oxford City Council, Peterborough City Council, Portsmouth City Council, Reading Council, Redbridge Council, Reigate & Banstead 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 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-->
|
||||
|
||||
|
||||
Reference in New Issue
Block a user