mirror of
https://github.com/sascha-hemi/hacs_waste_collection_schedule.git
synced 2026-03-21 04:06:03 +01:00
add valeofglamorgan_gov_uk
This commit is contained in:
@@ -1413,6 +1413,7 @@ Waste collection schedules in the following formats and countries are supported.
|
||||
- [Tunbridge Wells](/doc/source/tunbridgewells_gov_uk.md) / tunbridgewells.gov.uk
|
||||
- [UK Bin Collection Schedule (UKBCD) project](/doc/source/ukbcd.md) / github.com/robbrad/UKBinCollectionData
|
||||
- [Uttlesford District Council](/doc/source/uttlesford_gov_uk.md) / uttlesford.gov.uk
|
||||
- [Vale of Glamorgan Council](/doc/source/valeofglamorgan_gov_uk.md) / valeofglamorgan.gov.uk
|
||||
- [Vale of White Horse District Council](/doc/source/binzone_uk.md) / whitehorsedc.gov.uk
|
||||
- [Walsall Council](/doc/source/walsall_gov_uk.md) / walsall.gov.uk
|
||||
- [Warrington Borough Council](/doc/source/warrington_gov_uk.md) / warrington.gov.uk
|
||||
|
||||
@@ -0,0 +1,117 @@
|
||||
import json
|
||||
import random
|
||||
from datetime import date, datetime, timedelta
|
||||
|
||||
import requests
|
||||
from bs4 import BeautifulSoup
|
||||
from waste_collection_schedule import Collection # type: ignore[attr-defined]
|
||||
|
||||
TITLE = "Vale of Glamorgan Council"
|
||||
DESCRIPTION = "Source for Vale of Glamorgan Council."
|
||||
URL = "https://valeofglamorgan.gov.uk/"
|
||||
TEST_CASES = {
|
||||
"CF62 7JP": {"uprn": 64003486},
|
||||
"CF32 0PW": {"uprn": 64017161},
|
||||
}
|
||||
|
||||
|
||||
ICON_MAP = {
|
||||
"Trash": "mdi:trash-can",
|
||||
"Food": "mdi:food",
|
||||
"Garden": "mdi:leaf",
|
||||
"Paper": "mdi:package-variant",
|
||||
"Recycle": "mdi:recycle",
|
||||
}
|
||||
|
||||
WEEKDAYS = [
|
||||
"Monday",
|
||||
"Tuesday",
|
||||
"Wednesday",
|
||||
"Thursday",
|
||||
"Friday",
|
||||
"Saturday",
|
||||
"Sunday",
|
||||
]
|
||||
|
||||
API_URL = "https://myvale.valeofglamorgan.gov.uk/getdata.aspx"
|
||||
|
||||
|
||||
class Source:
|
||||
def __init__(self, uprn: str | int):
|
||||
self._uprn: str | int = uprn
|
||||
|
||||
def __get_colltion(self, calendar_url: str, bin_type: str) -> list[Collection]:
|
||||
r = requests.get(calendar_url)
|
||||
r.raise_for_status()
|
||||
soup = BeautifulSoup(r.text, "html.parser")
|
||||
entries = []
|
||||
for tr in soup.select("table tr"):
|
||||
tds = tr.select("td")
|
||||
if len(tds) != 2:
|
||||
continue
|
||||
|
||||
months = tds[0].text.strip()
|
||||
days = tds[1].text.strip().replace("and", ",").split(",")
|
||||
for day in days:
|
||||
day = day.strip()
|
||||
if not day.isdigit():
|
||||
continue
|
||||
date = datetime.strptime(f"{day} {months}", "%d %B %Y").date()
|
||||
entries.append(
|
||||
Collection(date=date, t=bin_type, icon=ICON_MAP[bin_type])
|
||||
)
|
||||
return entries
|
||||
|
||||
def fetch(self) -> list[Collection]:
|
||||
timestamp = str(int(datetime.now().timestamp() * 1000))
|
||||
random_callback_number = str(
|
||||
random.randint(10000000000000000000, 99999999999999999999)
|
||||
)
|
||||
params = {
|
||||
"RequestType": "LocalInfo",
|
||||
"ms": "ValeOfGlamorgan/AllMaps",
|
||||
"group": "Waste|new_refuse",
|
||||
"type": "jsonp",
|
||||
"callback": "AddressInfoCallback",
|
||||
"uid": self._uprn,
|
||||
"import": f"jQuery{random_callback_number}_{timestamp}",
|
||||
"_": timestamp,
|
||||
}
|
||||
|
||||
# get json file
|
||||
r = requests.get(API_URL, params=params)
|
||||
r.raise_for_status()
|
||||
text = r.text
|
||||
text = text.replace("AddressInfoCallback(", "").rstrip(");")
|
||||
data = json.loads(text)["Results"]["waste"]
|
||||
|
||||
entries: list[Collection] = []
|
||||
recycling_food = data["recycling_food"]
|
||||
if recycling_food not in WEEKDAYS:
|
||||
raise ValueError(f"Unknown recycling_food: {recycling_food}")
|
||||
|
||||
next_recycling_food = date.today()
|
||||
while next_recycling_food.weekday() != WEEKDAYS.index(recycling_food):
|
||||
next_recycling_food += timedelta(days=1)
|
||||
|
||||
entries.extend(
|
||||
Collection(
|
||||
date=next_recycling_food + timedelta(weeks=i),
|
||||
t="Recycling",
|
||||
icon=ICON_MAP["Recycle"],
|
||||
)
|
||||
for i in range(10)
|
||||
)
|
||||
entries.extend(
|
||||
Collection(
|
||||
date=next_recycling_food + timedelta(weeks=i),
|
||||
t="Food",
|
||||
icon=ICON_MAP["Food"],
|
||||
)
|
||||
for i in range(10)
|
||||
)
|
||||
|
||||
entries.extend(self.__get_colltion(data["residual_calendar_url"], "Trash"))
|
||||
entries.extend(self.__get_colltion(data["green_calendar_url"], "Garden"))
|
||||
|
||||
return entries
|
||||
36
doc/source/valeofglamorgan_gov_uk.md
Normal file
36
doc/source/valeofglamorgan_gov_uk.md
Normal file
@@ -0,0 +1,36 @@
|
||||
# Vale of Glamorgan Council
|
||||
|
||||
Support for schedules provided by [Vale of Glamorgan Council](https://valeofglamorgan.gov.uk/), serving Vale of Glamorgan Council, UK.
|
||||
|
||||
## Configuration via configuration.yaml
|
||||
|
||||
```yaml
|
||||
waste_collection_schedule:
|
||||
sources:
|
||||
- name: valeofglamorgan_gov_uk
|
||||
args:
|
||||
uprn: "UPRN"
|
||||
|
||||
```
|
||||
|
||||
### Configuration Variables
|
||||
|
||||
**uprn**
|
||||
*(String | Integer) (required)*
|
||||
|
||||
## Example
|
||||
|
||||
```yaml
|
||||
waste_collection_schedule:
|
||||
sources:
|
||||
- name: valeofglamorgan_gov_uk
|
||||
args:
|
||||
uprn: "64003486"
|
||||
|
||||
```
|
||||
|
||||
## How to get the source argument
|
||||
|
||||
An 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.
|
||||
|
||||
Alternatively, you can find your UPRN by inspecting the source code of the Vale of Glamorgan Council's waste collection page after entering your postcode.
|
||||
Reference in New Issue
Block a user