Comments (8)
fixed in #1657 This will be part of release 1.45.0 or is available now as master (git) version (3-dot menu -> redownload -> change version to master -> fully restart HA (this will increase update cycle by a lot)
This fix did not work for me (or it broke again?).
The request always responds with 404.
I had to do following changes to finally make it work, additionally to the fix in release 1.45.0:
- Change the API_URL to
https://web4.karlsruhe.de/...
instead ofhttps://web6.karlsruhe.de/...
- AND send the request (line 68) with an additional
verify=False
argument
from hacs_waste_collection_schedule.
Seems like they changed the Api Url again. Their website now also points to web4
from hacs_waste_collection_schedule.
This code (file: custom_components\waste_collection_schedule\waste_collection_schedule\source\karlsruhe_de.py) works for me:
import datetime
import re
import requests
from bs4 import BeautifulSoup
from waste_collection_schedule import Collection # type: ignore[attr-defined]
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
},
"Bernsteinstraße 10 ladeort 1": {
"street": "Bernsteinstraße",
"hnr": 10,
"ladeort": 1
},
"Bernsteinstraße 10 ladeort 2": {
"street": "Bernsteinstraße",
"hnr": 10,
"ladeort": 2
}
}
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_2023/akal.php"
class Source:
def __init__(self, street: str, hnr: str | int, ladeort: int | None = None):
self._street: str = street
self._hnr: str | int = hnr
self._ladeort: int | None = ladeort
def fetch(self):
args = {
"strasse_n": self._street,
"hausnr": self._hnr,
"ladeort": self._ladeort,
"anzeigen": "anzeigen"
}
# get json file
r = requests.post(API_URL, data=args, params={"hausnr=": ""})
r.raise_for_status()
with open("test.html", "w", encoding="utf-8") as f:
f.write(r.text)
soup = BeautifulSoup(r.text, "html.parser")
rows = soup.find_all("div", class_="row")
entries = []
for row in rows:
column = row.find("div", class_="col_6-2")
if column is None or not column.contents:
column = row.find("div", class_="col_7-3")
if column is None or not column.contents:
continue
for content in column.contents:
if content.text.startswith("Sperrmüllabholung"):
bin_type = column.contents[0].text.strip()
if bin_type.endswith(":"):
bin_type = bin_type[:-1].strip()
icon = ICON_MAP.get(bin_type) # Collection icon
elif content.text.startswith("Straßensperrmüll"):
dates = re.findall(r"\d{2}\.\d{2}\.\d{4}", content.text)
date = datetime.datetime.strptime(dates[0], "%d.%m.%Y").date()
entries.append(Collection(date=date, t=bin_type, icon=icon))
else:
bin_type = column.contents[0].text.split(",")[0].strip()
icon = ICON_MAP.get(bin_type) # Collection icon
pickup_col = row.find("div", class_="col_6-3")
if pickup_col is 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()
entries.append(Collection(date=date, t=bin_type, icon=icon))
return entries
from hacs_waste_collection_schedule.
The code works for me, too. I use API_URL https://web6.karlsruhe.de/service/abfall/akal/akal_2024.php instead. Result is the same.
Thanks!
from hacs_waste_collection_schedule.
fixed in #1657
This will be part of release 1.45.0 or is available now as master (git) version (3-dot menu -> redownload -> change version to master -> fully restart HA (this will increase update cycle by a lot)
from hacs_waste_collection_schedule.
should be fixed again in #1694
This will be part of release 1.46.0 or is available now as master (git) version (3-dot menu -> redownload -> change version to master -> fully restart HA (this will increase update cycle by a lot)
from hacs_waste_collection_schedule.
Looks like the API URL https://web6.karlsruhe.de/service/abfall/akal/akal.php changed to https://web6.karlsruhe.de/service/abfall/akal_2023/akal.php.
Change line with open("test.html", "w") as f:
to with open("test.html", "w", encoding="utf-8") as f:
??
Change line bin_type = row.find("div", class_="col_3-2")
to bin_type = row.find("div", class_="col_6-2")
??
Change line pickup_col = row.find("div", class_="col_3-3")
to pickup_col = row.find("div", class_="col_6-3")
??
from hacs_waste_collection_schedule.
According to the main website https://tsk.karlsruhe.de/abfuhrkalender, the API URL is now:
https://web6.karlsruhe.de/service/abfall/akal/akal_2024.php
from hacs_waste_collection_schedule.
Related Issues (20)
- [Bug]: Calender shift 1 day between supplier information and calender integrated from WC (BSR Source) HOT 1
- [Source Request]: Halton Borough Council (UK) HOT 1
- [Bug]: Source is not working HOT 3
- [Source Request]: Dithmarschen, Germany HOT 1
- [Source Request]: South Kesteven District Council HOT 1
- [Source Request]: Moorabool Shire, Victoria, Australia
- [Source Request]: Hull City Council HOT 1
- [Source Request]: Stroud District Council, UK HOT 2
- Request for new source: https://www.monaloga.de/mportal/awista-logistik/stadt-remscheid HOT 1
- [Source Request]: Add Wychavon Council HOT 2
- [Bug]: SSL Error port_enf_sa_gov_au.py HOT 1
- [Source Request]: Ards and North Down Borough Council HOT 2
- [Feature]: Adding Already supported Sources for Austria, Vorarlberg to the Documentation HOT 2
- [Source Request]: Kreis Steinburg, Germany HOT 1
- [Bug]: ICS Sensor Not longer working HOT 1
- [Source Request]: Townsville (https://www.townsville.qld.gov.au) HOT 1
- [Bug]: fetch failed for source Apps by Abfall+: HOT 2
- [Source Request]: Solihull Council, UK HOT 1
- [Source Request]: Darlington Borough Council HOT 3
- [Source Request]: Steinburg, Germany HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hacs_waste_collection_schedule.