mirror of
https://github.com/sascha-hemi/hacs_waste_collection_schedule.git
synced 2026-03-21 02:04:22 +01:00
refactor wollongongwaste_com_au
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
import json
|
from datetime import date, datetime, timedelta
|
||||||
from datetime import datetime, date, timedelta
|
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
from waste_collection_schedule import Collection
|
from waste_collection_schedule import Collection
|
||||||
@@ -8,12 +7,16 @@ TITLE = "Wollongong Council"
|
|||||||
DESCRIPTION = "Source script for wollongongwaste.com.au"
|
DESCRIPTION = "Source script for wollongongwaste.com.au"
|
||||||
URL = "https://wollongongwaste.com"
|
URL = "https://wollongongwaste.com"
|
||||||
COUNTRY = "au"
|
COUNTRY = "au"
|
||||||
TEST_CASES = {
|
TEST_CASES = {"TestName1": {"propertyID": "21444"}}
|
||||||
"TestName1": {"propertyID": "21444"}
|
|
||||||
}
|
|
||||||
|
|
||||||
API_URL = "https://wollongong.waste-info.com.au/api/v1/properties/"
|
API_URL = "https://wollongong.waste-info.com.au/api/v1/properties/"
|
||||||
|
|
||||||
|
ICON_MAP = {
|
||||||
|
"waste": "mdi:trash-can",
|
||||||
|
"organic": "mdi:leaf",
|
||||||
|
"recycle": "mdi:recycle",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def day_of_week(start_date, end_date, day_of_week_index):
|
def day_of_week(start_date, end_date, day_of_week_index):
|
||||||
day_of_week_dates = []
|
day_of_week_dates = []
|
||||||
@@ -23,57 +26,45 @@ def day_of_week(start_date, end_date, day_of_week_index):
|
|||||||
start_date += timedelta(days=1)
|
start_date += timedelta(days=1)
|
||||||
return day_of_week_dates
|
return day_of_week_dates
|
||||||
|
|
||||||
|
|
||||||
class Source:
|
class Source:
|
||||||
def __init__(self,propertyID):
|
def __init__(self, propertyID):
|
||||||
self._propertyID = propertyID
|
self._propertyID = propertyID
|
||||||
self._url = API_URL
|
|
||||||
|
|
||||||
def fetch(self):
|
def fetch(self):
|
||||||
# Have to specify a start and end, or the API returns nothing. So lets request this year, and next year.
|
# Have to specify a start and end, or the API returns nothing. So lets request this year, and next year.
|
||||||
# start=2022-12-31T13:00:00.000Z&end=2024-12-30T13:00:00.000Z
|
# start=2022-12-31T13:00:00.000Z&end=2024-12-30T13:00:00.000Z
|
||||||
startdate = datetime(date.today().year-1, 12, 31, 13, 0, 0)
|
startdate = datetime(date.today().year - 1, 12, 31, 13, 0, 0)
|
||||||
enddate = datetime(date.today().year+1, 12, 31, 13, 0, 0)
|
enddate = datetime(date.today().year + 1, 12, 31, 13, 0, 0)
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
"start": startdate.strftime("%Y-%m-%dT%H:%M:%S.%fZ"),
|
"start": startdate.strftime("%Y-%m-%dT%H:%M:%S.%fZ"),
|
||||||
"end": enddate.strftime("%Y-%m-%dT%H:%M:%S.%fZ")
|
"end": enddate.strftime("%Y-%m-%dT%H:%M:%S.%fZ"),
|
||||||
}
|
}
|
||||||
|
|
||||||
r = requests.get(f"{self._url}{self._propertyID}.json", data=data)
|
r = requests.get(f"{API_URL}{self._propertyID}.json", data=data)
|
||||||
|
r.raise_for_status()
|
||||||
d = r.json()
|
d = r.json()
|
||||||
|
|
||||||
entries = []
|
entries = []
|
||||||
for entry in d:
|
for entry in d:
|
||||||
if entry['event_type'] == "waste":
|
waste_type = entry["event_type"]
|
||||||
dow = entry['daysOfWeek']
|
if waste_type in ("waste", "organic"):
|
||||||
for day in dow:
|
for day in entry["daysOfWeek"]:
|
||||||
for pickupdate in day_of_week(startdate, enddate, day-1):
|
for pickupdate in day_of_week(startdate, enddate, day - 1):
|
||||||
entries.append(
|
entries.append(
|
||||||
Collection(
|
Collection(
|
||||||
date=pickupdate.date(),
|
date=pickupdate.date(),
|
||||||
t="Waste to Landfill (Red)",
|
t=waste_type,
|
||||||
icon = "mdi:trash-can"
|
icon=ICON_MAP.get(waste_type),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
if entry['event_type'] == "organic":
|
if waste_type in ("recycle"):
|
||||||
dow = entry['daysOfWeek']
|
|
||||||
for day in dow:
|
|
||||||
for pickupdate in day_of_week(startdate, enddate, day-1):
|
|
||||||
print(pickupdate)
|
|
||||||
entries.append(
|
|
||||||
Collection(
|
|
||||||
date=pickupdate.date(),
|
|
||||||
t="FOGO (Green)",
|
|
||||||
icon = "mdi:leaf",
|
|
||||||
)
|
|
||||||
)
|
|
||||||
if entry['event_type'] == "recycle":
|
|
||||||
entries.append(
|
entries.append(
|
||||||
Collection(
|
Collection(
|
||||||
date=date(*map(int, entry['start'].split('-'))),
|
date=date(*map(int, entry["start"].split("-"))),
|
||||||
t="Recycling (Yelllow)",
|
t=waste_type,
|
||||||
icon="mdi:recycle"
|
icon=ICON_MAP.get(waste_type),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
return entries
|
return entries
|
||||||
|
|
||||||
|
|||||||
@@ -14,42 +14,34 @@ waste_collection_schedule:
|
|||||||
|
|
||||||
### Configuration Variables
|
### Configuration Variables
|
||||||
|
|
||||||
### Configuration Variables
|
**propertyID**
|
||||||
|
|
||||||
**propertyID**<br>
|
|
||||||
*(string) (mandatory)*
|
*(string) (mandatory)*
|
||||||
|
|
||||||
This is required.
|
### How to find your propertyID
|
||||||
|
|
||||||
|
Go to <https://wollongong.waste-info.com.au/api/v1/localities.json>
|
||||||
|
amd get the locality ID from the above json.
|
||||||
|
|
||||||
#### How to find your `propertyID`
|
Add it as `locality=<id>` to the Street query,
|
||||||
|
e.g.: <https://wollongong.waste-info.com.au/api/v1/streets.json?locality=19>
|
||||||
|
Get the street ID from the above json.
|
||||||
|
|
||||||
Get your locality.
|
Add it as `street=<id>` to the property query,
|
||||||
|
e.g.: <https://wollongong.waste-info.com.au/api/v1/properties.json?street=663>
|
||||||
https://wollongong.waste-info.com.au/api/v1/localities.json
|
Get the property ID from the above json.
|
||||||
get the locality ID from the above json.
|
|
||||||
|
|
||||||
Add it as locality=<id> to the Street query
|
|
||||||
eg: https://wollongong.waste-info.com.au/api/v1/streets.json?locality=19
|
|
||||||
Get the street ID from the above json
|
|
||||||
|
|
||||||
Add it as street=<id> to the property query
|
|
||||||
eg: https://wollongong.waste-info.com.au/api/v1/properties.json?street=663
|
|
||||||
get the property ID from the above json.
|
|
||||||
|
|
||||||
This is your propertyID
|
This is your propertyID
|
||||||
|
|
||||||
This is all you need to directly query your calendar json in future, you can skip all the above steps once you know your property ID
|
This is all you need to directly query your calendar json in future, you can skip all the above steps once you know your property ID
|
||||||
|
|
||||||
You could also use [Waste Calendar](https://www.wollongongwaste.com.au/calendar/) with developer tools open on the Network tab, look up your address, and make note of the filename in the last request. It will be in the format <propertyID>.json
|
You could also use [Waste Calendar](https://www.wollongongwaste.com.au/calendar/) with developer tools open on the Network tab, look up your address, and make note of the filename in the last request. It will be in the format `<propertyID>.json`, e.g.: <https://wollongong.waste-info.com.au/api/v1/properties/21444.json?start=2022-12-31T13:00:00.000Z&end=2023-12-30T13:00:00.000Z>
|
||||||
eg: https://wollongong.waste-info.com.au/api/v1/properties/21444.json?start=2022-12-31T13:00:00.000Z&end=2023-12-30T13:00:00.000Z
|
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
## Example using UPRN
|
|
||||||
```yaml
|
```yaml
|
||||||
waste_collection_schedule:
|
waste_collection_schedule:
|
||||||
sources:
|
sources:
|
||||||
- name: wollongongwaste_com_au
|
- name: wollongongwaste_com_au
|
||||||
args:
|
args:
|
||||||
uprn: 21444
|
propertyID: 21444
|
||||||
```
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user