mirror of
https://github.com/sascha-hemi/hacs_waste_collection_schedule.git
synced 2026-03-21 02:04:22 +01:00
tewkesbury add support for UPRN instead of postcode
This commit is contained in:
@@ -10,6 +10,7 @@ URL = "https://www.tewkesbury.gov.uk"
|
||||
TEST_CASES = {
|
||||
"Council Office": {"postcode": "GL20 5TT"},
|
||||
"Council Office No Spaces": {"postcode": "GL205TT"},
|
||||
"UPRN example": {"uprn": 100120544973},
|
||||
}
|
||||
|
||||
API_URL = "https://api-2.tewkesbury.gov.uk/general/rounds/%s/nextCollection"
|
||||
@@ -23,14 +24,14 @@ ICON_MAP = {
|
||||
|
||||
|
||||
class Source:
|
||||
def __init__(self, postcode: str = None):
|
||||
self._postcode = postcode
|
||||
def __init__(self, postcode: str = None, uprn: str = None):
|
||||
self._post_or_uprn = str(uprn) if uprn else postcode
|
||||
|
||||
def fetch(self):
|
||||
if self._postcode is None:
|
||||
if self._post_or_uprn is None:
|
||||
raise Exception("postcode not set")
|
||||
|
||||
encoded_postcode = urlquote(self._postcode)
|
||||
encoded_postcode = urlquote(self._post_or_uprn)
|
||||
request_url = API_URL % encoded_postcode
|
||||
response = requests.get(request_url)
|
||||
|
||||
@@ -39,16 +40,19 @@ class Source:
|
||||
|
||||
entries = []
|
||||
|
||||
if data["status"] == "OK":
|
||||
schedule = data["body"]
|
||||
for schedule_entry in schedule:
|
||||
entries.append(
|
||||
Collection(
|
||||
date=datetime.strptime(
|
||||
schedule_entry["NextCollection"], "%Y-%m-%d").date(),
|
||||
t=schedule_entry["collectionType"],
|
||||
icon=ICON_MAP.get(schedule_entry["collectionType"])
|
||||
)
|
||||
if data["status"] != "OK":
|
||||
raise Exception(f"Error fetching data. \"{data['status']}\": \n {data['body']}")
|
||||
|
||||
schedule = data["body"]
|
||||
for schedule_entry in schedule:
|
||||
entries.append(
|
||||
Collection(
|
||||
date=datetime.strptime(
|
||||
schedule_entry["NextCollection"], "%Y-%m-%d").date(),
|
||||
t=schedule_entry["collectionType"],
|
||||
icon=ICON_MAP.get(schedule_entry["collectionType"])
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
return entries
|
||||
|
||||
@@ -12,10 +12,24 @@ waste_collection_schedule:
|
||||
postcode: POSTCODE
|
||||
```
|
||||
|
||||
```yaml
|
||||
waste_collection_schedule:
|
||||
sources:
|
||||
- name: tewkesbury_gov_uk
|
||||
args:
|
||||
uprn: UNIQUE PROPERTY REFERENCE NUMBER
|
||||
```
|
||||
|
||||
### Configuration Variables
|
||||
|
||||
**POSTCODE**
|
||||
*(string) (required)*
|
||||
*(string) (optional)*
|
||||
Not all addresses are supported by postcode. Then you have to provide a UPRN.
|
||||
|
||||
**UPRN**
|
||||
*(string) (optional)*
|
||||
|
||||
Either `postcode` or `uprn` must be provided.
|
||||
|
||||
## Example
|
||||
|
||||
@@ -26,3 +40,15 @@ waste_collection_schedule:
|
||||
args:
|
||||
postcode: "GL20 5TT"
|
||||
```
|
||||
|
||||
```yaml
|
||||
waste_collection_schedule:
|
||||
sources:
|
||||
- name: tewkesbury_gov_uk
|
||||
args:
|
||||
uprn: 100120544973
|
||||
```
|
||||
|
||||
## How to find your `UPRN`
|
||||
|
||||
An easy way to find your Unique Property Reference Number (UPRN) is by going to <https://www.findmyaddress.co.uk/> and entering your address details.
|
||||
|
||||
Reference in New Issue
Block a user