Merge pull request #1058 from 5ila5/ashford_gov_uk

add source ashford_gov_uk
This commit is contained in:
5ila5
2023-07-01 18:56:58 +02:00
committed by GitHub
4 changed files with 172 additions and 1 deletions

View File

@@ -704,6 +704,7 @@ Waste collection schedules in the following formats and countries are supported.
- [Aberdeenshire Council](/doc/source/aberdeenshire_gov_uk.md) / aberdeenshire.gov.uk
- [Amber Valley Borough Council](/doc/source/ambervalley_gov_uk.md) / ambervalley.gov.uk
- [Ashfield District Council](/doc/source/ashfield_gov_uk.md) / ashfield.gov.uk
- [Ashford Borough Council](/doc/source/ashford_gov_uk.md) / ashford.gov.uk
- [Basildon Council](/doc/source/basildon_gov_uk.md) / basildon.gov.uk
- [Basingstoke and Deane Borough Council](/doc/source/basingstoke_gov_uk.md) / basingstoke.gov.uk
- [Bath & North East Somerset Council](/doc/source/bathnes_gov_uk.md) / bathnes.gov.uk

View File

@@ -0,0 +1,115 @@
import requests
from waste_collection_schedule import Collection # type: ignore[attr-defined]
from bs4 import BeautifulSoup, Tag
import re
from datetime import datetime
TITLE = "Ashford Borough Council"
DESCRIPTION = "Source for Ashford Borough Council."
URL = "https://ashford.gov.uk"
TEST_CASES = {
"100060796052": {
"uprn": 100060796052,
"postcode": "TN23 3DY"
},
"100060780440": {
"uprn": "100060780440",
"postcode": "TN24 9JD"
},
"100062558476": {
"uprn": "100062558476",
"postcode": "TN233LX"
},
}
ICON_MAP = {
"household refuse": "mdi:trash-can",
"food waste": "mdi:food",
"garden waste": "mdi:leaf",
"recycling": "mdi:recycle",
}
API_URL = "https://secure.ashford.gov.uk/wastecollections/collectiondaylookup/"
class Source:
def __init__(self, postcode: str, uprn: str | int):
self._uprn = str(uprn).strip()
self._postcode = str(postcode).strip()
self._post_code_args = {"CollectionDayLookup2$Button_PostCodeSearch": "Continue+>"}
self._uprn_args = {"CollectionDayLookup2$Button_SelectAddress": "Continue+>"}
self._post_code_args["CollectionDayLookup2$TextBox_PostCode"] = self._postcode
self._uprn_args["CollectionDayLookup2$DropDownList_Addresses"] = self._uprn
def fetch(self):
# get json file
s = requests.Session()
r = s.get(API_URL)
r.raise_for_status()
soup: BeautifulSoup = BeautifulSoup(r.text, "html.parser")
viewstate = soup.find("input", id="__VIEWSTATE")
viewstate_generator = soup.find("input", id="__VIEWSTATEGENERATOR")
if not viewstate or type(viewstate) != Tag or not viewstate_generator or type(viewstate_generator) != Tag:
raise Exception("could not get valid data from ashford.gov.uk")
self._post_code_args["__VIEWSTATE"] = str(viewstate["value"])
self._post_code_args["__VIEWSTATEGENERATOR"] = str(viewstate_generator["value"])
self._uprn_args["__VIEWSTATEGENERATOR"] = str(viewstate_generator["value"])
r = s.post(API_URL, data=self._post_code_args)
r.raise_for_status()
soup: BeautifulSoup = BeautifulSoup(r.text, "html.parser")
viewstate = soup.find("input", id="__VIEWSTATE")
if not viewstate or type(viewstate) != Tag:
raise Exception("could not get valid data from ashford.gov.uk")
self._uprn_args["__VIEWSTATE"] = str(viewstate["value"])
r = s.post(API_URL, data=self._uprn_args)
if r.status_code != 200:
raise Exception(
f"could not get correct data for your postcode ({self._postcode}). check {API_URL} to validate your arguments.")
soup: BeautifulSoup = BeautifulSoup(r.text, "html.parser")
bin_tables = soup.find_all("table")
if bin_tables == []:
raise Exception(
f"could not get valid data from ashford.gov.uk. is your UPRN ({self._uprn}) correct for postcode ({self._postcode})? check https://uprn.uk/{self._uprn} and {API_URL}")
entries = []
for bin_table in bin_tables:
bin_text = bin_table.find(
"td", id=re.compile("CollectionDayLookup2_td_"))
if not bin_text:
continue
bin_type_soup = bin_text.find("b")
if not bin_type_soup:
continue
bin_type: str = bin_type_soup.text.strip()
date_soup = bin_text.find("span", id=re.compile(r"CollectionDayLookup2_Label_\w*_Date"))
if not date_soup or not " " in date_soup.text.strip():
continue
date_str: str = date_soup.text.strip()
try:
date = datetime.strptime(
date_str.split(" ")[1], "%d/%m/%y").date()
except ValueError:
continue
icon = ICON_MAP.get(bin_type.split("(")[0].strip().lower())
entries.append(Collection(date=date, t=bin_type, icon=icon))
return entries

View File

@@ -0,0 +1,55 @@
# Ashford Borough Council
Support for schedules provided by [Ashford Borough Council](https://ashford.gov.uk), serving Ashford, UK.
## Configuration via configuration.yaml
```yaml
waste_collection_schedule:
sources:
- name: ashford_gov_uk
args:
uprn: UPRN
postcode: POSTCODE
```
### Configuration Variables
**uprn**
*(String | Integer) (required)*
**postcode**
*(String) (required)*
## Example
```yaml
waste_collection_schedule:
sources:
- name: ashford_gov_uk
args:
uprn: 100060796052
postcode: TN23 3DY
```
## How to get the source argument
Use your postcode as `postcode` argument.
### How to get your UPRN
#### From external website
Find the parameter of your address using <https://secure.ashford.gov.uk/wastecollections/collectiondaylookup/> and write them exactly like on the web page.
#### From browser request analasys
- Go to <https://secure.ashford.gov.uk/wastecollections/collectiondaylookup/>.
- Insert you postcode and click `Continue`.
- Open your browsers Inspection tools (`F12` or `right click -> inspect`) and select the network tab.
- Select your address and click `continue`.
- You should now see multiple requests in the network tab. The first one should be (`POST`) `collectiondaylookup/`, select it.
- Select the `Payload` tab of this request.
- You can find your UPRN after `CollectionDayLookup2$DropDownList_Addresses:`

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, 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, Basildon Council, Basingstoke and Deane Borough Council, Bath & North East Somerset Council, Bedford Borough Council, Binzone, Blackburn with Darwen Borough Council, Bracknell Forest Council, Bradford Metropolitan District Council, Braintree District Council, Breckland Council, Bristol City Council, Broadland District 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, 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, Horsham District Council, Huntingdonshire District Council, 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, 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, Sheffield City Council, South Cambridgeshire District Council, South Derbyshire District Council, South Gloucestershire Council, South Hams District Council, South Norfolk Council, South Oxfordshire District Council, South Tyneside 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, Wealden District Council, Welwyn Hatfield Borough Council, West Berkshire Council, West Devon Borough Council, West Dunbartonshire Council, Wigan Council, Wiltshire Council, Wirral Council, Wyre Forest District Council |
| United Kingdom | Aberdeenshire Council, Amber Valley Borough Council, Ashfield District Council, Ashford Borough Council, Basildon Council, Basingstoke and Deane Borough Council, Bath & North East Somerset Council, Bedford Borough Council, Binzone, Blackburn with Darwen Borough Council, Bracknell Forest Council, Bradford Metropolitan District Council, Braintree District Council, Breckland Council, Bristol City Council, Broadland District 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, 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, Horsham District Council, Huntingdonshire District Council, 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, 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, Sheffield City Council, South Cambridgeshire District Council, South Derbyshire District Council, South Gloucestershire Council, South Hams District Council, South Norfolk Council, South Oxfordshire District Council, South Tyneside 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, Wealden District Council, Welwyn Hatfield Borough Council, West Berkshire Council, West Devon Borough Council, West Dunbartonshire Council, Wigan Council, Wiltshire Council, Wirral Council, Wyre Forest District Council |
| United States of America | Albuquerque, New Mexico, USA, 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-->