Added support for Contarina S.p.A. (it) (#1569)

* Added support for Contarina S.p.A. (it)

* remove contarina_it source shorten main url

---------

Co-authored-by: 5ila5 <5ila5@users.noreply.github.com>
This commit is contained in:
Alessandro Borsato
2023-12-26 14:10:12 +01:00
committed by GitHub
parent ca521c42ff
commit e038205170
7 changed files with 149 additions and 120 deletions

View File

@@ -963,7 +963,7 @@ Waste collection schedules in the following formats and countries are supported.
<details>
<summary>Italy</summary>
- [Contarina](/doc/source/contarina_it.md) / contarina.it
- [Contarina S.p.A](/doc/ics/contarina_it.md) / contarina.it
</details>
<details>

View File

@@ -1,79 +0,0 @@
from datetime import datetime
import requests
from bs4 import BeautifulSoup
from waste_collection_schedule import Collection # type: ignore[attr-defined]
TITLE = "Contarina"
DESCRIPTION = "Waste collection provider in Treviso, Italy"
URL = "https://contarina.it/"
TEST_CASES = {
"Trevignano": {"district": "Trevignano"},
"Montebelluna 1": {"district": "Montebelluna centro storico"},
"Montebelluna 2": {"district": "Montebelluna fuori centro storico"},
}
API_URL = f"{URL}cittadino/raccolta-differenziata/eco-calendario"
ICON_MAP = {
"secco": "mdi:trash-can",
"vpl": "mdi:recycle",
"carta": "mdi:package-variant",
"umido": "mdi:leaf",
"vegetale": "mdi:leaf",
}
class Source:
def __init__(self, district: str):
self._district = district.lower()
def _find_district_table(self, soup: BeautifulSoup) -> BeautifulSoup:
tables = soup.find_all("table", {"class": ["table", "comune"]})
for table in tables:
row = table.find_all("tr")[0]
cells = row.find_all("td")
if len(cells) == 0:
continue
table_district = cells[0].text.strip().lower().replace("\n", " ")
if self._district in table_district:
return table
return None
def fetch(self) -> list[Collection]:
# Fetch the page
r = requests.get(API_URL)
# Parse the page
soup = BeautifulSoup(r.content, "html.parser")
# Find the table that contains the given district
# in the first column of the first row
table = self._find_district_table(soup)
if table is None:
raise Exception(f"Could not find district {self._district}")
# The first cell of the second rows contains another table
# with header "Date" and "Waste type"
second_row = table.find_all("tr")[1]
waste_table = second_row.find_all("table")[0]
waste_rows = waste_table.find_all("tr")
# Skip first row and parse the rest as collections
# NOTE: there may be more than one collection per day
collections = []
for row in waste_rows[1:]:
cells = row.find_all("td")
date = datetime.strptime(cells[0].text.strip(), "%d-%m-%Y").date()
paragraphs = cells[1].find_all("p")
for paragraph in paragraphs:
waste_text = paragraph.text.strip()
icon = ICON_MAP[waste_text.lower()]
collections.append(Collection(date, waste_text, icon))
return collections

77
doc/ics/contarina_it.md Normal file
View File

@@ -0,0 +1,77 @@
# Contarina S.p.A
Contarina S.p.A is supported by the generic [ICS](/doc/source/ics.md) source. For all available configuration options, please refer to the source description.
## How to get the configuration arguments
- Copy the `url` in the example configuration with this link.
- Replace the url's `{zone}` substring with your location's zone code (check below for the chart)
Zone codes `{code} : {zone}`:
- 1 : "Treviso - cintura urbana",
- 2 : "Treviso - fuori mura",
- 3 : "Treviso - centro storico",
- 4 : "Arcade",
- 5 : "Breda di Piave",
- 6 : "Carbonera",
- 7 : "Casale sul Sile",
- 8 : "Casier",
- 9 : "Giavera del Montello",
- 10 : "Maserada sul Piave",
- 11 : "Monastier di Treviso",
- 12 : "Morgano",
- 13 : "Nervesa della Battaglia",
- 14 : "Paese",
- 15 : "Ponzano Veneto",
- 16 : "Povegliano",
- 17 : "Preganziol",
- 18 : "Quinto di Treviso",
- 19 : "Roncade",
- 20 : "San Biagio di Callalta",
- 21 : "Silea",
- 22 : "Spresiano",
- 23 : "Susegana",
- 24 : "Villorba",
- 25 : "Volpago del Montello",
- 26 : "Zenson di Piave",
- 27 : "Zero Branco",
- 28 : "Altivole",
- 29 : "Asolo - centro storico",
- 30 : "Asolo - fuori centro storico",
- 31 : "Borso del Grappa",
- 32 : "Caerano di San Marco",
- 33 : "Castelcucco",
- 34 : "Castelfranco Veneto - centro storico",
- 35 : "Castelfranco Veneto - fuori centro storico",
- 36 : "Castello di Godego",
- 37 : "Cavaso del Tomba",
- 38 : "Cornuda",
- 40 : "Crocetta del Montello",
- 41 : "Fonte",
- 42 : "Istrana",
- 43 : "Loria",
- 44 : "Maser",
- 45 : "Monfumo",
- 46 : "Montebelluna - centro storico",
- 47 : "Montebelluna - fuori centro storico",
- 49 : "Pederobba",
- 50 : "Possagno",
- 51 : "Resana",
- 52 : "Riese Pio X",
- 53 : "San Zenone degli Ezzelini",
- 54 : "Trevignano",
- 55 : "Vedelago",
- 56 : "Pieve del Grappa"
## Examples
### Treviso - cintura urbana"
```yaml
waste_collection_schedule:
sources:
- name: ics
args:
url: https://contarina.it/ajax/moduli/appbugfixapi/genera_ics_calendari?id_zona=1
```

View File

@@ -0,0 +1,66 @@
title: Contarina S.p.A
url: https://contarina.it/
country: it
howto: |
- Copy the `url` in the example configuration with this link.
- Replace the url's `{zone}` substring with your location's zone code (check below for the chart)
Zone codes `{code} : {zone}`:
- 1 : "Treviso - cintura urbana",
- 2 : "Treviso - fuori mura",
- 3 : "Treviso - centro storico",
- 4 : "Arcade",
- 5 : "Breda di Piave",
- 6 : "Carbonera",
- 7 : "Casale sul Sile",
- 8 : "Casier",
- 9 : "Giavera del Montello",
- 10 : "Maserada sul Piave",
- 11 : "Monastier di Treviso",
- 12 : "Morgano",
- 13 : "Nervesa della Battaglia",
- 14 : "Paese",
- 15 : "Ponzano Veneto",
- 16 : "Povegliano",
- 17 : "Preganziol",
- 18 : "Quinto di Treviso",
- 19 : "Roncade",
- 20 : "San Biagio di Callalta",
- 21 : "Silea",
- 22 : "Spresiano",
- 23 : "Susegana",
- 24 : "Villorba",
- 25 : "Volpago del Montello",
- 26 : "Zenson di Piave",
- 27 : "Zero Branco",
- 28 : "Altivole",
- 29 : "Asolo - centro storico",
- 30 : "Asolo - fuori centro storico",
- 31 : "Borso del Grappa",
- 32 : "Caerano di San Marco",
- 33 : "Castelcucco",
- 34 : "Castelfranco Veneto - centro storico",
- 35 : "Castelfranco Veneto - fuori centro storico",
- 36 : "Castello di Godego",
- 37 : "Cavaso del Tomba",
- 38 : "Cornuda",
- 40 : "Crocetta del Montello",
- 41 : "Fonte",
- 42 : "Istrana",
- 43 : "Loria",
- 44 : "Maser",
- 45 : "Monfumo",
- 46 : "Montebelluna - centro storico",
- 47 : "Montebelluna - fuori centro storico",
- 49 : "Pederobba",
- 50 : "Possagno",
- 51 : "Resana",
- 52 : "Riese Pio X",
- 53 : "San Zenone degli Ezzelini",
- 54 : "Trevignano",
- 55 : "Vedelago",
- 56 : "Pieve del Grappa"
test_cases:
Treviso - cintura urbana":
url: "https://contarina.it/ajax/moduli/appbugfixapi/genera_ics_calendari?id_zona=1"

View File

@@ -1,39 +0,0 @@
# Contarina
Support for schedules provided by [Contarina.it](https://contarina.it/).
## Types
Supported waste types for this sources are:
- Secco
- Carta
- VPL (vetro, plastica e lattine)
- Umido
- Vegetale
## Configuration via configuration.yaml
```yaml
waste_collection_schedule:
sources:
- name: contarina_it
args:
district: DISTRICT_NAME
```
### Configuration Variables
**district_name**
*(string) (required)*
The list of allowed district names (comune) can be found in the [calendar page](https://contarina.it/cittadino/raccolta-differenziata/eco-calendario).
## Example
```yaml
waste_collection_schedule:
sources:
- name: contarina_it
args:
district: Treviso
```

View File

@@ -205,6 +205,10 @@ This source has been successfully tested with the following service providers:
- [Zweckverband Abfallwirtschaft Region Trier (A.R.T.)](/doc/ics/art_trier_de.md) / art-trier.de
- [Zweckverband Abfallwirtschaft Südwestsachsen (ZAS)](/doc/ics/za_sws_de.md) / za-sws.de
### Italy
- [Contarina S.p.A](/doc/ics/contarina_it.md) / contarina.it
### Norway
- [Trondheim](/doc/ics/trv_no.md) / trv.no

File diff suppressed because one or more lines are too long