tewkesbury add support for UPRN instead of postcode

This commit is contained in:
5ila5
2023-04-20 18:01:01 +02:00
parent 579ddeb3fc
commit 013a2c1e72
2 changed files with 45 additions and 15 deletions

View File

@@ -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,7 +40,9 @@ class Source:
entries = []
if data["status"] == "OK":
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(
@@ -51,4 +54,5 @@ class Source:
)
)
return entries

View File

@@ -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.