-
-
Notifications
You must be signed in to change notification settings - Fork 718
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New Source: Shire of Mundaring (#2848)
* different date formates handled * test cases added * arg details added * .md added, arg text made consistent * updaet doculinks * pre-commit installed into venv
- Loading branch information
Showing
8 changed files
with
222 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
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
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
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
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
104 changes: 104 additions & 0 deletions
104
...ponents/waste_collection_schedule/waste_collection_schedule/source/mundaring_wa_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,104 @@ | ||
from datetime import datetime | ||
|
||
import requests | ||
from bs4 import BeautifulSoup | ||
from dateutil.rrule import FR, MO, SA, SU, TH, TU, WE, WEEKLY, rrule | ||
from waste_collection_schedule import Collection # type: ignore[attr-defined] | ||
|
||
TITLE = "Shire of Mundaring" | ||
DESCRIPTION = "Source for mundaring.wa.gov.au services for the Shire of Mundaring, Western Australia" | ||
URL = "https://wwwhttps://www.mundaring.wa.gov.au/" | ||
TEST_CASES = { | ||
"Test_001": {"parcel_number": 103239, "suburb": "Helena Valley"}, | ||
"Test_002": {"parcel_number": "100119", "suburb": "Swan View"}, | ||
"Test_003": {"parcel_number": 1119284, "suburb": "Glen Forrest"}, | ||
} | ||
ICON_MAP = { | ||
"FOGO Bin": "mdi:leaf", | ||
"Recycle Bin": "mdi:recycle", | ||
"General Waste": "mdi:trash-can", | ||
"Bulk Verge Collection": "mdi:sofa", | ||
} | ||
HEADERS = { | ||
"user-agent": "Mozilla/5.0", | ||
} | ||
DAYS = { | ||
"Monday": MO, | ||
"Tuesday": TU, | ||
"Wednesday": WE, | ||
"Thursday": TH, | ||
"Friday": FR, | ||
"Saturday": SA, | ||
"Sunday": SU, | ||
} | ||
HOW_TO_GET_ARGUMENTS_DESCRIPTION = { | ||
"en": "An easy way to discover your parcel_number is by going to https://geohub-mundaring.hub.arcgis.com/, and use the Property Map to search for your address ensuring both Lot Numbers and House Number checkboxes are ticked. The pop-up that appears contains an entry that shows your parcel number.", | ||
} | ||
PARAM_TRANSLATIONS = { | ||
"en": { | ||
"parcel_number": "A number that uniquely identifies your property.", | ||
} | ||
} | ||
PARAM_DESCRIPTIONS = { | ||
"en": { | ||
"parcel_number": "An easy way to discover your parcel_number is by going to https://geohub-mundaring.hub.arcgis.com/, and use the Property Map to search for your address ensuring both Lot Numbers and House Number checkboxes are ticked. The pop-up that appears contains an entry that shows your parcel number.", | ||
} | ||
} | ||
|
||
|
||
class Source: | ||
def __init__(self, parcel_number: str | int, suburb: str): | ||
self._parcel_number = str(parcel_number) | ||
self._suburb = str(suburb).upper() | ||
|
||
def tidytext(self, lst: list) -> list: | ||
temp_list = [ | ||
txt.replace("\r\n ", "").replace("\r\n", "").strip() | ||
for txt in lst | ||
] | ||
return temp_list | ||
|
||
def fetch(self): | ||
s = requests.Session() | ||
|
||
params = {"parcelNumber": self._parcel_number, "suburb": self._suburb} | ||
r = s.get( | ||
"https://my.mundaring.wa.gov.au/BinLocationInfo/Info?", | ||
headers=HEADERS, | ||
params=params, | ||
) | ||
r.raise_for_status() | ||
|
||
soup = BeautifulSoup(r.content.decode("utf-8"), "html.parser") | ||
pickups = soup.find_all("div", {"class": "form-group mb-3"}) | ||
|
||
today = datetime.now() | ||
entries = [] | ||
for pickup in pickups[1:]: | ||
details: list = self.tidytext(pickup.text.split(":")) | ||
for detail in details: | ||
if "FOGO" in details[0]: | ||
dt = list( | ||
rrule( | ||
WEEKLY, byweekday=DAYS[details[1]], dtstart=today, count=1 | ||
) | ||
)[0] | ||
waste = "FOGO Bin" | ||
elif "Bulk" in details[0]: | ||
dt = datetime.strptime(details[1], "%d %B %Y") | ||
waste = "Bulk Verge Collection" | ||
else: | ||
dt = datetime.strptime(details[1], "%d/%m/%Y") | ||
if "Recycle" in details[0]: | ||
waste = "Recycle Bin" | ||
else: | ||
waste = "General Waste" | ||
entries.append( | ||
Collection( | ||
date=dt.date(), | ||
t=waste, | ||
icon=ICON_MAP.get(waste), | ||
) | ||
) | ||
|
||
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,41 @@ | ||
# Shire of Mundaring | ||
|
||
Support for schedules provided by the [Shire of Mundaring](https://mundaring.wa.gov.au/), in Western Australia. | ||
|
||
## Configuration via configuration.yaml | ||
|
||
```yaml | ||
waste_collection_schedule: | ||
sources: | ||
- name: mundaring_wa_gov_au | ||
args: | ||
parcel_number: PARCEL_NUMBER | ||
suburb: SUBURB | ||
``` | ||
### Configuration Variables | ||
**parcel_number** | ||
*(integer | string)* | ||
The unique reference number that identified your property | ||
**suburb** | ||
*(string)* | ||
The suburb for your address | ||
## Example | ||
```yaml | ||
waste_collection_schedule: | ||
sources: | ||
- name: mundaring_wa_gov_au | ||
args: | ||
parcel_number: 103239 | ||
suburb: "Helena Valley" | ||
``` | ||
## How to get the parcel_number source argument | ||
An easy way to discover your parcel_number is by going to https://geohub-mundaring.hub.arcgis.com/, and use the *Property Map* to search for your address ensuring both *Lot Numbers* and *House Number* checkboxes are ticked. The pop-up that appears contains an entry that shows your parcel number. |
Oops, something went wrong.