mirror of
https://github.com/sascha-hemi/hacs_waste_collection_schedule.git
synced 2026-03-21 03:04:09 +01:00
add source Kusel, Germany
This commit is contained in:
@@ -425,6 +425,7 @@ Waste collection schedules in the following formats and countries are supported.
|
||||
- [Landkreis Kelheim](/doc/source/awido_de.md) / landkreis-kelheim.de
|
||||
- [Landkreis Kronach](/doc/source/awido_de.md) / landkreis-kronach.de
|
||||
- [Landkreis Kulmbach](/doc/source/awido_de.md) / landkreis-kulmbach.de
|
||||
- [Landkreis Kusel](/doc/source/landkreis_kusel_de.md) / landkreis-kusel.de
|
||||
- [Landkreis Leer (MyMuell App)](/doc/source/jumomind_de.md) / mymuell.de
|
||||
- [Landkreis Limburg-Weilburg](/doc/source/abfall_io.md) / awb-lm.de
|
||||
- [Landkreis Mettmann (MyMuell App)](/doc/source/jumomind_de.md) / mymuell.de
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
import requests
|
||||
from bs4 import BeautifulSoup, NavigableString
|
||||
from waste_collection_schedule import Collection # type: ignore[attr-defined]
|
||||
from waste_collection_schedule.service.ICS import ICS
|
||||
|
||||
TITLE = "Landkreis Kusel"
|
||||
DESCRIPTION = "Source for Landkreis Kusel."
|
||||
URL = "https://www.landkreis-kusel.de/"
|
||||
TEST_CASES = {
|
||||
"Adenbach": {"ortsgemeinde": "Adenbach"},
|
||||
"St. Julian - Eschenau": {"ortsgemeinde": "St. Julian - Eschenau"},
|
||||
"rutsweiler glan (wrong spelling)": {"ortsgemeinde": "rutsweiler glan"},
|
||||
}
|
||||
|
||||
|
||||
ICON_MAP = {
|
||||
"restmüll": "mdi:trash-can",
|
||||
"glasabfuhr": "mdi:bottle-soda",
|
||||
"bioabfall": "mdi:leaf",
|
||||
"Paper": "mdi:package-variant",
|
||||
"wertstoffsäcke": "mdi:recycle",
|
||||
"umweltmobil": "mdi:dump-truck",
|
||||
}
|
||||
|
||||
|
||||
API_URL = "https://abfallwirtschaft.landkreis-kusel.de"
|
||||
|
||||
|
||||
def make_comparable(ortsgemeinde: str) -> str:
|
||||
return (
|
||||
ortsgemeinde.lower()
|
||||
.replace("-", "")
|
||||
.replace(".", "")
|
||||
.replace("/", "")
|
||||
.replace(" ", "")
|
||||
)
|
||||
|
||||
|
||||
class Source:
|
||||
def __init__(self, ortsgemeinde: str):
|
||||
self._ortsgemeinde: str = make_comparable(ortsgemeinde)
|
||||
self._ics = ICS()
|
||||
|
||||
def fetch(self):
|
||||
s = requests.Session()
|
||||
# get json file
|
||||
r = s.get(API_URL)
|
||||
r.raise_for_status()
|
||||
|
||||
soup = BeautifulSoup(r.text, "html.parser")
|
||||
select = soup.find("select", {"id": "search_ak_pickup_akPickup"})
|
||||
|
||||
if not select or isinstance(select, NavigableString):
|
||||
raise Exception("Invalid response from API")
|
||||
|
||||
pickup_id = None
|
||||
for option in select.find_all("option"):
|
||||
if make_comparable(option.text) == self._ortsgemeinde:
|
||||
pickup_id = option["value"]
|
||||
break
|
||||
|
||||
if not pickup_id:
|
||||
raise Exception(
|
||||
f"could not find matching 'Ortsgemeinde' please check your spelling at {API_URL}"
|
||||
)
|
||||
|
||||
args = {
|
||||
"search_ak_pickup[akPickup]": pickup_id,
|
||||
"search_ak_pickup[wasteType]": "0",
|
||||
"search_ak_pickup[startDate]": "",
|
||||
"search_ak_pickup[endDate]": "",
|
||||
"search_ak_pickup[search]": "",
|
||||
}
|
||||
|
||||
r = s.post(API_URL, data=args)
|
||||
r.raise_for_status()
|
||||
|
||||
r = s.get(f"{API_URL}/ical")
|
||||
r.raise_for_status()
|
||||
|
||||
dates = self._ics.convert(r.text)
|
||||
entries = []
|
||||
for d in dates:
|
||||
entries.append(Collection(d[0], d[1], ICON_MAP.get(d[1].lower())))
|
||||
|
||||
return entries
|
||||
34
doc/source/landkreis_kusel_de.md
Normal file
34
doc/source/landkreis_kusel_de.md
Normal file
@@ -0,0 +1,34 @@
|
||||
# Landkreis Kusel
|
||||
|
||||
Support for schedules provided by [Landkreis Kusel](https://www.landkreis-kusel.de/), Germany.
|
||||
|
||||
## Configuration via configuration.yaml
|
||||
|
||||
```yaml
|
||||
waste_collection_schedule:
|
||||
sources:
|
||||
- name: landkreis_kusel_de
|
||||
args:
|
||||
ortsgemeinde: ORTSGEMEINDE
|
||||
|
||||
```
|
||||
|
||||
### Configuration Variables
|
||||
|
||||
**ortsgemeinde**
|
||||
*(String) (required)*
|
||||
|
||||
## Example
|
||||
|
||||
```yaml
|
||||
waste_collection_schedule:
|
||||
sources:
|
||||
- name: landkreis_kusel_de
|
||||
args:
|
||||
ortsgemeinde: Adenbach
|
||||
|
||||
```
|
||||
|
||||
## How to get the source argument
|
||||
|
||||
Go to <https://www.landkreis-kusel.de/buergerservice-und-verwaltung/themen/abfallwirtschaft/abfall-app-abfallkalender/> and select your `Ortsgemeinde` and use this as `ortsgemeinde` parameter. Copy it exactly from the web page.
|
||||
Reference in New Issue
Block a user