-
-
Notifications
You must be signed in to change notification settings - Fork 728
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New Source: Shellharbour City council, NSW, Australia (#1324)
* Added support for Shellharbour City council, Australia * Added support for Shellharbour City council, Australia * Fixed a few little bugs with Shellharbourwaste integration * renamed md + reformatting --------- Co-authored-by: 5ila5 <[email protected]>
- Loading branch information
Showing
4 changed files
with
99 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
55 changes: 55 additions & 0 deletions
55
...ts/waste_collection_schedule/waste_collection_schedule/source/shellharbourwaste_com_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,55 @@ | ||
from datetime import datetime | ||
|
||
import requests | ||
from bs4 import BeautifulSoup | ||
from waste_collection_schedule import Collection | ||
|
||
TITLE = "Shellharbour City Council" | ||
DESCRIPTION = "Source script for shellharbourwaste.com.au" | ||
URL = "https://shellharbourwaste.com.au" | ||
COUNTRY = "au" | ||
TEST_CASES = {"TestName1": {"zoneID": "Monday A"}, "TestName2": {"zoneID": "Friday A"}} | ||
|
||
API_URL = "https://www.shellharbourwaste.com.au/waste-collection" | ||
|
||
ICON_MAP = { | ||
"Waste": "mdi:trash-can", | ||
"FOGO": "mdi:leaf", | ||
"Recycling": "mdi:recycle", | ||
} | ||
|
||
|
||
def findUrl(zoneID): | ||
# Take Zone ID and find url to parse | ||
r = requests.get( | ||
f"https://www.shellharbourwaste.com.au/wp-json/rb_co/v1/get-waste-url?zone={zoneID}" | ||
) | ||
r.raise_for_status | ||
d = r.json() | ||
return d["url"] | ||
|
||
|
||
class Source: | ||
def __init__(self, zoneID): | ||
self._zoneID = zoneID | ||
|
||
def fetch(self): | ||
data = {"Referer": "https://www.shellharbourwaste.com.au/find-my-bin-day/"} | ||
pageurl = findUrl(self._zoneID) | ||
r = requests.get(f"{pageurl}", data=data) | ||
r.raise_for_status() | ||
soup = BeautifulSoup(r.content, "html.parser") | ||
collections = soup.select("div.waste-block__content") | ||
entries = [] | ||
for entry in collections: | ||
waste_type = entry.find("h3", class_="waste-block__title").text | ||
date_string = entry.find("time", class_="waste-block__time").text.strip() | ||
pickupdate = datetime.strptime(date_string, "%d/%m/%Y") | ||
entries.append( | ||
Collection( | ||
date=pickupdate.date(), | ||
t=waste_type.split("/")[0], | ||
icon=ICON_MAP.get(waste_type.split("/")[0]), | ||
) | ||
) | ||
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,42 @@ | ||
# Shellharbour City Council | ||
|
||
Support for schedules provided by [Shellharbour City council](https://www.shellharbourwaste.com.au/), serving Shellharbour City Council in the Illawara, New South Wales, Australia | ||
|
||
## Configuration via configuration.yaml | ||
|
||
```yaml | ||
waste_collection_schedule: | ||
sources: | ||
- name: shellharbourwaste_com_au | ||
args: | ||
zoneID: ZONE_ID | ||
``` | ||
### Configuration Variables | ||
**zoneID** | ||
*(string) (mandatory)* | ||
### How to find your calendarID | ||
Go to <https://www.shellharbourwaste.com.au/find-my-bin-day/> | ||
Put in your address, and click Search. | ||
The site will list the Zone eg: Monday A. | ||
This is the zoneID | ||
Another way is to look for your address in the KML provided by the shellharbourwaste website. | ||
https://www.shellharbourwaste.com.au/wp-content/uploads/2022/12/Untitled-map-1.kml | ||
This KML has polygons that define the various zones. | ||
## Example | ||
```yaml | ||
waste_collection_schedule: | ||
sources: | ||
- name: shellharbourwaste_com_au | ||
args: | ||
zoneID: "Monday A" | ||
``` |
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