Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Moyne Shire Council - Victoria Australia #3069

Merged
merged 3 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ If your service provider is not listed, feel free to open a [source request issu
- [Moree Plains Shire Council](/doc/source/impactapps_com_au.md) / mpsc.nsw.gov.au
- [Moreton Bay](/doc/ics/moretonbay_qld_gov_au.md) / moretonbay.qld.gov.au
- [Mosman Council](/doc/source/mosman_nsw_gov_au.md) / mosman.nsw.gov.au
- [Moyne Shire Council](/doc/source/moyne_vic_gov_au.md) / moyne.vic.gov.au
- [Naracoorte Lucindale Council](/doc/source/app_my_local_services_au.md) / naracoortelucindale.sa.gov.au
- [Nillumbik Shire Council](/doc/source/nillumbik_vic_gov_au.md) / nillumbik.vic.gov.au
- [North Adelaide Waste Management Authority](/doc/source/nawma_sa_gov_au.md) / nawma.sa.gov.au
Expand Down
6 changes: 6 additions & 0 deletions custom_components/waste_collection_schedule/sources.json
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,12 @@
"default_params": {},
"id": "mosman_nsw_gov_au"
},
{
"title": "Moyne Shire Council",
"module": "moyne_vic_gov_au",
"default_params": {},
"id": "moyne_vic_gov_au"
},
{
"title": "Naracoorte Lucindale Council",
"module": "app_my_local_services_au",
Expand Down
20 changes: 20 additions & 0 deletions custom_components/waste_collection_schedule/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -983,6 +983,26 @@
},
"data_description": {}
},
"args_moyne_vic_gov_au": {
"title": "Quelle konfigurieren",
"description": "Konfiguriere deinen Service Provider. Mehr details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/moyne_vic_gov_au.md",
"data": {
"calendar_title": "Kalender Titel",
"street_address": "Street Address"
},
"data_description": {
"calendar_title": "Ein lesbarerer oder benutzerfreundlicherer Name für den Müllkalender. Wenn nichts angegeben wird, wird der Name der Quelle verwendet."
}
},
"reconfigure_moyne_vic_gov_au": {
"title": "Quelle Neu Konfigurieren",
"description": "Konfiguriere deinen Service Provider. Mehr details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/moyne_vic_gov_au.md",
"data": {
"calendar_title": "Kalender Titel",
"street_address": "Street Address"
},
"data_description": {}
},
"args_nillumbik_vic_gov_au": {
"title": "Quelle konfigurieren",
"description": "Konfiguriere deinen Service Provider. Mehr details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/nillumbik_vic_gov_au.md",
Expand Down
20 changes: 20 additions & 0 deletions custom_components/waste_collection_schedule/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -983,6 +983,26 @@
},
"data_description": {}
},
"args_moyne_vic_gov_au": {
"title": "Configure Source",
"description": "Configure your service provider. More details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/moyne_vic_gov_au.md.",
"data": {
"calendar_title": "Calendar Title",
"street_address": "Street Address"
},
"data_description": {
"calendar_title": "A more readable, or user-friendly, name for the waste calendar. If nothing is provided, the name returned by the source will be used."
}
},
"reconfigure_moyne_vic_gov_au": {
"title": "Reconfigure Source",
"description": "Configure your service provider. More details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/moyne_vic_gov_au.md.",
"data": {
"calendar_title": "Calendar Title",
"street_address": "Street Address"
},
"data_description": {}
},
"args_nillumbik_vic_gov_au": {
"title": "Configure Source",
"description": "Configure your service provider. More details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/nillumbik_vic_gov_au.md.",
Expand Down
20 changes: 20 additions & 0 deletions custom_components/waste_collection_schedule/translations/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -983,6 +983,26 @@
},
"data_description": {}
},
"args_moyne_vic_gov_au": {
"title": "Configurazione Sorgente",
"description": "Compila i campi per ottenere le informazioni sul tuo servizio di raccolta. Maggiori informazioni: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/moyne_vic_gov_au.md.",
"data": {
"calendar_title": "Nome Calendario",
"street_address": "Indirizzo Strada"
},
"data_description": {
"calendar_title": "Puoi cambiare il nome del calendario della raccolta dei rifiuti, altrimenti di default verra' utilizzato il nome del tuo fornitore di servizi."
}
},
"reconfigure_moyne_vic_gov_au": {
"title": "Riconfigurazione Sorgente",
"description": "Compila i campi per ottenere le informazioni sul tuo servizio di raccolta. Per maggiori informazioni: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/moyne_vic_gov_au.md.",
"data": {
"calendar_title": "Nome Calendario",
"street_address": "Indirizzo Strada"
},
"data_description": {}
},
"args_nillumbik_vic_gov_au": {
"title": "Configurazione Sorgente",
"description": "Compila i campi per ottenere le informazioni sul tuo servizio di raccolta. Maggiori informazioni: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/nillumbik_vic_gov_au.md.",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import logging
import re
from datetime import datetime

import requests
from bs4 import BeautifulSoup
from waste_collection_schedule import Collection # type: ignore[attr-defined]

TITLE = "Moyne Shire Council"
DESCRIPTION = "Source for Moyne Shire Council rubbish collection."
URL = "https://www.moyne.vic.gov.au"
TEST_CASES = {"Test": {"street_address": "1 Cox Street, PORT FAIRY, 3284"}}

_LOGGER = logging.getLogger(__name__)

ICON_MAP = {
"Landfill": "mdi:trash-can",
"Recycling": "mdi:recycle",
"FOGO": "mdi:leaf",
"Glass Only": "mdi:BottleWine",
}


class Source:
def __init__(self, street_address):
self._street_address = street_address

def fetch(self):
session = requests.Session()

response = session.get(
"https://www.moyne.vic.gov.au/Your-property/Waste-and-recycling/Kerbside-collection-dates"
)
response.raise_for_status()

response = session.get(
"https://www.moyne.vic.gov.au/api/v1/myarea/search",
params={"keywords": self._street_address},
)
response.raise_for_status()
addressSearchApiResults = response.json()
if (
addressSearchApiResults["Items"] is None
or len(addressSearchApiResults["Items"]) < 1
):
raise Exception(
f"Address search for '{self._street_address}' returned no results. Check your address on https://www.moyne.vic.gov.au/Your-property/Waste-and-recycling/Kerbside-collection-dates"
)

addressSearchTopHit = addressSearchApiResults["Items"][0]
_LOGGER.debug("Address search top hit: %s", addressSearchTopHit)

geolocationid = addressSearchTopHit["Id"]
_LOGGER.debug("Geolocationid: %s", geolocationid)

response = session.get(
"https://www.moyne.vic.gov.au/ocapi/Public/myarea/wasteservices?ocsvclang=en-AU",
params={"geolocationid": geolocationid},
)
response.raise_for_status()

wasteApiResult = response.json()
_LOGGER.debug("Waste API result: %s", wasteApiResult)

soup = BeautifulSoup(wasteApiResult["responseContent"], "html.parser")

entries = []
for article in soup.find_all("article"):
waste_type = article.h3.string
icon = ICON_MAP.get(waste_type)
next_pickup = article.find(class_="next-service").string
if next_pickup is None:
continue
date_match = re.search(r"\d{1,2}\/\d{1,2}\/\d{4}", next_pickup)
if date_match:
next_pickup_date = datetime.strptime(
date_match.group(0), "%d/%m/%Y"
).date()
entries.append(
Collection(date=next_pickup_date, t=waste_type, icon=icon)
)

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

Support for schedules provided by [Moyne Shire Council](https://www.moyne.vic.gov.au/Your-property/Waste-and-recycling/Kerbside-collection-dates).

## Configuration via configuration.yaml

```yaml
waste_collection_schedule:
sources:
- name: moyne_vic_gov_au
args:
street_address: STREET_ADDRESS
```

### Configuration Variables

**street_address**
*(string) (required)*

## Example

```yaml
waste_collection_schedule:
sources:
- name: moyne_vic_gov_au
args:
street_address: 1 Cox Street, PORT FAIRY, 3284
```

## How to get the source arguments

Visit the [Moyne Shire Council waste and recycling](https://www.moyne.vic.gov.au/Your-property/Waste-and-recycling/Kerbside-collection-dates) page and search for your address. The arguments should exactly match the street address shown in the autocomplete result.
Loading