mirror of
https://github.com/sascha-hemi/hacs_waste_collection_schedule.git
synced 2026-03-21 00:04:11 +01:00
add solihull_gov_uk
This commit is contained in:
@@ -1279,6 +1279,7 @@ Waste collection schedules in the following formats and countries are supported.
|
||||
- [Crawley Borough Council (myCrawley)](/doc/source/crawley_gov_uk.md) / crawley.gov.uk
|
||||
- [Croydon Council](/doc/source/croydon_gov_uk.md) / croydon.gov.uk
|
||||
- [Denbighshire County Council](/doc/source/denbighshire_gov_uk.md) / denbighshire.gov.uk
|
||||
- [Denbighshire County Council](/doc/source/solihull_gov_uk.md) / denbighshire.gov.uk
|
||||
- [Derby City Council](/doc/source/derby_gov_uk.md) / derby.gov.uk
|
||||
- [Dudley Metropolitan Borough Council](/doc/source/dudley_gov_uk.md) / dudley.gov.uk
|
||||
- [Durham County Council](/doc/source/durham_gov_uk.md) / durham.gov.uk
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
import logging
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
import requests
|
||||
from bs4 import BeautifulSoup
|
||||
from waste_collection_schedule import Collection # type: ignore[attr-defined]
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
TITLE = "Denbighshire County Council"
|
||||
DESCRIPTION = "Source for Denbighshire County Council."
|
||||
URL = "https://www.denbighshire.gov.uk/"
|
||||
TEST_CASES = {
|
||||
"100070994046": {"uprn": 100070994046},
|
||||
"200003821723, Predict": {"uprn": 200003821723, "predict": True},
|
||||
}
|
||||
|
||||
ICON_MAP = {
|
||||
"garden waste": "mdi:leaf",
|
||||
"household waste": "mdi:trash-can",
|
||||
"mixed recycling": "mdi:recycle",
|
||||
}
|
||||
|
||||
API_URL = "https://digital.solihull.gov.uk/BinCollectionCalendar/Calendar.aspx"
|
||||
|
||||
|
||||
class Source:
|
||||
def __init__(self, uprn: str | int, predict: bool = False):
|
||||
self._uprn: str | int = uprn
|
||||
self._predict = predict
|
||||
|
||||
def fetch(self) -> list[Collection]:
|
||||
params = {"UPRN": self._uprn}
|
||||
r = requests.get(API_URL, params=params)
|
||||
r.raise_for_status()
|
||||
|
||||
soup = BeautifulSoup(r.text, "html.parser")
|
||||
|
||||
entries = []
|
||||
for card in soup.find_all("div", class_="card-title"):
|
||||
bin_type_tag = card.find("h5") or card.find("h4")
|
||||
bin_type = bin_type_tag.text
|
||||
icon = ICON_MAP.get(bin_type.lower())
|
||||
|
||||
siblings = card.find_next_siblings("div", class_="mt-1")
|
||||
for sibling in siblings:
|
||||
date_tag = sibling.find("strong")
|
||||
if not date_tag:
|
||||
continue
|
||||
date_str = date_tag.text
|
||||
# Wednesday, 19 June 2024
|
||||
try:
|
||||
date = datetime.strptime(date_str, "%A, %d %B %Y").date()
|
||||
except ValueError:
|
||||
_LOGGER.warning(f"Could not parse date {date_str}")
|
||||
continue
|
||||
entries.append(Collection(date=date, t=bin_type, icon=icon))
|
||||
|
||||
if "next" in sibling.text and self._predict:
|
||||
try:
|
||||
# card sibling with no class
|
||||
freq_str = card.find_next_sibling()
|
||||
if not (
|
||||
"every other week" in freq_str.text.lower()
|
||||
or "every week" in freq_str.text.lower()
|
||||
):
|
||||
_LOGGER.info(
|
||||
f"Skipping predikt (unknown frequency) for {freq_str.text}"
|
||||
)
|
||||
continue
|
||||
|
||||
freq = 2 if "every other week" in freq_str.text.lower() else 1
|
||||
for i in range(1, 10 // freq):
|
||||
entries.append(
|
||||
Collection(
|
||||
date=date + timedelta(weeks=i * freq),
|
||||
t=bin_type,
|
||||
icon=icon,
|
||||
)
|
||||
)
|
||||
except Exception as e:
|
||||
_LOGGER.warning(f"Error predicting next collection: {e}")
|
||||
pass
|
||||
|
||||
return entries
|
||||
53
doc/source/solihull_gov_uk.md
Normal file
53
doc/source/solihull_gov_uk.md
Normal file
@@ -0,0 +1,53 @@
|
||||
# Solihull
|
||||
|
||||
Waste collection schedules provided by [Solihull](https://www.solihull.gov.uk/).
|
||||
|
||||
## Configuration via configuration.yaml
|
||||
|
||||
```yaml
|
||||
waste_collection_schedule:
|
||||
sources:
|
||||
- name: solihull_gov_uk
|
||||
args:
|
||||
uprn: UPNR
|
||||
predict: PREDICT
|
||||
```
|
||||
|
||||
### Configuration Variables
|
||||
|
||||
**uprn**
|
||||
*(string|integer) (required)*
|
||||
|
||||
**predict**
|
||||
*(bool) (optional, default=False)*
|
||||
*predict the next 10 weeks of collection dates based on the next collection date and the frequency of collections (only returns the next collection date if set to False)*
|
||||
|
||||
## Example
|
||||
|
||||
### Example 1
|
||||
|
||||
```yaml
|
||||
waste_collection_schedule:
|
||||
sources:
|
||||
- name: solihull_gov_uk
|
||||
args:
|
||||
uprn: 100070994046
|
||||
```
|
||||
|
||||
### Example with prediction
|
||||
|
||||
```yaml
|
||||
waste_collection_schedule:
|
||||
sources:
|
||||
- name: solihull_gov_uk
|
||||
args:
|
||||
uprn: 200003821723
|
||||
predict: True
|
||||
```
|
||||
|
||||
|
||||
## How to get your UPRN
|
||||
|
||||
You can see the uprn in the address bar after searching your address in the [Solihull Council Bincollection Form](https://digital.solihull.gov.uk/BinCollectionCalendar/).
|
||||
|
||||
another easy way to discover your Unique Property Reference Number (UPRN) is by going to <https://www.findmyaddress.co.uk/> and entering in your address details.
|
||||
Reference in New Issue
Block a user