mirror of
https://github.com/sascha-hemi/hacs_waste_collection_schedule.git
synced 2026-03-21 05:06:33 +01:00
add source karlsruhe_de
This commit is contained in:
@@ -327,6 +327,7 @@ Waste collection schedules in the following formats and countries are supported.
|
||||
- [Bürgerportal](/doc/source/buergerportal_de.md) / c-trace.de
|
||||
- [C-Trace](/doc/source/c_trace_de.md) / c-trace.de
|
||||
- [Chemnitz (ASR)](/doc/source/hausmuell_info.md) / asr-chemnitz.de
|
||||
- [City of Karlsruhe](/doc/source/karlsruhe_de.md) / karlsruhe.de
|
||||
- [CM City Media - Müllkalender](/doc/source/cmcitymedia_de.md) / cmcitymedia.de
|
||||
- [Darmstadt (MyMuell App)](/doc/source/jumomind_de.md) / mymuell.de
|
||||
- [Darmstadt-Dieburg (ZAW)](/doc/source/jumomind_de.md) / zaw-online.de
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
import requests
|
||||
from waste_collection_schedule import Collection # type: ignore[attr-defined]
|
||||
from bs4 import BeautifulSoup
|
||||
import re
|
||||
import datetime
|
||||
|
||||
TITLE = "City of Karlsruhe"
|
||||
DESCRIPTION = "Source for City of Karlsruhe."
|
||||
URL = "https://www.karlsruhe.de/"
|
||||
TEST_CASES = {
|
||||
"Östliche Rheinbrückenstraße 1": {
|
||||
"street": "Östliche Rheinbrückenstraße",
|
||||
"hnr": 1
|
||||
},
|
||||
"Habichtweg 4": {
|
||||
"street": "Habichtweg",
|
||||
"hnr": "4"
|
||||
},
|
||||
"Machstraße 5": {
|
||||
"street": "Machstraße",
|
||||
"hnr": "5"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ICON_MAP = {
|
||||
"Restmüll": "mdi:trash-can",
|
||||
"Bioabfall": "mdi:leaf",
|
||||
"Papier": "mdi:package-variant",
|
||||
"Wertstoff": "mdi:recycle",
|
||||
"Sperrmüllabholung": "mdi:wardrobe"
|
||||
}
|
||||
|
||||
|
||||
API_URL = "https://web6.karlsruhe.de/service/abfall/akal/akal.php"
|
||||
|
||||
|
||||
class Source:
|
||||
def __init__(self, street: str, hnr: str | int):
|
||||
self._street: str = street
|
||||
self._hnr: str | int = hnr
|
||||
|
||||
def fetch(self):
|
||||
args = {
|
||||
"strasse_n": self._street,
|
||||
"hausnr": self._hnr,
|
||||
"anzeigen": "anzeigen",
|
||||
}
|
||||
|
||||
# get json file
|
||||
r = requests.post(API_URL, data=args, params={"hausnr=": ""})
|
||||
r.raise_for_status()
|
||||
|
||||
with open("test.html", "w") as f:
|
||||
f.write(r.text)
|
||||
|
||||
soup = BeautifulSoup(r.text, "html.parser")
|
||||
rows = soup.find_all("div", class_="row")
|
||||
entries = []
|
||||
|
||||
for row in rows:
|
||||
bin_type = row.find("div", class_="col_3-2")
|
||||
if bin_type == None:
|
||||
continue
|
||||
|
||||
bin_type = bin_type.contents[0].text.split(",")[0].strip()
|
||||
if bin_type.endswith(":"):
|
||||
bin_type = bin_type[:-1].strip()
|
||||
|
||||
pickup_col = row.find("div", class_="col_3-3")
|
||||
if pickup_col == None or not pickup_col.contents:
|
||||
pickup_col = row.find("div", class_="col_4-3")
|
||||
|
||||
if pickup_col == None or not pickup_col.contents:
|
||||
continue
|
||||
|
||||
for date in re.findall(r"\d{2}\.\d{2}\.\d{4}", pickup_col.text):
|
||||
date = datetime.datetime.strptime(date, "%d.%m.%Y").date()
|
||||
|
||||
icon = ICON_MAP.get(bin_type) # Collection icon
|
||||
entries.append(Collection(date=date, t=bin_type, icon=icon))
|
||||
return entries
|
||||
39
doc/source/karlsruhe_de.md
Normal file
39
doc/source/karlsruhe_de.md
Normal file
@@ -0,0 +1,39 @@
|
||||
# City of Karlsruhe
|
||||
|
||||
Support for schedules provided by [City of Karlsruhe](https://www.karlsruhe.de/), serving Karlsruhe, Germany.
|
||||
|
||||
## Configuration via configuration.yaml
|
||||
|
||||
```yaml
|
||||
waste_collection_schedule:
|
||||
sources:
|
||||
- name: karlsruhe_de
|
||||
args:
|
||||
street: STRAßE
|
||||
hnr: "HAUSNUMMER"
|
||||
|
||||
```
|
||||
|
||||
### Configuration Variables
|
||||
|
||||
**street**
|
||||
*(String) (required)*
|
||||
|
||||
**hnr**
|
||||
*(String | Integer) (required)*
|
||||
|
||||
|
||||
## Example
|
||||
|
||||
```yaml
|
||||
waste_collection_schedule:
|
||||
sources:
|
||||
- name: karlsruhe_de
|
||||
args:
|
||||
street: Östliche Rheinbrückenstraße
|
||||
hnr: 1
|
||||
```
|
||||
|
||||
## How to get the source argument
|
||||
|
||||
Find the parameter of your address using [https://web6.karlsruhe.de/service/abfall/akal/akal.php](https://web6.karlsruhe.de/service/abfall/akal/akal.php) and write them exactly like on the web page.
|
||||
Reference in New Issue
Block a user