-
-
Notifications
You must be signed in to change notification settings - Fork 766
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
171 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
.../waste_collection_schedule/waste_collection_schedule/source/abfallwirtschaft_vechta_de.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import requests | ||
from waste_collection_schedule import Collection # type: ignore[attr-defined] | ||
from waste_collection_schedule.service.ICS import ICS | ||
|
||
import json | ||
import re | ||
from datetime import datetime | ||
|
||
TITLE = "AWB Abfallwirtschaft Vechta" | ||
DESCRIPTION = "Source for AWB Abfallwirtschaft Vechta." | ||
URL = "https://www.abfallwirtschaft-vechta.de/" | ||
TEST_CASES = { | ||
"Vechta, An der Hasenweide": { | ||
"stadt": "Vechta", | ||
"strasse": "An der Hasenweide" | ||
}, | ||
"Bakum, Up'n Sande": { | ||
"stadt": "Bakum", | ||
"strasse": "Up'n Sande" | ||
}, | ||
"Neuenkirchen-Vörden, Braunschweiger Straße": { | ||
"stadt": "Neuenkirchen-Vörden", | ||
"strasse": "Braunschweiger Straße" | ||
}, | ||
"Goldenstedt, An der Ellenbäke": { | ||
"stadt": "Goldenstedt", | ||
"strasse": "An der Ellenbäke" | ||
}, | ||
} | ||
|
||
|
||
ICON_MAP = { | ||
"Restabfall": "mdi:trash-can", | ||
"Glass": "mdi:bottle-soda", | ||
"Bioabfall": "mdi:leaf", | ||
"Altpapier": "mdi:package-variant", | ||
"Altpapier": "mdi:package-variant", | ||
"Altpapier Siemer": "mdi:package-variant", | ||
"Altpapier Pamo": "mdi:package-variant", | ||
"Gelbe Tonne": "mdi:recycle", | ||
} | ||
|
||
class Source: | ||
def __init__(self, stadt: str, strasse: str): | ||
self._stadt: str = stadt | ||
self._strasse: str = strasse | ||
self._ics = ICS() | ||
|
||
def fetch(self): | ||
args = { | ||
"stadt": self._stadt, | ||
"strasse": self._strasse | ||
} | ||
|
||
collection_entries = [] | ||
string_entries = [] | ||
|
||
for papier_typ in ["pamo", "siemer"]: | ||
session = requests.Session() | ||
session.cookies.set("jahr", str(datetime.now().year)) | ||
|
||
r = session.get( | ||
"https://www.abfallwirtschaft-vechta.de/CALENDER/inc.suche_stadt.php", params={"term": self._stadt}) | ||
r.raise_for_status() | ||
city_id = r.json()[0]["id"] | ||
session.cookies.set("stadt", str(city_id)) | ||
|
||
r = session.get("https://www.abfallwirtschaft-vechta.de/CALENDER/inc.suche_strasse.php", | ||
params={"stadt": city_id, "term": self._strasse}) | ||
r.raise_for_status() | ||
street = json.loads(r.text[1:-2])["strassen"][0] | ||
session.cookies.set("stadt", str(street["id"])) | ||
session.cookies.set("abfuhrbezirk", str(street["abfuhrbezirk"])) | ||
session.cookies.set("abfuhrbezirkpapir", str(street[papier_typ])) | ||
session.cookies.set("papier", papier_typ) | ||
|
||
|
||
args = { | ||
"stadt": city_id, | ||
"strasse": street["id"], | ||
"abfuhrbezirkpapier": street[papier_typ], | ||
"jahr": datetime.now().year, | ||
"papier": papier_typ, | ||
"trigger": "false", | ||
"triggerday": "false", | ||
"triggertime": "false", | ||
} | ||
|
||
r = session.get( | ||
"https://www.abfallwirtschaft-vechta.de/CALENDER/inc.get_calender_ics.php", params=args) | ||
r.raise_for_status() | ||
r.encoding = "utf-8" | ||
|
||
# sometimes has a not ascii UID this would raise an Exception while converting | ||
dates = self._ics.convert(r.text.replace("UID:", "NOTUID: ")) | ||
|
||
for d in dates: | ||
bin_type = d[1].replace("Abfuhrtermin", "").replace( | ||
"Erinnerung", "").replace("für", "").strip() | ||
|
||
if f"{bin_type} {str(d[0])}" in string_entries: | ||
continue | ||
string_entries.append(f"{bin_type} {str(d[0])}") | ||
|
||
collection_entries.append(Collection(d[0], bin_type, ICON_MAP.get( | ||
re.sub("[0-9]", "", bin_type).strip().replace(" ", " ")))) | ||
return collection_entries |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# AWB Abfallwirtschaft Vechta | ||
|
||
Support for schedules provided by [AWB Abfallwirtschaft Vechta](https://www.abfallwirtschaft-vechta.de/), serving Landkreis Vechta, Germany. | ||
|
||
## Configuration via configuration.yaml | ||
|
||
```yaml | ||
waste_collection_schedule: | ||
sources: | ||
- name: abfallwirtschaft_vechta_de | ||
args: | ||
stadt: STADT | ||
strasse: STRASSE | ||
|
||
``` | ||
### Configuration Variables | ||
**stadt** | ||
*(String) (required)* | ||
**strasse** | ||
*(String) (required)* | ||
## Example | ||
```yaml | ||
waste_collection_schedule: | ||
sources: | ||
- name: abfallwirtschaft_vechta_de | ||
args: | ||
stadt: Vechta | ||
strasse: An der Hasenweide | ||
|
||
``` | ||
## How to get the source argument | ||
Find the parameter of your address using [https://www.abfallwirtschaft-vechta.de/index.php/termine/abfuhrkalender](https://www.abfallwirtschaft-vechta.de/index.php/termine/abfuhrkalender) and write them exactly like on the web page. | ||
## Filtering | ||
This source returns multiple paper pickup types you probably want only one of them detailed information [Configuring Source(s)](https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/installation.md#configuring-sources) | ||
### Filtering Example | ||
hiding `Siemer Altpapier` | ||
|
||
```yaml | ||
waste_collection_schedule: | ||
sources: | ||
- name: abfallwirtschaft_vechta_de | ||
args: | ||
stadt: Vechta | ||
strasse: An der Hasenweide | ||
customize: | ||
- type: Altpapier 1 Siemer | ||
show: false | ||
- type: Altpapier 2 Siemer | ||
show: false | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters