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

New Source: Scenic Rim, QLD, AU #3267

Merged
merged 9 commits into from
Dec 26, 2024
Merged
Show file tree
Hide file tree
Changes from 8 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 @@ -137,6 +137,7 @@ If your service provider is not listed, feel free to open a [source request issu
- [Regional Council of Goyder](/doc/source/app_my_local_services_au.md) / goyder.sa.gov.au
- [Renmark Paringa Council](/doc/source/app_my_local_services_au.md) / renmarkparinga.sa.gov.au
- [Rural City of Murray Bridge](/doc/source/app_my_local_services_au.md) / murraybridge.sa.gov.au
- [Scenic Rim Regional Council](/doc/source/scenicrim_qld_gov_au.md) / scenicrim.qld.gov.au
- [Shellharbour City Council](/doc/source/shellharbourwaste_com_au.md) / shellharbourwaste.com.au
- [Shire of Mundaring](/doc/source/mundaring_wa_gov_au.md) / mundaring.wa.gov.au
- [Shire of Serpentine Jarrahdale](/doc/source/sjshire_wa_gov_au.md) / sjshire.wa.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 @@ -692,6 +692,12 @@
"default_params": {},
"id": "app_my_local_services_au"
},
{
"title": "Scenic Rim Regional Council",
"module": "scenicrim_qld_gov_au",
"default_params": {},
"id": "scenicrim_qld_gov_au"
},
{
"title": "Shellharbour City Council",
"module": "shellharbourwaste_com_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 @@ -1185,6 +1185,26 @@
},
"data_description": {}
},
"args_scenicrim_qld_gov_au": {
"title": "Quelle konfigurieren",
"description": "Konfiguriere deinen Service Provider. \n\nYour address as it appears in the _Street_Address_ column of the csv file used by the website. Addresses contain both single-space and double-space character sequences and these need to be preserved. The csv file can be found at (https://srrcwastebinserviceday.blob.core.windows.net/wastebinservicedayexport/WasteBinServiceDay_SRRCWebsiteSearch.csv \n\nMehr details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/scenicrim_qld_gov_au.md",
"data": {
"calendar_title": "Kalender Titel",
"address": "Addresse"
},
"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_scenicrim_qld_gov_au": {
"title": "Quelle Neu Konfigurieren",
"description": "Konfiguriere deinen Service Provider. \n\nYour address as it appears in the _Street_Address_ column of the csv file used by the website. Addresses contain both single-space and double-space character sequences and these need to be preserved. The csv file can be found at (https://srrcwastebinserviceday.blob.core.windows.net/wastebinservicedayexport/WasteBinServiceDay_SRRCWebsiteSearch.csv \n\nMehr details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/scenicrim_qld_gov_au.md",
"data": {
"calendar_title": "Kalender Titel",
"address": "Addresse"
},
"data_description": {}
},
"args_shellharbourwaste_com_au": {
"title": "Quelle konfigurieren",
"description": "Konfiguriere deinen Service Provider. Mehr details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/shellharbourwaste_com_au.md",
Expand Down
23 changes: 23 additions & 0 deletions custom_components/waste_collection_schedule/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1188,6 +1188,29 @@
},
"data_description": {}
},
"args_scenicrim_qld_gov_au": {
"title": "Configure Source",
"description": "Configure your service provider. \n\nYour address as it appears in the _Street_Address_ column of the csv file used by the website. Addresses contain both single-space and double-space character sequences and these need to be preserved. The csv file can be found at (https://srrcwastebinserviceday.blob.core.windows.net/wastebinservicedayexport/WasteBinServiceDay_SRRCWebsiteSearch.csv \n\nMore details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/scenicrim_qld_gov_au.md.",
"data": {
"calendar_title": "Calendar Title",
"address": "Your address as it appears in the csf file used by the website"
},
"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.",
"address": "Your address as it appears in the csf file used by the website"
}
},
"reconfigure_scenicrim_qld_gov_au": {
"title": "Reconfigure Source",
"description": "Configure your service provider. \n\nYour address as it appears in the _Street_Address_ column of the csv file used by the website. Addresses contain both single-space and double-space character sequences and these need to be preserved. The csv file can be found at (https://srrcwastebinserviceday.blob.core.windows.net/wastebinservicedayexport/WasteBinServiceDay_SRRCWebsiteSearch.csv \n\nMore details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/scenicrim_qld_gov_au.md.",
"data": {
"calendar_title": "Calendar Title",
"address": "Your address as it appears in the csf file used by the website"
},
"data_description": {
"address": "Your address as it appears in the csf file used by the website"
}
},
"args_shellharbourwaste_com_au": {
"title": "Configure Source",
"description": "Configure your service provider. More details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/shellharbourwaste_com_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 @@ -1185,6 +1185,26 @@
},
"data_description": {}
},
"args_scenicrim_qld_gov_au": {
"title": "Configurazione Sorgente",
"description": "Compila i campi per ottenere le informazioni sul tuo servizio di raccolta. \n\nYour address as it appears in the _Street_Address_ column of the csv file used by the website. Addresses contain both single-space and double-space character sequences and these need to be preserved. The csv file can be found at (https://srrcwastebinserviceday.blob.core.windows.net/wastebinservicedayexport/WasteBinServiceDay_SRRCWebsiteSearch.csv \n\nMaggiori informazioni: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/scenicrim_qld_gov_au.md.",
"data": {
"calendar_title": "Nome Calendario",
"address": "Address"
},
"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_scenicrim_qld_gov_au": {
"title": "Riconfigurazione Sorgente",
"description": "Compila i campi per ottenere le informazioni sul tuo servizio di raccolta. \n\nYour address as it appears in the _Street_Address_ column of the csv file used by the website. Addresses contain both single-space and double-space character sequences and these need to be preserved. The csv file can be found at (https://srrcwastebinserviceday.blob.core.windows.net/wastebinservicedayexport/WasteBinServiceDay_SRRCWebsiteSearch.csv \n\nPer maggiori informazioni: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/scenicrim_qld_gov_au.md.",
"data": {
"calendar_title": "Nome Calendario",
"address": "Address"
},
"data_description": {}
},
"args_shellharbourwaste_com_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/shellharbourwaste_com_au.md.",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import csv
import logging
from datetime import datetime, timedelta

import requests
from dateutil.rrule import FR, MO, TH, TU, WE, WEEKLY, rrule
from waste_collection_schedule import Collection # type: ignore[attr-defined]

TITLE = "Scenic Rim Regional Council"
DESCRIPTION = "Source for scenicrim.qld.gov.au services for Scenic Rim Regional Council"
URL = "https://scenicrim.qld.gov.au"
TEST_CASES = {
"Red Week": {
"address": "The Old Avocado Farm 77A Long Road TAMBORINE MOUNTAIN QLD 4272",
},
"Blue Week": {
"address": "Elysian Fields 2/3043 Beaudesert-Nerang Road WONGLEPONG QLD 4275"
},
}
API_URL = "https://srrcwastebinserviceday.blob.core.windows.net/wastebinservicedayexport/WasteBinServiceDay_SRRCWebsiteSearch.csv"
ICON_MAP = {
"GENERAL WASTE": "mdi:trash-can",
"RECYCLING": "mdi:recycle",
}
DAYS: dict = {
"MONDAY": MO,
"TUESDAY": TU,
"WEDNESDAY": WE,
"THURSDAY": TH,
"FRIDAY": FR,
}
WEEKDAYS: list = [MO, TU, WE, TH, FR]
START_DATES: dict = { # taken from https://www.scenicrim.qld.gov.au/downloads/file/6551/your-waste-bins-and-facilities-guide
"BLUE": datetime(2024, 12, 2, 0, 0, 0), # known Monday in a Red Week
"RED": datetime(2024, 12, 9, 0, 0, 0), # known Monday in a Blue Week
}
NOW: datetime = datetime.now()
START_DATE: datetime = NOW + timedelta(days=-1)
END_DATE: datetime = NOW + timedelta(days=14)
dt215git marked this conversation as resolved.
Show resolved Hide resolved

# ### Arguments affecting the configuration GUI ####

HOW_TO_GET_ARGUMENTS_DESCRIPTION = { # Optional dictionary to describe how to get the arguments, will be shown in the GUI configuration form above the input fields, does not need to be translated in all languages
"en": "Your address as it appears in the _Street_Address_ column of the csv file used by the website. Addresses contain both single-space and double-space character sequences and these need to be preserved. The csv file can be found at (https://srrcwastebinserviceday.blob.core.windows.net/wastebinservicedayexport/WasteBinServiceDay_SRRCWebsiteSearch.csv ",
}

PARAM_DESCRIPTIONS = { # Optional dict to describe the arguments, will be shown in the GUI configuration below the respective input field
"en": {
"address": "Your address as it appears in the csf file used by the website",
},
}

PARAM_TRANSLATIONS = { # Optional dict to translate the arguments, will be shown in the GUI configuration form as placeholder text
"en": {
"address": "Your address as it appears in the csf file used by the website",
},
}

# ### End of arguments affecting the configuration GUI ####


_LOGGER = logging.getLogger(__name__)


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

def generate_dates(self, weekday: int, date_start: datetime, interval: int) -> list:
rr = rrule(
freq=WEEKLY,
interval=interval,
wkst=MO,
byweekday=(weekday),
dtstart=date_start,
)
dates = [dt for dt in rr.between(date_start, END_DATE, inc=True)]
return dates

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

# get master schedule from website
csv_file = s.get(API_URL)
csv_decoded = csv_file.content.decode("utf-8")
address_list: list = csv.reader(csv_decoded.splitlines(), delimiter=",")
address_list = [
[element.upper() for element in address] for address in address_list
]

# extract service day and recycling code
for item in address_list:
if self._address in item[0]:
service_day: str = item[-2]
recycling_code: str = item[-1].split(" ")[1]

# generate general waste dates
service_days = self.generate_dates(DAYS[service_day], START_DATE, 1)
service_days = [["GENERAL WASTE", day] for day in service_days]
# generate recycling dates
recycling_days = self.generate_dates(
DAYS[service_day], START_DATES[recycling_code], 2
)
recycling_days = [["RECYCLING", day] for day in recycling_days]
# combine to create collection schedule
collection_days: list = service_days + recycling_days

entries = []
for item in collection_days:
entries.append(
Collection(
date=item[1].date(),
t=item[0],
icon=ICON_MAP.get(item[0]),
)
)

return entries
31 changes: 31 additions & 0 deletions doc/source/scenicrim_qld_gov_au.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Scenic Rim Regional Council

Support for schedules provided by [Scenic Rim Regional Council](https://scenicrim.qld.gov.au), serving Scenic Rim Regional Council in Queensland, Australia

## Configuration via configuration.yaml

```yaml
waste_collection_schedule:
sources:
- name: scenicrim_qld_gov_au
args:
address: ADDRESS
```

### Configuration Variables

**address**
*(string) (mandatory)*

Your address as it appears in the _Street_Address_ column of the
[csv file](https://srrcwastebinserviceday.blob.core.windows.net/wastebinservicedayexport/WasteBinServiceDay_SRRCWebsiteSearch.csv) used by the website. Addresses contain both single-space and double-space character sequences and these need to be preserved.

## Example

```yaml
waste_collection_schedule:
sources:
- name: scenicrim_qld_com_au
args:
address: "The Old Avocado Farm 77A Long Road TAMBORINE MOUNTAIN QLD 4272"
```
Loading
Loading