add afvalstoffendiesnt.nl

This commit is contained in:
5ila5
2024-08-14 17:19:39 +02:00
committed by 5ila5
parent 1e07a9cddb
commit a59e6808f0
6 changed files with 318 additions and 3 deletions

View File

@@ -1194,12 +1194,16 @@ If your service provider is not listed, feel free to open a [source request issu
<details>
<summary>Netherlands</summary>
- ['s-Hertogenbosch](/doc/source/afvalstoffendienst_nl.md) / afvalstoffendienst.nl
- [ACV Group](/doc/source/ximmio_nl.md) / acv-afvalkalender.nl
- [Afvalstoffendienst.nl](/doc/source/afvalstoffendienst_nl.md) / afvalstoffendienst.nl
- [Alpen an den Rijn](/doc/source/hvcgroep_nl.md) / alphenaandenrijn.nl
- [Altena](/doc/source/afvalstoffendienst_nl.md) / altena.afvalstoffendienstkalender.nl
- [Area Afval](/doc/source/ximmio_nl.md) / area-afval.nl
- [Avalex](/doc/source/ximmio_nl.md) / avalex.nl
- [Avri](/doc/source/ximmio_nl.md) / avri.nl
- [Bar Afvalbeheer](/doc/source/ximmio_nl.md) / bar-afvalbeheer.nl
- [Bernheze](/doc/source/afvalstoffendienst_nl.md) / bernheze.afvalstoffendienstkalender.nl
- [Circulus](/doc/source/circulus_nl.md) / mijn.circulus.nl
- [Cyclus NV](/doc/source/hvcgroep_nl.md) / cyclusnv.nl
- [Dar](/doc/source/hvcgroep_nl.md) / dar.nl
@@ -1219,9 +1223,11 @@ If your service provider is not listed, feel free to open a [source request issu
- [Gemeente Voorschoten](/doc/source/hvcgroep_nl.md) / voorschoten.nl
- [Gemeente Waalre](/doc/source/hvcgroep_nl.md) / waalre.nl
- [Gemeente Westland](/doc/source/ximmio_nl.md) / gemeentewestland.nl
- [Heusden](/doc/source/afvalstoffendienst_nl.md) / heusden.afvalstoffendienstkalender.nl
- [HVC Groep](/doc/source/hvcgroep_nl.md) / hvcgroep.nl
- [Meerlanden](/doc/source/ximmio_nl.md) / meerlanden.nl
- [Mijn Blink](/doc/source/hvcgroep_nl.md) / mijnblink.nl
- [Oisterwijk](/doc/source/afvalstoffendienst_nl.md) / oisterwijk.afvalstoffendienstkalender.nl
- [PreZero](/doc/source/hvcgroep_nl.md) / prezero.nl
- [Purmerend](/doc/source/hvcgroep_nl.md) / purmerend.nl
- [RAD BV](/doc/source/ximmio_nl.md) / radbv.nl
@@ -1229,6 +1235,7 @@ If your service provider is not listed, feel free to open a [source request issu
- [Reinis](/doc/source/ximmio_nl.md) / reinis.nl
- [Spaarnelanden](/doc/source/hvcgroep_nl.md) / spaarnelanden.nl
- [Twente Milieu](/doc/source/ximmio_nl.md) / twentemilieu.nl
- [Vught](/doc/source/afvalstoffendienst_nl.md) / vught.afvalstoffendienstkalender.nl
- [Waardlanden](/doc/source/ximmio_nl.md) / waardlanden.nl
- [Ximmio](/doc/source/ximmio_nl.md) / ximmio.nl
- [ZRD](/doc/source/hvcgroep_nl.md) / zrd.nl

View File

@@ -6539,6 +6539,13 @@
}
],
"Netherlands": [
{
"title": "'s-Hertogenbosch",
"module": "afvalstoffendienst_nl",
"default_params": {
"region": "s-hertogenbosch"
}
},
{
"title": "ACV Group",
"module": "ximmio_nl",
@@ -6546,6 +6553,11 @@
"company": "acv"
}
},
{
"title": "Afvalstoffendienst.nl",
"module": "afvalstoffendienst_nl",
"default_params": {}
},
{
"title": "Alpen an den Rijn",
"module": "hvcgroep_nl",
@@ -6553,6 +6565,13 @@
"service": "alphenaandenrijn"
}
},
{
"title": "Altena",
"module": "afvalstoffendienst_nl",
"default_params": {
"region": "altena"
}
},
{
"title": "Area Afval",
"module": "ximmio_nl",
@@ -6581,6 +6600,13 @@
"company": "bar"
}
},
{
"title": "Bernheze",
"module": "afvalstoffendienst_nl",
"default_params": {
"region": "bernheze"
}
},
{
"title": "Circulus",
"module": "circulus_nl",
@@ -6712,6 +6738,13 @@
"company": "westland"
}
},
{
"title": "Heusden",
"module": "afvalstoffendienst_nl",
"default_params": {
"region": "heusden"
}
},
{
"title": "HVC Groep",
"module": "hvcgroep_nl",
@@ -6733,6 +6766,13 @@
"service": "mijnblink"
}
},
{
"title": "Oisterwijk",
"module": "afvalstoffendienst_nl",
"default_params": {
"region": "oisterwijk"
}
},
{
"title": "PreZero",
"module": "hvcgroep_nl",
@@ -6780,6 +6820,13 @@
"company": "twentemilieu"
}
},
{
"title": "Vught",
"module": "afvalstoffendienst_nl",
"default_params": {
"region": "vught"
}
},
{
"title": "Waardlanden",
"module": "ximmio_nl",

View File

@@ -282,7 +282,8 @@
"voivodeship": "Voivodeship",
"building_id": "Building Id",
"addressNo": "Address No",
"territory": "Territory"
"territory": "Territory",
"addition": "Addition"
},
"data_description": {
"calendar_title": "A more readable, or user-friendly, name for the waste calendar. If nothing is provided, the name returned by the source will be used."
@@ -536,7 +537,8 @@
"voivodeship": "Voivodeship",
"building_id": "Building Id",
"addressNo": "Address No",
"territory": "Territory"
"territory": "Territory",
"addition": "Addition"
}
}
},

View File

@@ -0,0 +1,202 @@
import logging
from datetime import datetime
from typing import Literal
from urllib.parse import quote
import requests
from bs4 import BeautifulSoup
from dateutil.parser import parse
from waste_collection_schedule import Collection # type: ignore[attr-defined]
_LOGGER = logging.getLogger(__name__)
TITLE = "Afvalstoffendienst.nl"
DESCRIPTION = (
"Source for 's Hertogenbosch, Heusden, Vught, Oisterwijk, Altena, Bernheze"
)
URL = "https://www.afvalstoffendienst.nl/"
TEST_CASES = {
"s-hertogenbosch, 5151MS 37 ": {
"postcode": "5151MS",
"house_number": 37,
"region": "s-hertogenbosch",
},
"heuden, 5256EJ, 44C": {
"postcode": "5256EJ",
"house_number": 44,
"addition": "C",
"region": "heusden",
},
"vught, 5262 CJ 18": {
"postcode": "5262 CJ",
"house_number": "18",
"region": "vught",
},
"Oisterwijk 5062 ER 13": {
"postcode": "5062 ER",
"house_number": "13",
"region": "oisterwijk",
},
"Altena 4286 AL 1": {
"postcode": "4286 AA",
"house_number": "1",
"region": "altena",
},
"bernheze": {"postcode": "5473 EW", "house_number": 50, "region": "bernheze"},
}
REGIONS = {
"heusden": {
"title": "Heusden",
"url": "https://heusden.afvalstoffendienstkalender.nl/",
"default_params": {"region": "heusden"},
},
"vught": {
"title": "Vught",
"url": "https://vught.afvalstoffendienstkalender.nl/",
"default_params": {"region": "vught"},
},
"oisterwijk": {
"title": "Oisterwijk",
"url": "https://oisterwijk.afvalstoffendienstkalender.nl/",
"default_params": {"region": "oisterwijk"},
},
"altena": {
"title": "Altena",
"url": "https://altena.afvalstoffendienstkalender.nl/",
"default_params": {"region": "altena"},
},
"bernheze": {
"title": "Bernheze",
"url": "https://bernheze.afvalstoffendienstkalender.nl/",
"default_params": {"region": "bernheze"},
},
"s-hertogenbosch": {
"title": "'s-Hertogenbosch",
"url": "https://www.afvalstoffendienst.nl/",
"default_params": {"region": "s-hertogenbosch"},
},
}
EXTRA_INFO = REGIONS.values()
["heusden", "vught", "oisterwijk", "altena", "bernheze", "s-hertogenbosch"]
REGIONS_LITERAL = Literal[
"heusden", "vught", "oisterwijk", "altena", "bernheze", "s-hertogenbosch"
]
ICON_MAP = {
"Groente": "mdi:apple",
"Plastic": "mdi:recycle",
"Papier": "mdi:package-variant",
"Restafval": "mdi:trash-can",
"Kerstbomen": "mdi:pine-tree",
}
DUTCH_MONTHS = {
"januari": "January",
"februari": "February",
"maart": "March",
"april": "April",
"mei": "May",
"juni": "June",
"juli": "July",
"augustus": "August",
"september": "September",
"oktober": "October",
"november": "November",
"december": "December",
}
DUTCH_WEEKDAYS = {
"maandag": "Monday",
"dinsdag": "Tuesday",
"woensdag": "Wednesday",
"donderdag": "Thursday",
"vrijdag": "Friday",
"zaterdag": "Saturday",
"zondag": "Sunday",
}
NORMAL_API_URL = "https://{region}.afvalstoffendienstkalender.nl/nl/{postcode}/{hnr}/"
HERTOGENBOSCH_API_URL = "https://www.afvalstoffendienst.nl/afvalkalender"
class Source:
def __init__(
self,
postcode: str,
house_number: str | int,
addition: str | None = None,
region: REGIONS_LITERAL = "s-hertogenbosch",
):
self._postcode: str = postcode.replace(" ", "").upper()
self._house_number: str | int = house_number
self._addition: str | None = addition.lower() if addition else None
if region.lower() not in REGIONS:
raise ValueError(f"Invalid region: {region}, must be one of {REGIONS}")
self._url = NORMAL_API_URL.format(
postcode=self._postcode, hnr=self._house_number, region=region
)
if self._addition:
self._url += f"{self._addition}/"
self._cookies = {}
self._prepare_urls = []
if region == "s-hertogenbosch":
self._url = HERTOGENBOSCH_API_URL
self._cookies = {
"loginParam": quote(
f'{{"username":null,"password":null,"rememberMe":null,"postcode":"{self._postcode}","huisnummer":"{self._house_number}","toevoeging":"{self._addition if self._addition else ""}","debtornumber":""}}'
)
}
self._prepare_urls = [
"https://www.afvalstoffendienst.nl/bewoners/s-hertogenbosch"
]
def fetch(self) -> list[Collection]:
s = requests.Session()
cookies = self._cookies.copy()
for url in self._prepare_urls:
s.get(url)
cookies.update(s.cookies.get_dict())
# get json file
r = requests.get(self._url, cookies=cookies)
r.raise_for_status()
soup = BeautifulSoup(r.text, "html.parser")
table = soup.select_one("div#jaaroverzicht") or soup.select_one(
"div.ophaaldagen"
)
table = table or soup
descr_spans = table.select("span.afvaldescr")
entries = []
for descr_span in descr_spans:
bin_type = descr_span.text.strip()
date_span = descr_span.find_previous_sibling("span")
if date_span is None:
# Get text sibbling not inside any tag (e.g. vrijdag 27 december <br> <span THIS TAG>text</span>)
date_str = descr_span.parent.text.replace(descr_span.text, "").strip()
else:
date_str = date_span.text.lower()
# replace Dutch months and weekdays with English
for dutch, english in {**DUTCH_MONTHS, **DUTCH_WEEKDAYS}.items():
date_str = date_str.replace(dutch, english)
try:
date = parse(date_str, dayfirst=True, default=datetime.now()).date()
except ValueError:
continue
icon = ICON_MAP.get(bin_type.split()[0].strip("-,")) # Collection icon
entries.append(Collection(date=date, t=bin_type, icon=icon))
return entries

View File

@@ -0,0 +1,57 @@
# Afvalstoffendienst.nl
Support for schedules provided by [Afvallstoffendienst.nl](https://www.afvalstoffendienst.nl/), serving 's Hertogenbosch, Heusden, Vught, Oisterwijk, Altena, Bernheze. Netherlands.
## Configuration via configuration.yaml
```yaml
waste_collection_schedule:
sources:
- name: afvalstoffendienst_nl
args:
region: REGION
postcode: POSTCODE
house_number: "HOUSSE NUMBER (huisnummer)"
addition: ADDITION (toevoeging)
```
### Configuration Variables
**region**
*(String) (required)* should be one of `heusden`, `vught`, `oisterwijk`, `altena`, `bernheze`, `s-hertogenbosch`
**postcode**
*(String) (required)*
**house_number**
*(String | Integer) (required)*
**addition**
*(String) (optional)*
## Example
```yaml
waste_collection_schedule:
sources:
- name: afvalstoffendienst_nl
args:
region: s-hertogenbosch
postcode: 5151MS
house_number: "37"
```
```yaml
waste_collection_schedule:
sources:
- name: afvalstoffendienst_nl
args:
region: heusden
postcode: 5256EJ
house_number: 44
addition: "C"
```
## How to get the source argument
You can check weather your parameter return a valid result using the website <https://www.afvalstoffendienst.nl>

View File

@@ -29,7 +29,7 @@ Waste collection schedules from service provider web sites are updated daily, de
| Italy | CIDIU S.p.A., Contarina S.p.A, Il Rifiutologo |
| Lithuania | Kauno švara, Telšių keliai |
| Luxembourg | Esch-sur-Alzette |
| Netherlands | ACV Group, Alpen an den Rijn, Area Afval, Avalex, Avri, Bar Afvalbeheer, Circulus, Cyclus NV, Dar, Den Haag, GAD, Gemeente Almere, Gemeente Berkelland, Gemeente Cranendonck, Gemeente Hellendoorn, Gemeente Lingewaard, Gemeente Meppel, Gemeente Middelburg + Vlissingen, Gemeente Peel en Maas, Gemeente Schouwen-Duiveland, Gemeente Sudwest-Fryslan, Gemeente Venray, Gemeente Voorschoten, Gemeente Waalre, Gemeente Westland, HVC Groep, Meerlanden, Mijn Blink, PreZero, Purmerend, RAD BV, Rd4, Reinis, Spaarnelanden, Twente Milieu, Waardlanden, Ximmio, ZRD, Ôffalkalinder van Noardeast-Fryslân & Dantumadiel |
| Netherlands | 's-Hertogenbosch, ACV Group, Afvalstoffendienst.nl, Alpen an den Rijn, Altena, Area Afval, Avalex, Avri, Bar Afvalbeheer, Bernheze, Circulus, Cyclus NV, Dar, Den Haag, GAD, Gemeente Almere, Gemeente Berkelland, Gemeente Cranendonck, Gemeente Hellendoorn, Gemeente Lingewaard, Gemeente Meppel, Gemeente Middelburg + Vlissingen, Gemeente Peel en Maas, Gemeente Schouwen-Duiveland, Gemeente Sudwest-Fryslan, Gemeente Venray, Gemeente Voorschoten, Gemeente Waalre, Gemeente Westland, Heusden, HVC Groep, Meerlanden, Mijn Blink, Oisterwijk, PreZero, Purmerend, RAD BV, Rd4, Reinis, Spaarnelanden, Twente Milieu, Vught, Waardlanden, Ximmio, ZRD, Ôffalkalinder van Noardeast-Fryslân & Dantumadiel |
| New Zealand | Auckland Council, Christchurch City Council, Dunedin District Council, Gore, Invercargill & Southland, Hamilton City Council, Horowhenua District Council, Hutt City Council, Porirua City, Rotorua Lakes Council, Tauranga City Council, Waipa District Council, Wellington City Council |
| Norway | BIR (Bergensområdets Interkommunale Renovasjonsselskap), Fosen Renovasjon, IRiS, Min Renovasjon, Movar IKS, Oslo Kommune, ReMidt Orkland muni, Sandnes Kommune, Stavanger Kommune, Trondheim |
| Poland | App Moje Odpady, Bydgoszcz Pronatura, Ecoharmonogram, Gmina Miękinia, Koziegłowy/Objezierze/Oborniki, Poznań, Warsaw, Wrocław |