Add source for Breckland Council, UK - update

Add ICON_Map
Add support for uprn

Update documentation
This commit is contained in:
bbr111
2022-12-30 11:42:01 +01:00
parent d30b9148f8
commit 53d28c3559
2 changed files with 61 additions and 28 deletions

View File

@@ -8,43 +8,56 @@ DESCRIPTION = "Source for breckland.gov.uk"
URL = "https://www.breckland.gov.uk/mybreckland" URL = "https://www.breckland.gov.uk/mybreckland"
TEST_CASES = { TEST_CASES = {
"test1" : {"postcode":"IP22 2LJ","address":"glen travis" }, "test1" : {"postcode":"IP22 2LJ","address":"glen travis" },
"test2" : {"uprn":"10011977093"},
}
API_URL = "https://www.breckland.gov.uk/apiserver/ajaxlibrary"
ICON_MAP = {
"Refuse Collection Service": "mdi:trash-can",
"Recycling Collection Service": "mdi:recycle",
"Garden Waste Service": "mdi:leaf",
} }
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
headers = {'referer': URL}
class Source: class Source:
def __init__(self,postcode,address): def __init__(self,postcode=None,address=None,uprn=None):
self._postcode = postcode self._postcode = postcode
self._address = address self._address = address
self._uprn = uprn
def fetch(self): def fetch(self):
json_data = { if self._postcode == None and self._address == None and self._uprn == None:
"jsonrpc":"2.0", _LOGGER.error("no attributes - specify postcode and address or just uprn")
"id":"",
"method":"Breckland.Whitespace.JointWasteAPI.GetSiteIDsByPostcode",
"params":{
"postcode":self._postcode,
"environment":"live"
}
}
headers = {'referer': 'https://www.breckland.gov.uk/mybreckland'}
url = 'https://www.breckland.gov.uk/apiserver/ajaxlibrary'
r = requests.post(url, json=json_data,headers=headers)
if r.status_code != 200:
_LOGGER.error("Error querying calender data")
return [] return []
json_response = r.json() if self._uprn == None:
json_data = {
"jsonrpc":"2.0",
"id":"",
"method":"Breckland.Whitespace.JointWasteAPI.GetSiteIDsByPostcode",
"params":{
"postcode":self._postcode,
"environment":"live"
}
}
uprn = "" r = requests.post(API_URL, json=json_data,headers=headers)
for key in json_response['result']:
if self._address.lower() in key['name'].lower():
uprn = (key['uprn'])
if uprn == "": if r.status_code != 200:
_LOGGER.error("Error querying calender data")
return []
json_response = r.json()
for key in json_response['result']:
if self._address.lower() in key['name'].lower():
self._uprn = (key['uprn'])
if self._uprn == None:
_LOGGER.error("Error querying calender data") _LOGGER.error("Error querying calender data")
return [] return []
@@ -53,12 +66,12 @@ class Source:
"id":"", "id":"",
"method":"Breckland.Whitespace.JointWasteAPI.GetBinCollectionsByUprn", "method":"Breckland.Whitespace.JointWasteAPI.GetBinCollectionsByUprn",
"params":{ "params":{
"uprn":uprn, "uprn":self._uprn,
"environment":"live" "environment":"live"
} }
} }
r = requests.post(url, json=json_data,headers=headers) r = requests.post(API_URL, json=json_data,headers=headers)
if r.status_code != 200: if r.status_code != 200:
_LOGGER.error("Error querying calender data") _LOGGER.error("Error querying calender data")
@@ -72,6 +85,10 @@ class Source:
for data in waste: for data in waste:
print(data['collectiontype']) print(data['collectiontype'])
print(data['nextcollection']) print(data['nextcollection'])
entries.append(Collection(datetime.strptime(data['nextcollection'],'%d/%m/%Y %H:%M:%S').date(),data['collectiontype'])) entries.append(Collection(
datetime.strptime(data['nextcollection'],'%d/%m/%Y %H:%M:%S').date(),
data['collectiontype'],
ICON_MAP.get(data['collectiontype'])
))
return entries return entries

View File

@@ -11,16 +11,20 @@ waste_collection_schedule:
args: args:
postcode: POSTCODE postcode: POSTCODE
address: ADDRESS address: ADDRESS
uprn: UPRN
``` ```
### Configuration Variables ### Configuration Variables
**POSTCODE** **POSTCODE**
*(string) (required)* *(string) (optional)*
**ADDRESS** **ADDRESS**
*(string) (required)* *(string) (optional)*
**UPRN**
*(string) (optional)*
## Examples ## Examples
@@ -33,8 +37,20 @@ waste_collection_schedule:
address: "glen travis" address: "glen travis"
``` ```
```yaml
waste_collection_schedule:
sources:
- name: breckland_gov_uk
args:
uprn: "10011977093"
```
If uprn is provided, only uprn is used. Otherwise postcode and address are required.
You can find all relevant informations at [Breckland Council](https://www.breckland.gov.uk/mybreckland) homepage You can find all relevant informations at [Breckland Council](https://www.breckland.gov.uk/mybreckland) homepage
use the POSTCODE -> click find address. use the POSTCODE -> click find address.
Choose your address. Please only use the first part of your address. If you got an error, use less charecters from address. Choose your address. Please only use the first part of your address. If you got an error, use less charecters from address.
## How to find your UPRN
An easy way to discover your Unique Property Reference Number (UPRN) is by going to [Find My Address](https://www.findmyaddress.co.uk/) and providng your address details.