-
-
Notifications
You must be signed in to change notification settings - Fork 766
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding french city mamirolle source (#1251)
* Add mamirolle info source * remove dependency + add next year check + reformatting (@5ila5) --------- Co-authored-by: Aghilas MESSARA <[email protected]>
- Loading branch information
1 parent
0820a9d
commit 51ad090
Showing
5 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
...m_components/waste_collection_schedule/waste_collection_schedule/source/mamirolle_info.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters