Adding east herts

This commit is contained in:
gingemonster
2023-01-15 17:33:07 +00:00
parent 87eabc571e
commit 1afe2a9ad2
4 changed files with 160 additions and 1 deletions

View File

@@ -360,6 +360,7 @@ Waste collection schedules in the following formats and countries are supported.
- [Cornwall Council](/doc/source/cornwall_gov_uk.md) / cornwall.gov.uk
- [Derby City Council](/doc/source/derby_gov_uk.md) / derby.gov.uk
- [Eastbourne Borough Council](/doc/source/environmentfirst_co_uk.md) / lewes-eastbourne.gov.uk
- [East Herts Council](/doc/source/eastherts_gov_uk.md) / eastherts.gov.uk
- [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

View File

@@ -0,0 +1,110 @@
from datetime import datetime
import requests
from bs4 import BeautifulSoup
from waste_collection_schedule import Collection # type: ignore[attr-defined]
TITLE = "East Herts Council"
DESCRIPTION = "Source for www.eastherts.gov.uk services for East Herts Council."
URL = "https://www.eastherts.gov.uk"
TEST_CASES = {
"Example": {
"address_postcode": "SG9 9AA",
"address_name_numer": "1 Trove House",
"address_street": "Baldock Road",
},
"Example No Postcode Space": {
"address_postcode": "SG99AA",
"address_name_numer": "1 Trove House",
"address_street": "Baldock Road",
},
}
ICON_MAP = {
"Refuse": "mdi:trash-can",
"Recycling": "mdi:recycle"
}
API_URL = "https://uhte-wrp.whitespacews.com/"
class Source:
def __init__(
self,
address_name_numer=None,
address_street=None,
street_town=None,
address_postcode=None,
):
self._address_name_numer = address_name_numer
self._address_street = address_street
self._street_town = street_town
self._address_postcode = address_postcode
def fetch(self):
session = requests.Session()
# get link from first page as has some kind of unique hash
r = session.get(
API_URL,
)
r.raise_for_status()
soup = BeautifulSoup(r.text, features="html.parser")
alink = soup.find("a", text="Find my bin collection day")
if alink is None:
raise Exception("Initial page did not load correctly")
# greplace 'seq' query string to skip next step
nextpageurl = alink["href"].replace("seq=1", "seq=2")
data = {
"address_name_numer": self._address_name_numer,
"address_street": self._address_street,
"street_town": self._street_town,
"address_postcode": self._address_postcode,
}
# get list of addresses
r = session.post(nextpageurl, data)
r.raise_for_status()
soup = BeautifulSoup(r.text, features="html.parser")
# get first address (if you don't enter enough argument values this won't find the right address)
alink = soup.find("div", id="property_list").find("a")
if alink is None:
raise Exception("Address not found")
nextpageurl = API_URL + alink["href"]
# get collection page
r = session.get(
nextpageurl,
)
r.raise_for_status()
soup = BeautifulSoup(r.text, features="html.parser")
if soup.find("span", id="waste-hint"):
raise Exception("No scheduled services at this address")
u1s = soup.find("section", id="scheduled-collections").find_all("u1")
entries = []
for u1 in u1s:
lis = u1.find_all("li", recursive=False)
entries.append(
Collection(
date=datetime.strptime(
lis[1].text.replace("\n", ""), "%d/%m/%Y"
).date(),
t=lis[2].text.replace("\n", ""),
icon=ICON_MAP.get(
lis[2].text.replace("\n", "").replace(" Collection Service", "")
),
)
)
return entries

View File

@@ -0,0 +1,48 @@
# Waverley Borough Council
Support for schedules provided by [East Herts Council](https://www.eastherts.gov.uk/bins-waste-and-recycling), serving East Herts, UK.
## Configuration via configuration.yaml
```yaml
waste_collection_schedule:
sources:
- name: eastherts_gov_uk
args:
address_postcode: POST_CODE
address_name_numer: HOUSE_NAME_NUMER,
address_street: ADDRESS_STREET,
street_town: STREET_TOWN
version: 1
```
### Configuration Variables
You must supply enough address details for the search to find your property as the first match.
Test this out manually first at [East Herts Council](https://www.eastherts.gov.uk/bins-waste-and-recycling) if you are not sure which are needed.
**POST_CODE**
*(string) (optional)*
**HOUSE_NAME_NUMER**
*(string) (optional)*
**ADDRESS_STREET**
*(string) (optional)*
**STREET_TOWN**
*(string) (optional)*
## Example
```yaml
waste_collection_schedule:
sources:
- name: eastherts_gov_uk
args:
post_code: "SG9 9AA"
address_name_numer: "1 Trove House"
address_street: "Baldock Road"
```

View File

@@ -28,7 +28,7 @@ Waste collection schedules from service provider web sites are updated daily, de
| Poland | Ecoharmonogram, Warsaw |
| Sweden | Landskrona - Svalövs Renhållning, Lerum Vatten och Avlopp, Ronneby Miljöteknik, 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 | Ashfield District 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, City of York Council, Colchester Borough Council, Cornwall Council, Derby City Council, Eastbourne Borough Council, Elmbridge Borough Council, Environment First, FCC Environment, Guildford Borough Council, Harborough District Council, Harlow Council, Horsham District Council, Huntingdonshire District Council, Lewes District Council, London Borough of Lewisham, Manchester City Council, Middlesbrough Council, Newcastle City Council, Newcastle Under Lyme Borough Council, North Somerset Council, Nottingham City Council, Peterborough City Council, Richmondshire District Council, Rushmoor Borough Council, Salford City Council, Sheffield City Council, South Cambridgeshire District Council, South Hams District Council, South Norfolk and Broadland Council, Southampton City Council, Stevenage Borough Council, Telford and Wrekin Council, Tewkesbury Borough Council, The Royal Borough of Kingston Council, Walsall Council, Waverley Borough Council, West Berkshire Council, West Devon Borough Council, Wiltshire Council, Wyre Forest District Council |
| United Kingdom | Ashfield District 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, City of York Council, Colchester Borough Council, Cornwall Council, Derby City Council, Eastbourne Borough Council, East Herts Council, Elmbridge Borough Council, Environment First, FCC Environment, Guildford Borough Council, Harborough District Council, Harlow Council, Horsham District Council, Huntingdonshire District Council, Lewes District Council, London Borough of Lewisham, Manchester City Council, Middlesbrough Council, Newcastle City Council, Newcastle Under Lyme Borough Council, North Somerset Council, Nottingham City Council, Peterborough City Council, Richmondshire District Council, Rushmoor Borough Council, Salford City Council, Sheffield City Council, South Cambridgeshire District Council, South Hams District Council, South Norfolk and Broadland Council, Southampton City Council, Stevenage Borough Council, Telford and Wrekin Council, Tewkesbury Borough Council, The Royal Borough of Kingston Council, Walsall Council, Waverley Borough Council, West Berkshire Council, West Devon Borough Council, Wiltshire Council, Wyre Forest District Council |
| United States of America | City of Pittsburgh, Republic Services, Seattle Public Utilities |
<!--End of country section-->