Initial commit - North Yorkshire Scarborough

This commit is contained in:
ReneNulschDE
2024-04-23 17:01:15 +02:00
committed by 5ila5
parent 503eef57c9
commit b79009bc6c
4 changed files with 102 additions and 1 deletions

View File

@@ -1302,6 +1302,7 @@ Waste collection schedules in the following formats and countries are supported.
- [North West Leicestershire District Council](/doc/source/nwleics_gov_uk.md) / nwleics.gov.uk
- [North Yorkshire Council - Hambleton](/doc/source/northyorks_hambleton_gov_uk.md) / northyorks.gov.uk
- [North Yorkshire Council - Harrogate](/doc/source/northyorks_harrogate_gov_uk.md) / secure.harrogate.gov.uk
- [North Yorkshire Council - Scarborough](/doc/source/northyorks_scarborough_gov_uk.md) / northyorks.gov.uk
- [North Yorkshire Council - Selby](/doc/source/northyorks_selby_gov_uk.md) / northyorks.gov.uk
- [Nottingham City Council](/doc/source/nottingham_city_gov_uk.md) / nottinghamcity.gov.uk
- [Oxford City Council](/doc/source/oxford_gov_uk.md) / oxford.gov.uk

View File

@@ -0,0 +1,66 @@
from datetime import datetime
import requests
from bs4 import BeautifulSoup
from waste_collection_schedule import Collection # type: ignore[attr-defined]
TITLE = "North Yorkshire Council - Scarborough"
DESCRIPTION = "Source for North Yorkshire Council - Scarborough."
URL = "https://northyorks.gov.uk"
TEST_CASES = {
"100052176620": {"uprn": 100050497178},
"10013454353": {"uprn": "100052161572"},
}
ICON_MAP = {
"Household waste": "mdi:trash-can",
"Garden": "mdi:leaf",
"Recycling": "mdi:recycle",
}
API_URL = "https://www.northyorks.gov.uk/bin-calendar/Scarborough/results/{uprn}/ajax?_wrapper_format=drupal_ajax"
class Source:
def __init__(self, uprn: str | int):
self._uprn: str = str(uprn)
def fetch(self):
r = requests.post(API_URL.format(uprn=self._uprn))
r.raise_for_status()
html = None
for res in r.json():
if "data" in res and isinstance(res["data"], str):
html = res["data"]
break
if not html or "Unfortunately we were unable to find your property" in html:
raise Exception("No data found, invalid UPRN?")
soup = BeautifulSoup(html, "html.parser")
rows = (
soup.find("div", id="upcoming-collection")
.find("table")
.find("tbody")
.find_all("tr")
)
entries = []
for row in rows:
tds = row.find_all("td")
if not tds or len(tds) < 3:
continue
date_str = tds[0].text
date = datetime.strptime(date_str, "%d %B %Y").date()
bin_types = [br.next_sibling.strip() for br in tds[2].find_all("i")]
if not bin_types:
continue
for bin_type in bin_types:
icon = ICON_MAP.get(bin_type.split(" ")[0])
entries.append(Collection(date=date, t=bin_type, icon=icon))
return entries

View File

@@ -0,0 +1,34 @@
# North Yorkshire Council - Selby
Support for schedules provided by [North Yorkshire Council - Scarborough](https://northyorks.gov.uk), serving North Yorkshire Council - Scarborough, UK.
## Configuration via configuration.yaml
```yaml
waste_collection_schedule:
sources:
- name: northyorks_scarborough_gov_uk
args:
uprn: "UPRN"
```
### Configuration Variables
**uprn**
_(String | Integer) (required)_
## Example
```yaml
waste_collection_schedule:
sources:
- name: northyorks_scarborough_gov_uk
args:
uprn: "100050497178"
```
## How to get the source argument
You can find your Unique Property Reference Number (UPRN) by visiting the [North Yorkshire Council - Scarborough](https://www.northyorks.gov.uk/bin-calendar/lookup) website and entering your address details. You should now see your collection dates. You UPRN will be in the URL of the page. For example, if the URL is `https://www.northyorks.gov.uk/bin-calendar/Scarborough/results/100050497178`, then your UPRN is `100050497178`.
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