Added support for Brisbane City Countil bin collection

This commit is contained in:
Tristan
2021-03-05 13:40:32 +10:00
parent 1e7ab438d4
commit b4d94a9a83
3 changed files with 164 additions and 0 deletions

View File

@@ -45,6 +45,10 @@ The information in the more-info popup can be displayed in different formats:
Currently the following service providers are supported:
### Australia
- [Brisbane City Council](./doc/source/brisbane_qld_gov_au.md)
### Germany
- [Abfall.IO / AbfallPlus.de](./doc/source/abfall_io.md)

View File

@@ -0,0 +1,117 @@
from datetime import date, timedelta
import json
import requests
from ..helpers import CollectionAppointment
DESCRIPTION = "Source for Brisbane City Council rubbish collection."
URL = "https://www.brisbane.qld.gov.au/clean-and-green/rubbish-tips-and-bins/rubbish-collections/bin-collection-calendar"
TEST_CASES = {
"Suburban Social": {
"suburb": "Chapel Hill",
"street_name": "Moordale St",
"street_number": "3",
},
"The Scratch Bar": {
"suburb": "Milton",
"street_name": "Park Rd",
"street_number": "8/1",
},
"Green Beacon": {
"suburb": "Teneriffe",
"street_name": "Helen St",
"street_number": "26",
}
}
class Source:
def __init__(self, suburb, street_name, street_number):
self.suburb = suburb
self.street_name = street_name
self.street_number = street_number
def fetch(self):
suburb_id = 0
street_id = 0
property_id = 0
today = date.today()
nextmonth = today + timedelta(30)
# Retrieve suburbs
r = requests.get(
f"https://brisbane.waste-info.com.au/api/v1/localities.json"
)
data = json.loads(r.text)
# Find the ID for our suburb
for item in data['localities']:
if item['name'] == self.suburb:
suburb_id = item['id']
break
if suburb_id == 0:
return []
# Retrieve the streets in our suburb
r = requests.get(
f"https://brisbane.waste-info.com.au/api/v1/streets.json?locality={suburb_id}"
)
data = json.loads(r.text)
# Find the ID for our street
for item in data['streets']:
if item['name'] == self.street_name:
street_id = item['id']
break
if street_id == 0:
return []
# Retrieve the properties in our street
r = requests.get(
f"https://brisbane.waste-info.com.au/api/v1/properties.json?street={street_id}"
)
data = json.loads(r.text)
# Find the ID for our property
for item in data['properties']:
if item['name'] == f"{self.street_number} {self.street_name} {self.suburb}":
property_id = item['id']
break
if property_id == 0:
return []
# Retrieve the upcoming collections for our property
r = requests.get(
f"https://brisbane.waste-info.com.au/api/v1/properties/{property_id}.json?start={today}&end={nextmonth}"
)
data = json.loads(r.text)
entries = []
for item in data:
if 'start' in item:
collection_date = date.fromisoformat(item['start'])
if (collection_date - today).days >= 0:
# Every collection day includes rubbish
entries.append(CollectionAppointment(
date=collection_date,
t="Rubbish",
icon="mdi:trash-can"))
if item['event_type'] == 'recycle':
entries.append(CollectionAppointment(
date=collection_date,
t="Recycling",
icon="mdi:recycle"))
if item['event_type'] == 'organic':
entries.append(CollectionAppointment(
date=collection_date,
t="Garden",
icon="mdi:leaf"))
return entries

View File

@@ -0,0 +1,43 @@
# PGH.ST
Support for schedules provided by [Brisbane City Council](https://www.brisbane.qld.gov.au/clean-and-green/rubbish-tips-and-bins/rubbish-collections/bin-collection-calendar).
## Configuration via configuration.yaml
```yaml
waste_collection_schedule:
sources:
- name: brisbane_qld_gov_au
args:
suburb: SUBURB
street_name: STREET_NAME
street_number: STREET_NUMBER
```
### Configuration Variables
**suburb**<br>
*(string) (required)*
**street_name**<br>
*(string) (required)*
**street_number**<br>
*(string) (required)*
## Example
```yaml
waste_collection_schedule:
sources:
- name: brisbane_qld_gov_au
args:
suburb: Milton
street_name: Park Rd
street_number: 8/1
```
## How to get the source arguments
Visit the [Brisbane City Council bin collection calendar](https://www.brisbane.qld.gov.au/clean-and-green/rubbish-tips-and-bins/rubbish-collections/bin-collection-calendar) page and search for your address. The arguments should exactly match the results shown for Suburb and Street and the number portion of the Property.