-
-
Notifications
You must be signed in to change notification settings - Fork 703
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding dedicated mijnafvalwijzer nl #3244
Merged
5ila5
merged 6 commits into
mampfes:master
from
gilaberticus:adding_dedicated_mijnafvalwijzer_nl
Dec 28, 2024
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c98aa29
Changed mijnafvalwijzer_nl from ics to source
gilaberticus 758a30a
remove translations from json file for old ics
gilaberticus 20acc88
Change TITLE in source file from Eindhoven to Afval Wijzer
gilaberticus 1d0e9db
Small fixes
gilaberticus abbf5c7
Code cleanup: Remove unused info, replace while loop, better md file,…
gilaberticus a3e2a79
reformatting
5ila5 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
113 changes: 113 additions & 0 deletions
113
...mponents/waste_collection_schedule/waste_collection_schedule/source/mijnafvalwijzer_nl.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,113 @@ | ||
import datetime | ||
import re | ||
|
||
import requests | ||
from bs4 import BeautifulSoup | ||
from waste_collection_schedule import Collection | ||
|
||
TITLE = "Afval Wijzer" | ||
DESCRIPTION = "Source for all cities regions supported in mijnafvalwijzer.nl" | ||
URL = "https://www.mijnafvalwijzer.nl" | ||
TEST_CASES = { | ||
"Eindhoven1": {"postcode": "5651AN", "number": "34", "add": "A"}, | ||
"Eindhoven2": {"postcode": "5651AN", "number": "34"}, | ||
"Tilburg": {"postcode": "5014NN", "number": "174"}, | ||
"Meierijstad": {"postcode": "5481LR", "number": "6"}, | ||
"Rotterdam": {"postcode": "3067AL", "number": "53"}, | ||
} | ||
|
||
ICON_MAP = { # Optional: Dict of waste types and suitable mdi icons | ||
"Restafval": "mdi:trash-can", | ||
"Papier en karton": "mdi:paper-roll", | ||
"Groente, Fruit en Tuinafval": "mdi:leaf", | ||
"PMD": "mdi:bottle-soda-classic-outline", | ||
"Plastic, Metalen en Drankkartons": "mdi:bottle-soda-classic-outline", | ||
"papier": "mdi:paper-roll", | ||
"GFT": "mdi:leaf", | ||
"GFT ": "mdi:leaf", | ||
"restafval": "mdi:trash-can", | ||
} | ||
|
||
# ### Arguments affecting the configuration GUI #### | ||
|
||
HOW_TO_GET_ARGUMENTS_DESCRIPTION = { # Optional dictionary to describe how to get the arguments, will be shown in the GUI configuration form above the input fields, does not need to be translated in all languages | ||
"en": "INPUT ARGUMENTS ARE THE SAME AS THE ONES YOU FILL IN FOR YOUR HOME ADDRESS AT: https://www.mijnafvalwijzer.nl/", | ||
} | ||
|
||
# ### End of arguments affecting the configuration GUI #### | ||
|
||
|
||
class Source: | ||
def __init__(self, postcode, number, add=""): | ||
self._postcode = postcode | ||
self._number = number | ||
if add is None: | ||
self._add = "" | ||
else: | ||
self._add = add | ||
|
||
def fetch(self): | ||
s = requests.Session() | ||
|
||
r = s.get( | ||
URL | ||
+ "/nl/" | ||
+ self._postcode.replace(" ", "") | ||
+ "/" | ||
+ self._number.replace(" ", "") | ||
+ "/" | ||
+ self._add.replace(" ", "") | ||
) | ||
r.raise_for_status() | ||
|
||
soup = BeautifulSoup(r.text, "html.parser") | ||
soup = soup.find("div", id="jaaroverzicht", class_="pageBlock") | ||
years = soup.find_all("div", id=re.compile("^jaar-"), class_="ophaaldagen") | ||
|
||
dict_month = { | ||
"januari": 1, | ||
"februari": 2, | ||
"maart": 3, | ||
"april": 4, | ||
"mei": 5, | ||
"juni": 6, | ||
"juli": 7, | ||
"augustus": 8, | ||
"september": 9, | ||
"oktober": 10, | ||
"november": 11, | ||
"december": 12, | ||
} | ||
|
||
date_day = [] | ||
date_month = [] | ||
date_year = [] | ||
types_list = [] | ||
for year in years: | ||
year_int = int(year.get("id")[-4:]) | ||
dates = soup.find_all("span", class_="span-line-break") | ||
for date in dates: | ||
date_day.append(int(date.string.split()[1])) | ||
date_month.append(dict_month[date.string.split()[2]]) | ||
date_year.append(year_int) | ||
types = soup.find_all("span", class_="afvaldescr") | ||
for type in types: | ||
types_list.append(type.string) | ||
|
||
entries: list[Collection] = [] | ||
|
||
for day, month, year, bin_type in zip( | ||
date_day, date_month, date_year, types_list | ||
): | ||
try: | ||
entries.append( | ||
Collection( | ||
date=datetime.date(year, month, day), # Collection date | ||
t=bin_type, # Collection type | ||
icon=ICON_MAP.get(bin_type), # Collection icon | ||
) | ||
) | ||
except Exception: | ||
pass | ||
|
||
return entries |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Afval Wijzer | ||
|
||
Afval Wijzer is a platform where users from many dutch municipalities can check their waste collection schedules. | ||
Supported municipalities include, but are not limited to: | ||
- Eindhoven | ||
- Rotterdam | ||
- Tilburg | ||
- Midden-Groningen | ||
- Waalwijk | ||
- Kampen | ||
- Oirschoot | ||
- Oss | ||
- ... | ||
|
||
## How to get the configuration arguments | ||
|
||
- Visit <https://www.mijnafvalwijzer.nl> and search for your location to make sure it is recognized | ||
- Write down your postcode, house number and house number addition, if any (e.g. A) | ||
|
||
|
||
### Configuration via yaml | ||
|
||
```yaml | ||
waste_collection_schedule: | ||
sources: | ||
- name: mijnafvalwijzer_nl | ||
args: | ||
postcode: YOUR_POSTCODE | ||
number: HOUSE_NUMBER | ||
add: HOUSE_NUMBER_ADDITION | ||
``` | ||
|
||
**Configuration Variables** | ||
|
||
**postcode** _(string) (required)_ : Postcode of your property (e.g. 5014NN) | ||
**postcode** _(string) (required)_ : House number (e.g. 174) | ||
**add** _(string)_ : House number addition (e.g. A) | ||
|
||
Example: Hoefstraat 174, Tilburg | ||
|
||
```yaml | ||
waste_collection_schedule: | ||
sources: | ||
- name: mijnafvalwijzer_nl | ||
args: | ||
postcode: 5014NN | ||
number: 174 | ||
add: | ||
``` |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution. Just having HA running for a few days and just found this integration and tested the latest changes.
Currently it is showing 2 entries because we are looping through the years
for year in years
but the dates found bydates = soup.find_all("span", class_="span-line-break")
are not related to the looped year.My suggestion would be to remove the
for year in years:
loop and use the year of the date string or only search for the dates in the year div. Not fully tested, but first testings looks good.