mirror of
https://github.com/sascha-hemi/hacs_waste_collection_schedule.git
synced 2026-03-21 04:06:03 +01:00
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:
@@ -254,6 +254,12 @@ Waste collection schedules in the following formats and countries are supported.
|
|||||||
- [Renosyd](/doc/source/renosyd_dk.md) / renosyd.dk
|
- [Renosyd](/doc/source/renosyd_dk.md) / renosyd.dk
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>France</summary>
|
||||||
|
|
||||||
|
- [Mairie de Mamirolle](/doc/source/mamirolle_info.md) / mamirolle.info
|
||||||
|
</details>
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
<summary>Germany</summary>
|
<summary>Germany</summary>
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
17
doc/source/mamirolle_info.md
Normal file
17
doc/source/mamirolle_info.md
Normal 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
|
||||||
@@ -444,6 +444,10 @@ COUNTRYCODES = [
|
|||||||
"code": "uk",
|
"code": "uk",
|
||||||
"name": "United Kingdom",
|
"name": "United Kingdom",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"code": "fr",
|
||||||
|
"name": "France",
|
||||||
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Reference in New Issue
Block a user