add darlington_gov_uk

This commit is contained in:
5ila5
2024-06-25 18:04:42 +02:00
committed by 5ila5
parent 96ba1d238d
commit caddefc00e
4 changed files with 98 additions and 1 deletions

View File

@@ -1278,6 +1278,7 @@ Waste collection schedules in the following formats and countries are supported.
- [Cornwall Council](/doc/source/cornwall_gov_uk.md) / cornwall.gov.uk
- [Crawley Borough Council (myCrawley)](/doc/source/crawley_gov_uk.md) / crawley.gov.uk
- [Croydon Council](/doc/source/croydon_gov_uk.md) / croydon.gov.uk
- [Darlington Borough Council](/doc/source/darlington_gov_uk.md) / darlington.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

View File

@@ -0,0 +1,53 @@
import re
from datetime import date
import requests
from waste_collection_schedule import Collection # type: ignore[attr-defined]
TITLE = "Darlington Borough Council"
DESCRIPTION = "Source for Darlington Borough Council."
URL = "https://darlington.gov.uk"
TEST_CASES = {
"010013315817": {"uprn": 10013315817},
"100110560916": {"uprn": 100110560916},
"200002724471": {"uprn": "200002724471"},
}
ICON_MAP = {
"Recycle": "mdi:recycle",
"Refuse": "mdi:trash-can",
"Garden": "mdi:leaf",
}
API_URL = "https://www.darlington.gov.uk/bins-waste-and-recycling/calendar/"
WASTE_TYPES = ["Recycle", "Refuse", "Garden"]
DATE_REGEX = re.compile(r"calDates.push\(new Date\((\d+)\)\);")
class Source:
def __init__(self, uprn: str | int):
self._uprn: str = str(uprn).zfill(12)
def fetch(self) -> list[Collection]:
args = {"uprn": self._uprn}
entries = []
for waste_type in WASTE_TYPES:
args["collectiontype"] = waste_type
icon = ICON_MAP.get(waste_type)
r = requests.get(API_URL, params=args)
r.raise_for_status()
# find all unix timestamps in the response
dates_list = re.findall(DATE_REGEX, r.text)
for date_str in dates_list:
d = date.fromtimestamp(int(date_str) / 1000)
entries.append(Collection(date=d, t=waste_type, icon=icon))
return entries

View File

@@ -0,0 +1,43 @@
# Darlington Borough Council
Support for schedules provided by [Darlington Borough Council](https://darlington.gov.uk), serving Darlington, UK.
## Configuration via configuration.yaml
```yaml
waste_collection_schedule:
sources:
- name: darlington_gov_uk
args:
uprn: "UPRN"
```
### Configuration Variables
**uprn**
*(String | Integer) (required)*
## Example
```yaml
waste_collection_schedule:
sources:
- name: darlington_gov_uk
args:
uprn: "010013315817"
```
```yaml
waste_collection_schedule:
sources:
- name: darlington_gov_uk
args:
uprn: 100110560916
```
## How to get the source argument
You can find your UPRN in your address bar after searching your address (<https://www.darlington.gov.uk/bins-waste-and-recycling/weekly-refuse-and-recycling-collection-lookup/>) and clicking one of the 'Print `CALENDER_TYPE` calendar' button.
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.

File diff suppressed because one or more lines are too long