mirror of
https://github.com/sascha-hemi/hacs_waste_collection_schedule.git
synced 2026-03-21 03:04:09 +01:00
add ahe_de
This commit is contained in:
@@ -319,6 +319,7 @@ Waste collection schedules in the following formats and countries are supported.
|
||||
- [Abfallwirtschaftsverbandes Lippe](/doc/source/abfall_lippe_de.md) / abfall-lippe.de
|
||||
- [Abfallwirtschaftszweckverband Wartburgkreis (AZV)](/doc/source/hausmuell_info.md) / azv-wak-ea.de
|
||||
- [Abfallzweckverband Rhein-Mosel-Eifel (Landkreis Mayen-Koblenz)](/doc/source/abfall_io.md) / azv-rme.de
|
||||
- [AHE Ennepe-Ruhr-Kreis](/doc/source/ahe_de.md) / ahe.de
|
||||
- [ALBA Berlin](/doc/source/abfall_io.md) / berlin.alba.info
|
||||
- [Altötting (LK)](/doc/source/jumomind_de.md) / lra-aoe.de
|
||||
- [ART Trier](/doc/source/art_trier_de.md) / art-trier.de
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
import requests
|
||||
from bs4 import BeautifulSoup
|
||||
from waste_collection_schedule import Collection # type: ignore[attr-defined]
|
||||
from waste_collection_schedule.service.ICS import ICS
|
||||
|
||||
TITLE = "AHE Ennepe-Ruhr-Kreis"
|
||||
DESCRIPTION = "Source for AHE Ennepe-Ruhr-Kreis."
|
||||
URL = "https://ahe.de"
|
||||
TEST_CASES = {
|
||||
"58300 Ahornstraße 1": {"plz": "58300", "strasse": "Ahornstraße", "hnr": 1},
|
||||
"58313 Alte Straße 1": {"plz": 58313, "strasse": "alte STraße", "hnr": "1"},
|
||||
}
|
||||
|
||||
|
||||
ICON_MAP = {
|
||||
"Restabfall": "mdi:trash-can",
|
||||
"Bioabfall": "mdi:leaf",
|
||||
"Papier": "mdi:package-variant",
|
||||
"Gelber Sack": "mdi:recycle",
|
||||
}
|
||||
|
||||
API_URL = "https://ahe.atino.net/{search}"
|
||||
SEARCH_API_URL = API_URL.format(search="search/{search}")
|
||||
|
||||
|
||||
class Source:
|
||||
def __init__(self, plz: str | int, strasse: str, hnr: str | int):
|
||||
self._plz: str = str(plz).strip()
|
||||
self._strasse: str = strasse
|
||||
self._hnr: str | int = hnr
|
||||
self._ics = ICS()
|
||||
|
||||
def fetch(self):
|
||||
s = requests.Session()
|
||||
r = s.get(API_URL.format(search="pickup-dates"))
|
||||
r.raise_for_status()
|
||||
|
||||
token = BeautifulSoup(r.text, "html.parser").find(
|
||||
"input", {"name": "pickup_date[_token]"}
|
||||
)["value"]
|
||||
|
||||
r = s.get(
|
||||
SEARCH_API_URL.format(search="postalcode"),
|
||||
params={
|
||||
"q": self._plz,
|
||||
},
|
||||
)
|
||||
r.raise_for_status()
|
||||
|
||||
post_id = None
|
||||
for entry in r.json():
|
||||
if entry["text"] == self._plz.replace(" ", ""):
|
||||
post_id = entry["id"]
|
||||
break
|
||||
if post_id is None:
|
||||
raise Exception("No id found for plz")
|
||||
|
||||
r = s.get(
|
||||
SEARCH_API_URL.format(search="city"),
|
||||
params={
|
||||
"postalCode": self._plz,
|
||||
},
|
||||
)
|
||||
r.raise_for_status()
|
||||
|
||||
data = r.json()
|
||||
if "id" not in data:
|
||||
raise Exception("No id found for plz")
|
||||
|
||||
city_id = data["id"]
|
||||
|
||||
r = s.get(
|
||||
SEARCH_API_URL.format(search="street"),
|
||||
params={"cityId": city_id, "q": self._strasse},
|
||||
)
|
||||
r.raise_for_status()
|
||||
|
||||
street_id = None
|
||||
data = r.json()
|
||||
for entry in data:
|
||||
if (
|
||||
entry["name"].replace(" ", "").replace(" ", "").strip().lower()
|
||||
== self._strasse.replace(" ", "").replace(" ", "").strip().lower()
|
||||
):
|
||||
street_id = entry["id"]
|
||||
break
|
||||
if street_id is None:
|
||||
raise Exception("No id found for street")
|
||||
|
||||
data = {
|
||||
"pickup_date[postalCode]": post_id,
|
||||
"fake_pickup_date[postalCode]": post_id,
|
||||
"pickup_date[street]": street_id,
|
||||
"pickup_date[houseNumber]": self._hnr,
|
||||
"pickup_date[format]": "1",
|
||||
"pickup_date[submit]": "",
|
||||
"pickup_date[_token]": token,
|
||||
}
|
||||
r = s.post(API_URL.format(search="pickup-dates"), data=data)
|
||||
r.raise_for_status()
|
||||
if "Es wurden keine Termine gefunden." in r.text:
|
||||
raise Exception(
|
||||
"No dates found for provided addresses please check https://ahe.atino.net/pickup-dates"
|
||||
)
|
||||
|
||||
dates = self._ics.convert(r.text)
|
||||
|
||||
entries = []
|
||||
for d in dates:
|
||||
entries.append(Collection(d[0], d[1], icon=ICON_MAP.get(d[1])))
|
||||
return entries
|
||||
44
doc/source/ahe_de.md
Normal file
44
doc/source/ahe_de.md
Normal file
@@ -0,0 +1,44 @@
|
||||
# AHE Ennepe-Ruhr-Kreis
|
||||
|
||||
Support for schedules provided by [AHE Ennepe-Ruhr-Kreis](https://ahe.de), serving Ennepe-Ruhr-Kreis, Germany.
|
||||
|
||||
## Configuration via configuration.yaml
|
||||
|
||||
```yaml
|
||||
waste_collection_schedule:
|
||||
sources:
|
||||
- name: ahe_de
|
||||
args:
|
||||
plz: POSTLEITZAHL
|
||||
strasse: STRAßE
|
||||
hnr: HAUSNUMMER
|
||||
|
||||
```
|
||||
|
||||
### Configuration Variables
|
||||
|
||||
**plz**
|
||||
*(String | Integer) (required)*
|
||||
|
||||
**strasse**
|
||||
*(String) (required)*
|
||||
|
||||
**hnr**
|
||||
*(String | Integer) (required)*
|
||||
|
||||
## Example
|
||||
|
||||
```yaml
|
||||
waste_collection_schedule:
|
||||
sources:
|
||||
- name: ahe_de
|
||||
args:
|
||||
plz: 58300
|
||||
strasse: Ahornstraße
|
||||
hnr: 1
|
||||
|
||||
```
|
||||
|
||||
## How to get the source argument
|
||||
|
||||
Find the parameter of your address using [https://ahe.atino.net/pickup-dates](https://ahe.atino.net/pickup-dates) and write them exactly like on the web page.
|
||||
Reference in New Issue
Block a user