mirror of
https://github.com/sascha-hemi/hacs_waste_collection_schedule.git
synced 2026-03-21 02:04:22 +01:00
Added Newark & Sherwood DC (#2240)
* Added Newark & Sherwood DC Added Newark & Sherwood District Council to the UK. * reformatting --------- Co-authored-by: 5ila5 <5ila5@users.noreply.github.com>
This commit is contained in:
@@ -1371,6 +1371,7 @@ Waste collection schedules in the following formats and countries are supported.
|
||||
- [Middlesbrough Council](/doc/source/middlesbrough_gov_uk.md) / middlesbrough.gov.uk
|
||||
- [Milton Keynes council](/doc/source/milton_keynes_gov_uk.md) / milton-keynes.gov.uk
|
||||
- [Moray Council](/doc/source/moray_gov_uk.md) / moray.gov.uk
|
||||
- [Newark & Sherwood District Council](/doc/source/newark_sherwooddc_gov_uk.md) / newark-sherwooddc.gov.uk
|
||||
- [Newcastle City Council](/doc/source/newcastle_gov_uk.md) / community.newcastle.gov.uk
|
||||
- [Newcastle Under Lyme Borough Council](/doc/source/newcastle_staffs_gov_uk.md) / newcastle-staffs.gov.uk
|
||||
- [Newport City Council](/doc/source/newport_gov_uk.md) / newport.gov.uk
|
||||
|
||||
@@ -6013,6 +6013,11 @@
|
||||
"module": "moray_gov_uk",
|
||||
"default_params": {}
|
||||
},
|
||||
{
|
||||
"title": "Newark & Sherwood District Council",
|
||||
"module": "newark_sherwooddc_gov_uk",
|
||||
"default_params": {}
|
||||
},
|
||||
{
|
||||
"title": "Newcastle City Council",
|
||||
"module": "newcastle_gov_uk",
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
import calendar
|
||||
import datetime
|
||||
import re
|
||||
|
||||
import requests
|
||||
from bs4 import BeautifulSoup
|
||||
from waste_collection_schedule import Collection # type: ignore[attr-defined]
|
||||
|
||||
TITLE = "Newark & Sherwood District Council"
|
||||
DESCRIPTION = "Source for Newark & Sherwood services."
|
||||
URL = "https://www.newark-sherwooddc.gov.uk/"
|
||||
TEST_CASES = {
|
||||
"Edwinstowe": {"uprn": "010091747078"},
|
||||
"Ollerton": {"uprn": 100031463343},
|
||||
"Clipstone": {"uprn": "010091745473"},
|
||||
}
|
||||
|
||||
BINS = {
|
||||
"recycle": {"icon": "mdi:recycle", "name": "Recycling"},
|
||||
"refuse": {"icon": "mdi:trash-can", "name": "General"},
|
||||
"garden": {"icon": "mdi:leaf", "name": "Garden"},
|
||||
"glass": {"icon": "mdi:glass-fragile", "name": "Glass"},
|
||||
}
|
||||
|
||||
|
||||
class Source:
|
||||
def __init__(self, uprn):
|
||||
self._uprn = uprn
|
||||
|
||||
def fetch(self):
|
||||
# get json file
|
||||
r = requests.get(
|
||||
"http://app.newark-sherwooddc.gov.uk/bincollection/calendar",
|
||||
params={"pid": self._uprn},
|
||||
)
|
||||
|
||||
entries = []
|
||||
|
||||
soup = BeautifulSoup(r.content, "html.parser")
|
||||
|
||||
# Collections are arranged by month, with each month as an individual table
|
||||
# Split page by months
|
||||
months = soup.find_all("table")
|
||||
|
||||
for month in months:
|
||||
# Month and year are set in th
|
||||
month_data = month.find("th").get_text(strip=True)
|
||||
# Regex the month and year then convert month name to number
|
||||
month_data_match = re.search(r"(\w*)\s*(\d{4})", month_data)
|
||||
extracted_month_name = month_data_match.group(1)
|
||||
month_number = list(calendar.month_name).index(extracted_month_name)
|
||||
year = month_data_match.group(2)
|
||||
|
||||
# Each collection for the month is an individual table row with a classname beginning bin_
|
||||
rows = month.find_all("tr", class_=re.compile("bin_"))
|
||||
for collection_day in rows:
|
||||
# Get type of bin collection
|
||||
collection_type_match = re.search(
|
||||
r"bin_(\w*)", collection_day["class"][0]
|
||||
)
|
||||
collection_type = collection_type_match.group(1)
|
||||
|
||||
# Get date of collection
|
||||
collection_day_match = re.search(
|
||||
r",\s*\w*\s*(\d{1,2})\w{2}",
|
||||
collection_day.find("td").get_text(strip=True),
|
||||
)
|
||||
collection_day = collection_day_match.group(1)
|
||||
|
||||
entries.append(
|
||||
Collection(
|
||||
date=datetime.date(
|
||||
int(year), int(month_number), int(collection_day)
|
||||
), # Collection date
|
||||
t=BINS.get(collection_type, {}).get(
|
||||
"name", collection_type
|
||||
), # Collection type
|
||||
icon=BINS.get(collection_type, {}).get(
|
||||
"icon"
|
||||
), # Collection icon
|
||||
)
|
||||
)
|
||||
|
||||
return entries
|
||||
38
doc/source/newark_sherwooddc_gov_uk.md
Normal file
38
doc/source/newark_sherwooddc_gov_uk.md
Normal file
@@ -0,0 +1,38 @@
|
||||
# Newark & Sherwood District Council
|
||||
|
||||
Support for schedules provided by [Newark & Sherwood District Council](https://app.newark-sherwooddc.gov.uk/bincollection/).
|
||||
|
||||
## Configuration via configuration.yaml
|
||||
|
||||
```yaml
|
||||
waste_collection_schedule:
|
||||
sources:
|
||||
- name: newark_sherwooddc_gov_uk
|
||||
args:
|
||||
uprn: UNIQUE_PROPERTY_REFERENCE_NUMBER
|
||||
```
|
||||
|
||||
### Configuration Variables
|
||||
|
||||
**uprn**
|
||||
_(string) (required)_
|
||||
|
||||
Unique number the council uses to identify your property.
|
||||
|
||||
#### How to find your `UPRN`
|
||||
|
||||
Search for your waste collection schedule at (https://app.newark-sherwooddc.gov.uk/bincollection/). Your `UPRN` is the set of numbers at the end of the url when your schedule is being displayed.
|
||||
|
||||
For example: https://app.newark-sherwooddc.gov.uk/bincollection/calendar?pid=`010091745473`
|
||||
|
||||
_Note:_ You can ignore the `Address` parameter, it's optional.
|
||||
|
||||
## Example
|
||||
|
||||
```yaml
|
||||
waste_collection_schedule:
|
||||
sources:
|
||||
- name: newark_sherwooddc_gov_uk
|
||||
args:
|
||||
uprn: '010091745473'
|
||||
```
|
||||
Reference in New Issue
Block a user