added new gateshead council service provider

This commit is contained in:
elibretto
2023-03-25 18:54:03 +00:00
parent 2cfb275004
commit da7f796b34
4 changed files with 123 additions and 1 deletions

View File

@@ -440,6 +440,7 @@ Waste collection schedules in the following formats and countries are supported.
- [Elmbridge Borough Council](/doc/source/elmbridge_gov_uk.md) / elmbridge.gov.uk
- [Environment First](/doc/source/environmentfirst_co_uk.md) / environmentfirst.co.uk
- [FCC Environment](/doc/source/fccenvironment_co_uk.md) / fccenvironment.co.uk
- [Gateshead Council](/doc/source/gateshead_gov_uk.md) / gateshead.gov.uk
- [Glasgow City Council](/doc/source/glasgow_gov_uk.md) / glasgow.gov.uk
- [Guildford Borough Council](/doc/source/guildford_gov_uk.md) / guildford.gov.uk
- [Harborough District Council](/doc/source/fccenvironment_co_uk.md) / harborough.gov.uk

View File

@@ -0,0 +1,88 @@
from datetime import datetime, timedelta
import requests
import re
import json
import base64
from bs4 import BeautifulSoup
from waste_collection_schedule import Collection
TITLE = "Gateshead Council"
DESCRIPTION = "Source for gateshead.gov.uk services for Gateshead"
URL = "gateshead.gov.uk"
TEST_CASES = {
"Test_001": {"uprn": "100000077407"},
"Test_002": {"uprn": "100000058404"},
}
ICON_MAP = {
"Household": "mdi:trash-can",
"Recycling": "mdi:recycle",
"Garden": "mdi:leaf",
}
class Source:
def __init__(self, uprn):
self._uprn = uprn
def fetch(self):
session = requests.Session()
# Start a session
r = session.get("https://www.gateshead.gov.uk/article/3150/Bin-collection-day-checker")
r.raise_for_status()
soup = BeautifulSoup(r.text, features="html.parser")
# Extract form submission url and form data
form_url = soup.find("form", attrs={"id": "BINCOLLECTIONCHECKER_FORM"})["action"]
pageSessionId = soup.find("input", attrs={"name": "BINCOLLECTIONCHECKER_PAGESESSIONID"})["value"]
sessionId = soup.find("input", attrs={"name": "BINCOLLECTIONCHECKER_SESSIONID"})["value"]
nonce = soup.find("input", attrs={"name": "BINCOLLECTIONCHECKER_NONCE"})["value"]
ticks = soup.find("input", attrs={"name": "BINCOLLECTIONCHECKER_ADDRESSSEARCH_TICKS"})["value"]
form_data = {
"BINCOLLECTIONCHECKER_PAGESESSIONID": pageSessionId,
"BINCOLLECTIONCHECKER_SESSIONID": sessionId,
"BINCOLLECTIONCHECKER_NONCE": nonce,
"BINCOLLECTIONCHECKER_ADDRESSSEARCH_TICKS": ticks,
"BINCOLLECTIONCHECKER_FORMACTION_NEXT": "BINCOLLECTIONCHECKER_ADDRESSSEARCH_NEXTBUTTON",
"BINCOLLECTIONCHECKER_ADDRESSSEARCH_UPRN": self._uprn,
}
# Submit form
r = session.post(form_url, data=form_data)
r.raise_for_status()
# Extract encoded response data
soup = BeautifulSoup(r.text, features="html.parser")
pattern = re.compile(r"var BINCOLLECTIONCHECKERFormData = \"(.*?)\";$", re.MULTILINE | re.DOTALL)
script = soup.find("script", text=pattern)
response_data = pattern.search(script.text).group(1)
# Decode base64 encoded response data and convert to JSON
decoded_data = base64.b64decode(response_data)
data = json.loads(decoded_data)
# Extract entries
entries = []
for bin in data["HOUSEHOLDCOLLECTIONS_1"]["DISPLAYHOUSEHOLD2"]["propertyCollections"]["future"]:
dt = datetime.strptime(bin['collectionDate'], '%Y-%m-%dT%H:%M:%S.%fZ')
if dt.hour == 23: # Some collections are returned as 11pm night before the collection
dt += timedelta(hours=1)
date = dt.date()
types = bin['wasteTypeCode'].split("|")
for type in types:
entries.append(
Collection(
date=date,
t=type,
icon=ICON_MAP.get(type),
)
)
return entries

View File

@@ -0,0 +1,33 @@
# Gateshead Council
Support for schedules provided by [Gateshead Council](https://www.gateshead.gov.uk/article/3150/Bin-collection-day-checker).
## Configuration via configuration.yaml
```yaml
waste_collection_schedule:
sources:
- name: gateshead_gov_uk
args:
uprn: UPRN
```
### Configuration Variables
**uprn**
*(string) (required)*
## Examples
```yaml
waste_collection_schedule:
sources:
- name: gateshead_gov_uk
args:
uprn: 010070837598
```
## 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.
Residential Addresses only. Some flat blocks are managed by trade waste companies.

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, 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, Cambridge City Council, Canterbury City Council, Central Bedfordshire Council, Cheshire East Council, Chesterfield Borough Council, Chichester District Council, City of York Council, Colchester City Council, Cornwall Council, Derby City Council, East Cambridgeshire District Council, East Herts Council, Eastbourne Borough Council, Elmbridge Borough Council, Environment First, FCC Environment, 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, 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, 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, Swindon Borough Council, Telford and Wrekin Council, Tewkesbury Borough Council, The Royal Borough of Kingston Council, Uttlesford District Council, Vale of White Horse District Council, Walsall Council, Waverley Borough Council, West Berkshire Council, West Devon Borough 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, Cambridge City Council, Canterbury City Council, Central Bedfordshire Council, Cheshire East Council, Chesterfield Borough Council, Chichester District Council, City of York Council, Colchester City Council, Cornwall Council, Derby City Council, East Cambridgeshire District Council, East Herts Council, Eastbourne Borough Council, Elmbridge Borough Council, Environment First, FCC Environment, 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, 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, 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, Swindon Borough Council, Telford and Wrekin Council, Tewkesbury Borough Council, The Royal Borough of Kingston Council, Uttlesford District Council, Vale of White Horse District Council, Walsall Council, Waverley Borough Council, West Berkshire Council, West Devon Borough 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-->