Skip to content

Commit

Permalink
add araccolta.it
Browse files Browse the repository at this point in the history
  • Loading branch information
5ila5 committed Dec 26, 2024
1 parent 6d85718 commit 3df02fe
Show file tree
Hide file tree
Showing 8 changed files with 206 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1698,6 +1698,7 @@ If your service provider is not listed, feel free to open a [source request issu
- [Squillace - Sieco Spa](/doc/source/junker_app.md) / junker.app
- [Stefanaconi](/doc/source/junker_app.md) / junker.app
- [Suno](/doc/source/junker_app.md) / junker.app
- [Taranto (araccolta.it)](/doc/source/araccolta_it.md) / araccolta.it
- [Termoli - Rieco Sud Scarl](/doc/source/junker_app.md) / junker.app
- [Terno d'Isola](/doc/source/junker_app.md) / junker.app
- [Terracina](/doc/source/junker_app.md) / junker.app
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 @@ -11033,6 +11033,12 @@
"default_params": {},
"id": "junker_app"
},
{
"title": "Taranto (araccolta.it)",
"module": "araccolta_it",
"default_params": {},
"id": "araccolta_it"
},
{
"title": "Termoli - Rieco Sud Scarl",
"module": "junker_app",
Expand Down
22 changes: 22 additions & 0 deletions custom_components/waste_collection_schedule/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -9617,6 +9617,28 @@
},
"data_description": {}
},
"args_araccolta_it": {
"title": "Quelle konfigurieren",
"description": "Konfiguriere deinen Service Provider. \n\nVisit [https://araccolta.it/#calendario](https://araccolta.it/#calendario) and select your district (Quartiere) write the argument exactly like in the URL after clicking on your district.\n\nMehr details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/araccolta_it.md",
"data": {
"calendar_title": "Kalender Titel",
"district": "Bezirk",
"domestic": "Domestic"
},
"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_araccolta_it": {
"title": "Quelle Neu Konfigurieren",
"description": "Konfiguriere deinen Service Provider. \n\nVisit [https://araccolta.it/#calendario](https://araccolta.it/#calendario) and select your district (Quartiere) write the argument exactly like in the URL after clicking on your district.\n\nMehr details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/araccolta_it.md",
"data": {
"calendar_title": "Kalender Titel",
"district": "Bezirk",
"domestic": "Domestic"
},
"data_description": {}
},
"args_grafikai_svara_lt": {
"title": "Quelle konfigurieren",
"description": "Konfiguriere deinen Service Provider. Mehr details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/grafikai_svara_lt.md",
Expand Down
22 changes: 22 additions & 0 deletions custom_components/waste_collection_schedule/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -9629,6 +9629,28 @@
},
"data_description": {}
},
"args_araccolta_it": {
"title": "Configure Source",
"description": "Configure your service provider. \n\nVisit [https://araccolta.it/#calendario](https://araccolta.it/#calendario) and select your district (Quartiere) write the argument exactly like in the URL after clicking on your district.\n\nMore details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/araccolta_it.md.",
"data": {
"calendar_title": "Calendar Title",
"district": "District",
"domestic": "Domestic"
},
"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_araccolta_it": {
"title": "Reconfigure Source",
"description": "Configure your service provider. \n\nVisit [https://araccolta.it/#calendario](https://araccolta.it/#calendario) and select your district (Quartiere) write the argument exactly like in the URL after clicking on your district.\n\nMore details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/araccolta_it.md.",
"data": {
"calendar_title": "Calendar Title",
"district": "District",
"domestic": "Domestic"
},
"data_description": {}
},
"args_grafikai_svara_lt": {
"title": "Configure Source",
"description": "Configure your service provider. More details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/grafikai_svara_lt.md.",
Expand Down
22 changes: 22 additions & 0 deletions custom_components/waste_collection_schedule/translations/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -9599,6 +9599,28 @@
},
"data_description": {}
},
"args_araccolta_it": {
"title": "Configurazione Sorgente",
"description": "Compila i campi per ottenere le informazioni sul tuo servizio di raccolta. \n\nVisita [https://araccolta.it/#calendario](https://araccolta.it/#calendario) e seleziona il tuo quartiere, scrivi l'argomento esattamente come nell'URL dopo aver cliccato sul tuo quartiere.\n\nMaggiori informazioni: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/araccolta_it.md.",
"data": {
"calendar_title": "Nome Calendario",
"district": "Quartiere",
"domestic": "Utenze domestiche"
},
"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_araccolta_it": {
"title": "Riconfigurazione Sorgente",
"description": "Compila i campi per ottenere le informazioni sul tuo servizio di raccolta. \n\nVisita [https://araccolta.it/#calendario](https://araccolta.it/#calendario) e seleziona il tuo quartiere, scrivi l'argomento esattamente come nell'URL dopo aver cliccato sul tuo quartiere.\n\nPer maggiori informazioni: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/araccolta_it.md.",
"data": {
"calendar_title": "Nome Calendario",
"district": "Quartiere",
"domestic": "Utenze domestiche"
},
"data_description": {}
},
"args_grafikai_svara_lt": {
"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/grafikai_svara_lt.md.",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
from datetime import datetime, timedelta

import requests
from bs4 import BeautifulSoup
from waste_collection_schedule import Collection

TITLE = "Taranto (araccolta.it)"
DESCRIPTION = "Source for Taranto (araccolta.it)."
URL = "https://araccolta.it/"
TEST_CASES = {
"lama-san-vito-talsano Domestic": {
"district": "lama-san-vito-talsano",
},
"isola-amministrativa non Domestic": {
"district": "isola-amministrativa",
"domestic": False,
},
}


PARAM_TRANSLATIONS = {
"en": {"district": "District", "domestic": "Domestic"},
"it": {"district": "Quartiere", "domestic": "Utenze domestiche"},
}

HOW_TO_GET_ARGUMENTS_DESCRIPTION = {
"en": "Visit [https://araccolta.it/#calendario](https://araccolta.it/#calendario) and select your district (Quartiere) write the argument exactly like in the URL after clicking on your district.",
"it": "Visita [https://araccolta.it/#calendario](https://araccolta.it/#calendario) e seleziona il tuo quartiere, scrivi l'argomento esattamente come nell'URL dopo aver cliccato sul tuo quartiere.",
}

ICON_MAP = {
"Carta e cartone": "mdi:newspaper",
"Organico": "mdi:leaf",
"Secco residuo": "mdi:delete",
"Vetro": "mdi:bottle-wine",
"Plastica e metalli": "mdi:bottle-soda-classic",
}


ITALIAN_WEEKDAYS = [
"lunedì",
"martedì",
"mercoledì",
"giovedì",
"venerdì",
"sabato",
"domenica",
]

API_URL = "https://araccolta.it/{district}/"


class Source:
def __init__(self, district: str, domestic: bool = True):
self._district: str = district.lower().strip().replace(" ", "-")
self._domestic: bool = domestic

def fetch(self) -> list[Collection]:
# get json file
r = requests.get(API_URL.format(district=self._district))
r.raise_for_status()

section_id = "ud" if self._domestic else "und"

soup = BeautifulSoup(r.text, "html.parser")

section = soup.select_one(f"section#{section_id}")
if not section:
raise ValueError("could not find calendar section for district")

entries: list[Collection] = []
for card in section.select("div.calendar-card"):
weekdays = (
card.select_one("div.day-wrapper").text.strip().lower().split("/")
)
if len(weekdays) == 1:
weekdays = weekdays[0].split(" - ")
waste_types = (t.text for t in card.select("h3"))
for weekday in weekdays:
weekday_int = ITALIAN_WEEKDAYS.index(weekday)
next_date = (
datetime.now()
+ timedelta(days=(weekday_int - datetime.now().weekday()) % 7)
).date()
for waste_type in waste_types:
entries += [
Collection(
date=next_date + timedelta(weeks=i),
t=waste_type,
icon=ICON_MAP.get(waste_type),
)
for i in range(25)
]

return entries
37 changes: 37 additions & 0 deletions doc/source/araccolta_it.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Taranto (araccolta.it)

Support for schedules provided by [Taranto (araccolta.it)](https://araccolta.it/), serving Taranto, Italy.

## Configuration via configuration.yaml

```yaml
waste_collection_schedule:
sources:
- name: araccolta_it
args:
district: DISTRICT (Quartiere)
domestic: DOMESTIC (Utenze Domestiche)
```
### Configuration Variables
**district**
*(String) (required)*
**domestic**
*(Integer) (optional, default=True)*
## Example
```yaml
waste_collection_schedule:
sources:
- name: araccolta_it
args:
district: lama-san-vito-talsano
domestic: True
```
## How to get the source argument
Visit [https://araccolta.it/#calendario](https://araccolta.it/#calendario) and select your district (Quartiere) write the argument exactly like in the URL after clicking on your district.
Loading

0 comments on commit 3df02fe

Please sign in to comment.