Merge pull request #445 from maverickme/master

Add source KWU Landkreis Oder-Spree
This commit is contained in:
Steffen Zimmermann
2022-11-27 16:20:45 +01:00
committed by GitHub
4 changed files with 132 additions and 0 deletions

View File

@@ -112,6 +112,7 @@ Currently the following service providers are supported:
- [Jumomind.de](./doc/source/jumomind_de.md)
- [KAEV Niederlausitz](./doc/source/kaev_niederlausitz_de.md)
- [KWB-Goslar.de](./doc/source/kwb_goslar_de.md)
- [KWU-Entsorgung](./doc/source/kwu_de.md)
- [Landkreis-Wittmund.de](./doc/source/landkreis_wittmund_de.md)
- [Landkreis Rhön Grabfeld](./doc/source/landkreis_rhoen_grabfeld.md)
- [Landkreis Schwäbisch Hall](./doc/source/lrasha_de.md)

View File

@@ -0,0 +1,100 @@
import requests
from bs4 import BeautifulSoup
from datetime import date
from waste_collection_schedule import Collection # type: ignore[attr-defined]
from waste_collection_schedule.service.ICS import ICS
TITLE = "KWU Entsorgung Landkreis Oder-Spree"
DESCRIPTION = "Source for KWU Entsorgung, Germany"
URL = "https://www.kwu-entsorgung.de/"
TEST_CASES = {
"Erkner": {"city": "Erkner", "street": "Heinrich-Heine-Straße", "number": "11"},
"Bad Saarow": {"city": "Bad Saarow", "street": "Ahornallee", "number": "1"}
}
HEADERS = {"user-agent": "Mozilla/5.0 (xxxx Windows NT 10.0; Win64; x64)"}
class Source:
def __init__(self, city, street, number):
self._city = city
self._street = street
self._number = number
self._ics = ICS()
self._iconMap = {
"Restabfall": "mdi:trash-can-outline",
"Gelber Sack" : "mdi:recycle",
"Papiertonne" : "mdi:package-variant",
"Biotonne": "mdi:food-apple-outline",
}
def fetch(self):
session = requests.Session()
params = {
"city": self._city,
"street": self._street,
"number": self._number,
"direct": "true",
}
r = requests.get("https://www.kwu-entsorgung.de/inc/wordpress/kal_objauswahl.php", headers=HEADERS)
parsed_html = BeautifulSoup(r.text, "html.parser")
Orte = parsed_html.find_all('option')
for Ort in Orte:
if self._city in Ort.text:
OrtValue = Ort['value']
break
r = requests.get("https://www.kwu-entsorgung.de/inc/wordpress/kal_str2ort.php", params={"ort": OrtValue}, headers=HEADERS)
parsed_html = BeautifulSoup(r.text, "html.parser")
Strassen = parsed_html.find_all('option')
for Strasse in Strassen:
if self._street in Strasse.text:
StrasseValue = Strasse['value']
break
r = requests.get("https://www.kwu-entsorgung.de/inc/wordpress/kal_str2ort.php", params={"ort": OrtValue, "strasse": StrasseValue}, headers=HEADERS)
parsed_html = BeautifulSoup(r.text, "html.parser")
Objekte = parsed_html.find_all('option')
for Objekt in Objekte:
if self._number in Objekt.text:
ObjektValue = Objekt['value']
break
r = requests.post("https://www.kwu-entsorgung.de/inc/wordpress/kal_uebersicht-2020.php", data={"ort": OrtValue, "strasse": StrasseValue, "objekt": ObjektValue, "jahr": date.today().year}, headers=HEADERS)
parsed_html = BeautifulSoup(r.text, "html.parser")
Links = parsed_html.find_all('a')
for Link in Links:
if 'ICal herunterladen' in Link.text:
ics_url = Link['href']
if ics_url is None:
raise Exception(f"ics url not found")
# get ics file
r = session.get(ics_url, headers=HEADERS)
r.raise_for_status()
# parse ics file
dates = self._ics.convert(r.text)
entries = []
#for d in dates:
# entries.append(Collection(d[0], d[1]))
#return entries
for d in dates:
# _LOGGER.error(d)
waste_type = d[1].strip()
next_pickup_date = d[0]
entries.append(Collection(date=next_pickup_date, t=waste_type, icon=self._iconMap.get(waste_type,"mdi:trash-can")))
return entries

30
doc/source/kwu_de.md Normal file
View File

@@ -0,0 +1,30 @@
# KWU Entsorgung
Support for schedules provided by [kwu-entsorgung.de](https://www.kwu-entsorgung.de/) located Landkreis Oder-Spree, Germany.
## Configuration via configuration.yaml
```yaml
waste_collection_schedule:
sources:
- name: kwu_de
args:
city: Bad Saarow
street: Ahornallee
number: 1
```
### Configuration Variables
**city**<br>
*(string) (required)*
**street**<br>
*(string) (required)*
**number**<br>
*(string) (required)*
## How to get the source arguments
Visit (Entsorgungskalender)[`https://www.kwu-entsorgung.de/?page_id=337`] and search for your address. The `city`, `street` and `number` argument should exactly match the autocomplete result.

View File

@@ -97,6 +97,7 @@ Currently the following service providers are supported:
- [Erlangen-Höchstadt](https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/erlangen_hoechstadt_de.md)
- [Jumomind.de](https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/jumomind_de.md)
- [KWB-Goslar.de](https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/kwb_goslar_de.md)
- [KWU-Entsorgung.de](https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/kwu_de.md)
- [KAEV Niederlausitz](https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/kaev_niederlausitz_de.md)
- [Landkreis-Wittmund.de](https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/landkreis_wittmund_de.md)
- [Landkreis Rhön Grabfeld](https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/landkreis_rhoen_grabfeld.md)