Added support for waste collection for Tewkesbury Borough Council (UK)

This commit is contained in:
Richard Hodgson
2022-12-16 05:46:34 +00:00
parent 6ca6f7cff9
commit 85997d2896
2 changed files with 83 additions and 0 deletions

View File

@@ -0,0 +1,54 @@
from datetime import datetime
from urllib.parse import quote as urlquote
import requests
from waste_collection_schedule import Collection
TITLE = "Tewkesbury Borough Council Waste and Recycling"
DESCRIPTION = "Home waste collection schedule for Tewkesbury Borough Council"
URL = "https://www.tewkesbury.gov.uk/waste-and-recycling"
TEST_CASES = {
"Council Office": {"postcode": "GL20 5TT"},
"Council Office No Spaces": {"postcode": "GL205TT"},
}
API_URL = "https://api-2.tewkesbury.gov.uk/general/rounds/%s/nextCollection"
ICONS = {
"Refuse": "mdi:trash-can",
"Recycling": "mdi:recycle",
"Garden": "mdi:leaf",
"Food": "mdi:silverware-fork-knife",
}
class Source:
def __init__(self, postcode: str = None):
self._postcode = postcode
def fetch(self):
if self._postcode is None:
raise Exception("postcode not set")
encoded_postcode = urlquote(self._postcode)
request_url = API_URL % encoded_postcode
response = requests.get(request_url)
response.raise_for_status()
data = response.json()
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=ICONS.get(schedule_entry["collectionType"])
)
)
return entries

View File

@@ -0,0 +1,29 @@
# Tewkesbury City Council
Support for upcoming schedules provided by [Tewkesbury City Council](https://www.tewkesbury.gov.uk/waste-and-recycling), serving Tewkesbury (UK) and areas of Gloucestershire.
## Configuration via configuration.yaml
```yaml
waste_collection_schedule:
sources:
- name: tewkesbury_gov_uk
args:
postcode: POSTCODE
```
### Configuration Variables
**POST_CODE**<br>
*(string) (required)*
## Example
```yaml
waste_collection_schedule:
sources:
- name: tewkesbury_gov_uk
args:
postcode: "GL20 5TT"
```