mirror of
https://github.com/sascha-hemi/hacs_waste_collection_schedule.git
synced 2026-03-21 03:04:09 +01:00
Added support for waste collection for Tewkesbury Borough Council (UK)
This commit is contained in:
@@ -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
|
||||
29
doc/source/tewkesbury_gov_uk.md
Normal file
29
doc/source/tewkesbury_gov_uk.md
Normal 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"
|
||||
```
|
||||
Reference in New Issue
Block a user