Skip to content

Commit

Permalink
Added cardinia_vic_gov_au
Browse files Browse the repository at this point in the history
  • Loading branch information
seedzero committed Feb 27, 2023
1 parent eaeda9e commit 9033783
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Waste collection schedules in the following formats and countries are supported.
- [Belmont City Council](/doc/source/belmont_wa_gov_au.md) / belmont.wa.gov.au
- [Brisbane City Council](/doc/source/brisbane_qld_gov_au.md) / brisbane.qld.gov.au
- [Campbelltown City Council](/doc/source/campbelltown_nsw_gov_au.md) / campbelltown.nsw.gov.au
- [Cardinia Shire Council](/doc/source/cardinia_vic_gov_au.md) / cardinia.vic.gov.au
- [City of Canada Bay Council](/doc/source/canadabay_nsw_gov_au.md) / canadabay.nsw.gov.au
- [City of Onkaparinga Council](/doc/source/onkaparingacity_com.md) / onkaparingacity.com
- [Gold Coast City Council](/doc/source/goldcoast_qld_gov_au.md) / goldcoast.qld.gov.au
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import time
from datetime import datetime, timedelta

import requests
from waste_collection_schedule import Collection

TITLE = "Cardinia Shire Council"
DESCRIPTION = "Source script for cardinia.vic.gov.au"
URL = "https://www.cardinia.vic.gov.au"
TEST_CASES = {
"1015 Manks Rd": {"address": "1015 Manks Rd, Dalmore Vic"}, # Monday
"6-8 Main St": {"address": "6-8 Main St, Nar Nar Goon Vic"}, # Tuesday
"875 Princes Hwy": {"address": "875 Princes Hwy, Pakenham Vic"}, # Thursday
"124 Main St": {"address": "124 Main St, Pakenham Vic"}, # Friday
}

API_URL = "https://www.cardinia.vic.gov.au/info/20002/rubbish_and_recycling/385/bin_collection_days_and_putting_your_bins_out/2#section-2-check-your-bin-collection-days-online"
ICON_MAP = {
"Rubbish": "mdi:trash-can",
"Recycling": "mdi:recycle",
"Green Waste": "mdi:leaf",
}


class Source:
def __init__(self, address):
self._address = address

def next_collection(self, collection_day, weeks, start_date):
collection_day = time.strptime(collection_day, "%A").tm_wday
days = (collection_day - datetime.now().date().weekday() + 7) % 7
next_collect = datetime.now().date() + timedelta(days=days)
days = abs(next_collect-datetime.strptime(start_date, "%Y-%m-%d").date()).days
if ((days//7)%weeks):
next_collect = next_collect + timedelta(days=7)
return next_collect

def fetch(self):
# Get latitude & longitude of address
url = "https://geocoder.cit.api.here.com/6.2/search.json"

params = {
"gen": "9",
"app_id": "pYZXmzEqjmR2DG66DRIr",
"app_code": "T-Z-VT6e6I7IXGuqBfF_vQ",
"country": "AUS",
"state": "VIC",
"searchtext": self._address,
"bbox": "-37.86,145.36;-38.34,145.78",
}

r = requests.get(url, params=params)
r.raise_for_status()

lat_long = r.json()["Response"]["View"][0]["Result"][0]["Location"]["DisplayPosition"]

# Get waste collection zone by longitude and latitude
url = "https://services3.arcgis.com/TJxZpUnYIJOvcYwE/arcgis/rest/services/WasteCollectionZones/FeatureServer/0/query"

params ={
"f": "geojson",
"outFields": "*",
"returnGeometry": "true",
"inSR": "4326",
"spatialRel": "esriSpatialRelIntersects",
"geometryType": "esriGeometryPoint",
"geometry": str(lat_long["Longitude"]) + "," + str(lat_long["Latitude"]),
}

r = requests.get(url, params=params)
r.raise_for_status()

waste_schedule = r.json()["features"][0]["properties"]

entries = []

entries.append(
Collection(
date = self.next_collection(waste_schedule["rub_day"], waste_schedule["rub_weeks"], waste_schedule["rub_start"]),
t = "Rubbish",
icon = ICON_MAP.get("Waste Type"),
)
)

entries.append(
Collection(
date = self.next_collection(waste_schedule["rec_day"], waste_schedule["rec_weeks"], waste_schedule["rec_start"]),
t = "Recycling",
icon = ICON_MAP.get("Waste Type"),
)
)

entries.append(
Collection(
date = self.next_collection(waste_schedule["grn_day"], waste_schedule["grn_weeks"], waste_schedule["grn_start"]),
t = "Green Waste",
icon = ICON_MAP.get("Waste Type"),
)
)

return entries
32 changes: 32 additions & 0 deletions doc/source/cardinia_vic_gov_au.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Cardinia Shire Council

Waste collection schedules provided by [Cardinia Shire Council](https://www.cardinia.vic.gov.au/).

## Configuration via configuration.yaml

```yaml
waste_collection_schedule:
sources:
- name: cardinia_vic_gov_au
args:
address: ADDRESS # FORMATTING MUST BE EXACT, PLEASE SEE BELOW
```
### Configuration Variables
**address**
*(string) (required)*
## Example
```yaml
waste_collection_schedule:
sources:
- name: cardinia_vic_gov_au
args:
address: 6-8 Main St, Nar Nar Goon Vic
```
## How to get the correct address
Search your address on [Cardinia Shire Council's Website](https://www.cardinia.vic.gov.au/info/20002/rubbish_and_recycling/385/bin_collection_days_and_putting_your_bins_out/2#check) to ensure you use the correct address format. Start typing the full address and the use autocomplete to search. After results have been found, copy the address exactly as it appears in the search box.
2 changes: 1 addition & 1 deletion info.md
Original file line number Diff line number Diff line change
Expand Up @@ -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, City of Onkaparinga Council, Gold Coast City Council, Hume 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 |
| Australia | Banyule City Council, Belmont City Council, Brisbane City Council, Campbelltown City Council, Cardinia Shire Council, City of Canada Bay Council, City of Onkaparinga Council, Gold Coast City Council, Hume 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 |
Expand Down

0 comments on commit 9033783

Please sign in to comment.