Adding french city mamirolle source (#1251)

* Add mamirolle info source

* remove dependency + add next year check + reformatting (@5ila5)

---------

Co-authored-by: Aghilas MESSARA <a.messara@billettiqueservices.com>
This commit is contained in:
AghilasMessara
2023-09-09 02:04:11 +02:00
committed by GitHub
parent 0820a9d7a6
commit 51ad0903c2
5 changed files with 95 additions and 0 deletions

View File

@@ -254,6 +254,12 @@ Waste collection schedules in the following formats and countries are supported.
- [Renosyd](/doc/source/renosyd_dk.md) / renosyd.dk
</details>
<details>
<summary>France</summary>
- [Mairie de Mamirolle](/doc/source/mamirolle_info.md) / mamirolle.info
</details>
<details>
<summary>Germany</summary>

View File

@@ -0,0 +1,67 @@
import datetime
import requests
from bs4 import BeautifulSoup
from waste_collection_schedule import Collection
TITLE = "Mairie de Mamirolle"
DESCRIPTION = "Source script for mamirolle.info"
COUNTRY = "fr"
URL = "http://mamirolle.info/"
TEST_CASES = {"TestSource": {}}
ICON_MAP = {
"Poubelle grise": "mdi:trash-can",
"Poubelle jaune": "mdi:recycle",
}
MONTH_NAMES = [
"janvier",
"février",
"mars",
"avril",
"mai",
"juin",
"juillet",
"août",
"septembre",
"octobre",
"novembre",
"décembre",
]
class Source:
def fetch(self):
now = datetime.datetime.now()
# get list of regions and weblinks
page = requests.get(URL)
# A lenient HTML parser is need
soup = BeautifulSoup(page.text.replace("<![endif]", ""), "html.parser")
trash_domestic = soup.find("i", class_="poubelle-grise")
_, day, month = trash_domestic.next_sibling.string.split()
date_domestic = now.replace(month=MONTH_NAMES.index(month), day=int(day)).date()
if date_domestic < now.date():
date_domestic = date_domestic.replace(year=date_domestic.year + 1)
trash_recycle = soup.find("i", class_="poubelle-jaune")
_, day, month = trash_recycle.next_sibling.string.split()
date_recycle = now.replace(month=MONTH_NAMES.index(month), day=int(day)).date()
if date_recycle < now.date():
date_recycle = date_recycle.replace(year=date_recycle.year + 1)
entries = [
Collection(
date=date_domestic,
t="Poubelle grise",
icon=ICON_MAP.get("Poubelle grise"),
),
Collection(
date=date_recycle,
t="Poubelle jaune",
icon=ICON_MAP.get("Poubelle jaune"),
),
] # List that holds collection schedule
return entries

View File

@@ -0,0 +1,17 @@
# Mairie de mamirolle
Support for Mamirolle communal website in France
## Configuration via configuration.yaml
```yaml
waste_collection_schedule:
sources:
- name: mamirolle_info
```
## Sensor setup
There are following types of garbage parsed:
- Poubelle grise
- Poubelle jaune

File diff suppressed because one or more lines are too long

View File

@@ -444,6 +444,10 @@ COUNTRYCODES = [
"code": "uk",
"name": "United Kingdom",
},
{
"code": "fr",
"name": "France",
},
]
if __name__ == "__main__":