Merge pull request #783 from framesfree/adding_Luxembourg_Esh-sur-Alzette

Adding source for Luxembourg Esch-sur-Alzette
This commit is contained in:
Steffen Zimmermann
2023-03-20 08:45:07 +01:00
committed by GitHub
3 changed files with 147 additions and 0 deletions

View File

@@ -266,6 +266,12 @@ Waste collection schedules in the following formats and countries are supported.
- [Kauno švara](/doc/source/grafikai_svara_lt.md) / grafikai.svara.lt
</details>
<details>
<summary>Luxembourg</summary>
- [Esch-sur-alzette](/doc/source/administration_esch_lu.md) / administration.esch.lu
</details>
<details>
<summary>Netherlands</summary>

View File

@@ -0,0 +1,73 @@
import datetime
from xml.etree.ElementTree import tostring
from waste_collection_schedule import Collection
import requests
from bs4 import BeautifulSoup
TITLE = "Esch-sur-Alzette" # Title will show up in README.md and info.md
DESCRIPTION = "Source script for administration.esch.lu, communal website of the city of Esch-sur-Alzette in Luxembourg" # Describe your source
URL = "https://administration.esch.lu" # Insert url to service homepage. URL will show up in README.md and info.md
TEST_CASES = { # Insert arguments for test cases to be used by test_sources.py script
"Zone A": {"zone": 'A'},
"Zone B": {"zone": 'B'}
}
API_URL = "https://administration.esch.lu/dechets/?street=0&tour="
ICON_MAP = { # Optional: Dict of waste types and suitable mdi icons
"Poubelle ménage": "mdi:trash-can",
"Papier": "mdi:newspaper",
"Organique": "mdi:leaf",
"Verre": "mdi:bottle-wine-outline",
"Valorlux": "mdi:recycle",
"Déchets toxiques": "mdi:skull-crossbones",
"Container ménage": "train-car-container"
}
class Source:
def __init__(self, zone): # argX correspond to the args dict in the source configuration
zones = {'A':'1',
'B':'2'
}
self._zone = zones[zone]
def fetch(self):
#locale.setlocale(locale.LC_ALL, 'fr_FR.UTF-8') # set the French locale to import the dates
response = requests.get(API_URL+str(self._zone))
soup = BeautifulSoup(response.content, "html.parser")
# Find the table containing the waste collection schedule
table = soup.find('table', {'id': 'garbage-table'})
#locale.setlocale(locale.LC_TIME, 'en_US.utf8') # Switch back to English locale
months = {
"janvier": "January",
"février": "February",
"mars": "March",
"avril": "April",
"mai": "May",
"juin": "June",
"juillet": "July",
"août": "August",
"septembre": "September",
"octobre": "October",
"novembre": "November",
"décembre": "December",
}
entries = [] # List that holds collection schedule
for row in table.find_all('tr'):
cells = row.find_all('td')
if len(cells) == 3:
t = cells[1].text.strip() # Collection type
if t.startswith("Cartons en vrac"):
continue # Skip the cardboard collection for companies
if t.startswith("Déchets toxiques"):
t = "Déchets toxiques" # Remove collecting insrtuctions
#locale.setlocale(locale.LC_ALL, 'fr_FR.UTF-8') # set the French locale to import the dates
date_fr = cells[2].text.strip().split(', ')[1]
#print (date_fr)
day, month, year = date_fr.split()
month = months[month]
date = datetime.datetime.strptime(f"{day}-{month}-{year}","%d-%B-%Y").date() # Collection date
icon = ICON_MAP.get(t)
entries.append(Collection(date,t,icon))
return entries

View File

@@ -0,0 +1,68 @@
# administration.esch.lu
Support for the Esch sur Alzette communal website in Luxembourg.
## Configuration via configuration.yaml
```yaml
waste_collection_schedule:
sources:
- name: administration_esch_lu
args:
zone: A
```
### Configuration Variables
There is currenly only one conficuration variable, which is *zone*, which accepts only two chars - A or B.
**zone**
*(char) (required)*
This variable indicates collection zone. The city is divided by two zones with different collection schedule.
One can identify their zone prior to configuring here:
https://administration.esch.lu/dechets/
## Sensor setup
There are following types of garbage parsed:
- Poubelle ménage
- Papier
- Organique
- Verre
- Valorlux
- Déchets toxiques
- Container ménage
Here is the example of sensors in `configuration.yaml`:
```yaml
sensor:
- platform: waste_collection_schedule
name: waste_organics
count: 2
add_days_to: True
types:
- Organique
- platform: waste_collection_schedule
name: waste_glass
add_days_to: True
count: 2
types:
- Verre
- platform: waste_collection_schedule
name: waste_valorlux
add_days_to: True
count: 2
types:
- Valorlux
- platform: waste_collection_schedule
name: waste_paper
add_days_to: True
count: 2
types:
- Papier
- platform: waste_collection_schedule
name: waste_household
add_days_to: True
count: 2
types:
- Poubelle ménage
```