forked from mampfes/hacs_waste_collection_schedule
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
85 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
...nents/waste_collection_schedule/waste_collection_schedule/source/townsville_qld_gov_au.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
from datetime import datetime | ||
|
||
import requests | ||
from waste_collection_schedule import Collection # type: ignore[attr-defined] | ||
|
||
TITLE = "Townsville" | ||
DESCRIPTION = "Source for Townsville." | ||
URL = "https://townsville.qld.gov.au/" | ||
TEST_CASES = { | ||
"Woodwark Drive, Bushland Beach": { | ||
"property_id": "009fe2d01b9ba090598520202d4bcbc7" | ||
}, | ||
"Riverway Dr, Kelso": {"property_id": "d41fe69c1b5ba090598520202d4bcb3c"}, | ||
"37 Pilkington St, Garbutt": {"property_id": "580f6e5c1b5ba090598520202d4bcb91"}, | ||
} | ||
|
||
|
||
ICON_MAP = { | ||
"Rubbish": "mdi:trash-can", | ||
"Recycle": "mdi:recycle", | ||
} | ||
|
||
|
||
API_URL = "https://mitownsville.service-now.com/api/cio19/bin_collection_dates/getBinCollectionCal" | ||
|
||
|
||
class Source: | ||
def __init__(self, property_id: str): | ||
self._property_id: str = property_id | ||
|
||
def fetch(self) -> list[Collection]: | ||
params = {"p_id": self._property_id} | ||
|
||
r = requests.get(API_URL, params=params) | ||
r.raise_for_status() | ||
data = r.json() | ||
|
||
entries = [] | ||
for d in data["result"]: | ||
bin_type = d["title"] | ||
# date format like: 2024-01-03T00:00:00+00:00 | ||
date = datetime.strptime(d["start"], "%Y-%m-%dT%H:%M:%S%z").date() | ||
icon = ICON_MAP.get(bin_type) # Collection icon | ||
entries.append(Collection(date=date, t=bin_type, icon=icon)) | ||
|
||
return entries |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Townsville | ||
|
||
Support for schedules provided by [Townsville](https://townsville.qld.gov.au/), serving Townsville, Australia. | ||
|
||
## Configuration via configuration.yaml | ||
|
||
```yaml | ||
waste_collection_schedule: | ||
sources: | ||
- name: townsville_qld_gov_au | ||
args: | ||
property_id: PROPERTY_ID | ||
|
||
``` | ||
### Configuration Variables | ||
**property_id** | ||
*(String) (required)* | ||
## Example | ||
```yaml | ||
waste_collection_schedule: | ||
sources: | ||
- name: townsville_qld_gov_au | ||
args: | ||
property_id: 009fe2d01b9ba090598520202d4bcbc7 | ||
|
||
``` | ||
## How to get the source argument | ||
Goto <https://mitownsville.service-now.com/webapps/bin_collection.do> and select your property. The `property_id` is the last part of the URL after you select your property. For example, if the URL is `https://mitownsville.service-now.com/webapps/bin_collection_calendar.do?property_id=009fe2d01b9ba090598520202d4bcbc7`, then the `property_id` is `009fe2d01b9ba090598520202d4bcbc7`. | ||
|
||
If you use the form, that's directly embedded in the <https://townsville.qld.gov.au/> website, you need to open you browser's developer tools and look for the `property_id` in the network tab. The `property_id` is part of the URL of the request to `https://mitownsville.service-now.com/webapps/bin_collection_calendar.do`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters