adding eastleigh_gov_uk

This commit is contained in:
5ila5
2024-04-23 21:11:06 +02:00
committed by 5ila5
parent b79009bc6c
commit 2ddbb6a10b
4 changed files with 102 additions and 1 deletions

View File

@@ -1242,6 +1242,7 @@ Waste collection schedules in the following formats and countries are supported.
- [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
- [Eastleigh Borough Council](/doc/source/eastleigh_gov_uk.md) / eastleigh.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
- [Exeter City Council](/doc/source/exeter_gov_uk.md) / exeter.gov.uk

View File

@@ -0,0 +1,64 @@
from datetime import datetime
import requests
from bs4 import BeautifulSoup
from waste_collection_schedule import Collection # type: ignore[attr-defined]
TITLE = "Eastleigh Borough Council"
DESCRIPTION = "Source for Eastleigh Borough Council."
URL = "https://eastleigh.gov.uk"
TEST_CASES = {
"100060319000": {"uprn": 100060319000},
"100060300958": {"uprn": "100060300958"},
}
ICON_MAP = {
"Paper": "mdi:package-variant",
"household": "mdi:trash-can",
"recycling": "mdi:recycle",
"food": "mdi:food",
"glass": "mdi:bottle-soda",
"garden": "mdi:leaf",
}
API_URL = "https://eastleigh.gov.uk/waste-bins-and-recycling/collection-dates/your-waste-bin-and-recycling-collections"
class Source:
def __init__(self, uprn: str | int):
self._uprn: str | int = uprn
def fetch(self):
args = {"uprn": self._uprn}
# get json file
r = requests.get(API_URL, params=args)
r.raise_for_status()
soup = BeautifulSoup(r.text, "html.parser")
dls = soup.find_all("dl")
entries = []
for dl in dls:
dts = dl.findAll("dt")
for dt in dts:
dd = dt.find_next_sibling("dd")
if not dd:
continue
try:
# Mon, 29 Apr 2024
date = datetime.strptime(dd.text, "%a, %d %b %Y").date()
except ValueError:
continue
icon = ICON_MAP.get(
dt.text.strip().split(" ")[0].lower()
) # Collection icon
type = dt.text
entries.append(Collection(date=date, t=type, icon=icon))
return entries

View File

@@ -0,0 +1,36 @@
# Eastleigh Borough Council
Support for schedules provided by [Eastleigh Borough Council](https://eastleigh.gov.uk), serving Eastleigh Borough, UK.
## Configuration via configuration.yaml
```yaml
waste_collection_schedule:
sources:
- name: eastleigh_gov_uk
args:
uprn: "UPRN"
```
### Configuration Variables
**uprn**
*(String | Integer) (required)*
## Example
```yaml
waste_collection_schedule:
sources:
- name: eastleigh_gov_uk
args:
uprn: "100060319000"
```
## How to get the source argument
You can see your uprn in your url bar when after selecting your address at <https://eastleigh.gov.uk/waste-bins-and-recycling/collection-dates>
An other way to discover your Unique Property Reference Number (UPRN) is by going to <https://www.findmyaddress.co.uk/> and entering in your address details.

File diff suppressed because one or more lines are too long