added whittlesea_vic_gov_au

This commit is contained in:
jezzaaa
2023-02-21 14:47:05 +11:00
parent 3e453fe0f5
commit cf57b08de8
4 changed files with 173 additions and 1 deletions

View File

@@ -44,6 +44,7 @@ Waste collection schedules in the following formats and countries are supported.
- [RecycleSmart](/doc/source/recyclesmart_com.md) / recyclesmart.com
- [Stonnington City Council](/doc/source/stonnington_vic_gov_au.md) / stonnington.vic.gov.au
- [The Hills Shire Council, Sydney](/doc/source/thehills_nsw_gov_au.md) / thehills.nsw.gov.au
- [Whittlesea City Council, Melbourne](/doc/source/whittlesea_vic_gov_au.md) / whittlesea.vic.gov.au
- [Wollongong City Council](/doc/source/wollongongwaste_com_au.md) / wollongongwaste.com
- [Wyndham City Council, Melbourne](/doc/source/wyndham_vic_gov_au.md) / wyndham.vic.gov.au
</details>

View File

@@ -0,0 +1,124 @@
from datetime import date, timedelta
import requests
from waste_collection_schedule import Collection # type: ignore[attr-defined]
import json
from dateutil.parser import parse
from datetime import datetime
TITLE = "Whittlesea Council"
DESCRIPTION = "Source for Whittlesea Council (VIC) rubbish collection."
URL = "https://whittlesea.vic.gov.au/community-support/my-neighbourhood/"
TEST_CASES = {
"Random address": {
"street_number": "5",
"street_name": "Hawkstowe Parade",
"suburb": "South Morang",
"postcode": "3752",
},
"Whittlesea Council Office": {
"street_number": "25",
"street_name": "Ferres Boulevard",
"suburb": "South Morang",
"postcode": "3752",
}
}
HEADERS = {
"user-agent": "Mozilla/5.0",
"content-type": "application/json",
}
NAMES = {
"rubbish": "Red (rubbish)",
"recycling": "Yellow (recycling)",
"glass": "Purple (glass)",
"green": "Green (garden)",
}
ICON_MAP = {
"rubbish": "mdi:trash-can",
"recycle": "mdi:recycle",
"glass": "mdi:glass-fragile",
"green": "mdi:leaf",
}
# Only a year's worth of dates is available
WEEKS = 53
# Time to wait for initial connection, then response
TIMEOUT=(10,5)
class Source:
def __init__(self, suburb, street_name, street_number, postcode):
self.suburb = suburb
self.street_name = street_name
self.street_number = street_number
self.postcode = postcode
def fetch(self):
# Retrieve geolocation for our address
# (TODO: cache the LAT/LON results)
address = self.street_number+" "+self.street_name+" "+self.suburb+" "+self.postcode
PARAMS = {"address": address}
url="https://www.whittlesea.vic.gov.au/umbraco/api/vicmap/GetAddressResultsUsingArcGis/"
r = requests.get(
url,
headers=HEADERS,
params=PARAMS,
timeout=TIMEOUT,
)
# TODO: better error handling of parsing issues
json_string = r.text.encode('raw_unicode_escape').decode('unicode_escape').lstrip('\"').rstrip('\"')
data = json.loads(json_string)
if not isinstance(data, dict):
raise Exception("malformed response from web query")
features=data.get("features")
# Find the coordinates for our address
# TODO: check that there is only one geometry
geometry = features[0].get("geometry")
geo_x = str(geometry.get("x"))
geo_y = str(geometry.get("y"))
# Armed with the LAT and LON coordinates, we construct
# a request to fetch the waste pick-up schedules
url="https://www.whittlesea.vic.gov.au/umbraco/api/cartomap/GetQueryResultsArcGisWasteCollection"
firstQuery = "geometry%3D"+geo_x+","+geo_y+"%26geometryType%3DesriGeometryPoint%26inSR%3D4326%26spatialRel%3DesriSpatialRelIntersects%26outFields%3DName%26returnGeometry%3Dfalse%26f%3Djson"
secondQuery = "where%3Dzonename%253D%2527%7B0%7D%2527%2Band%2Bdate%3ECURRENT_TIMESTAMP-1%26time%3D%26topFilter%3D%257B%250D%250A%2B%2B%2522groupByFields%2522%253A%2B%2522zonename%2522%252C%250D%250A%2B%2B%2522topCount%2522%253A%2B"+str(WEEKS)+"%252C%250D%250A%2B%2B%2522orderByFields%2522%253A%2B%2522date%2522%250D%250A%257D%26outFields%3D*%26orderByFields%3Ddate%26resultRecordCount%3D"+str(WEEKS)+"%26f%3Djson"
url += "?firstQuery="+firstQuery+"&secondQuery="+secondQuery
r = requests.get(
url,
headers=HEADERS,
timeout=(5,3),
)
json_string = r.text.encode('raw_unicode_escape').decode('unicode_escape').lstrip('\"').rstrip('\"')
data = json.loads(json_string)
entries = []
today = datetime.utcnow().date()
for item in data["rows"]:
if "cartodb_id" in item:
collection_date = parse(item["date"]).date()
# Only return dates in the future
if (collection_date - today).days >= 0:
#print(f"found date {collection_date}")
entries.append(Collection(date=collection_date,t=NAMES.get("rubbish"),icon=ICON_MAP.get("rubbish"),))
if item["recycling"] == 1:
entries.append(Collection(date=collection_date,t=NAMES.get("recycling"),icon=ICON_MAP.get("recycling")))
if item["green"] == 1:
entries.append(Collection(date=collection_date,t=NAMES.get("green"),icon=ICON_MAP.get("green")))
if item["glass"] == 1:
entries.append(Collection(date=collection_date,t=NAMES.get("glass"),icon=ICON_MAP.get("glass")))
return entries

View File

@@ -0,0 +1,47 @@
# Whittlesea Council (VIC)
Support for schedules provided by [Whittlesea Council (VIC)](https://whittlesea.vic.gov.au/community-support/my-neighbourhood/).
## Configuration via configuration.yaml
```yaml
waste_collection_schedule:
sources:
- name: maribyrnong_vic_gov_au
args:
street_number: STREET_NUMBER
suburb: SUBURB
street_name: STREET_NAME
suburb: POSTCODE
```
### Configuration Variables
**street_number**<br>
*(string) (required)*
**street_name**<br>
*(string) (required)*
**suburb**<br>
*(string) (required)*
**postcode**<br>
*(string) (required)*
## Example
```yaml
waste_collection_schedule:
sources:
- name: whittlesea_vic_gov_au
args:
street_number: 25
street_name: Ferres Bouleavard
suburb: South Morang
postcode: 3752
```
## How to get the source arguments
Visit the [Whittlesea Council (VIC)](https://www.maribyrnong.vic.gov.au/Residents/Bins-and-recycling) page and search for your address. The arguments should exactly match the results shown.

View File

@@ -16,7 +16,7 @@ Waste collection schedules from service provider web sites are updated daily, de
|--|--|
| Generic | ICS / iCal files |
| Static | User-defined dates or repeating date patterns |<!--Begin of country section-->
| Australia | Banyule City Council, Belmont City Council, Brisbane City Council, Campbelltown City Council, City of Canada Bay Council, Gold Coast City Council, Inner West Council (NSW), Ipswich City Council, Ku-ring-gai Council, Lake Macquarie City Council, Macedon Ranges Shire Council, Maribyrnong Council, Maroondah City Council, Melton City Council, Nillumbik Shire Council, North Adelaide Waste Management Authority, RecycleSmart, Stonnington City Council, The Hills Shire Council, Sydney, Wollongong City Council, Wyndham City Council, Melbourne |
| Australia | Banyule City Council, Belmont City Council, Brisbane City Council, Campbelltown City Council, City of Canada Bay Council, Gold Coast City Council, Inner West Council (NSW), Ipswich City Council, Ku-ring-gai Council, Lake Macquarie City Council, Macedon Ranges Shire Council, Maribyrnong Council, Maroondah City Council, Melton City Council, Nillumbik Shire Council, North Adelaide Waste Management Authority, RecycleSmart, Stonnington City Council, The Hills Shire Council, Sydney, Whittlesea City Council, Wollongong City Council, Wyndham City Council, Melbourne |
| Austria | Burgenländischer Müllverband, infeo, Stadtservice Korneuburg, Umweltprofis, WSZ Moosburg |
| Belgium | Hygea, Recycle! |
| Canada | City of Toronto |