forked from mampfes/hacs_waste_collection_schedule
-
Notifications
You must be signed in to change notification settings - Fork 0
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
8 changed files
with
211 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
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
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
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
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
88 changes: 88 additions & 0 deletions
88
custom_components/waste_collection_schedule/waste_collection_schedule/source/awv_ot_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,88 @@ | ||
from datetime import datetime | ||
from urllib.parse import urlencode | ||
|
||
import requests | ||
from waste_collection_schedule import Collection # type: ignore[attr-defined] | ||
from waste_collection_schedule.service.ICS import ICS | ||
|
||
TITLE = "AWV: Abfall Wirtschaftszweckverband Ostthüringen" | ||
DESCRIPTION = "Source for AWV: Abfall Wirtschaftszweckverband Ostthüringen." | ||
URL = "https://www.awv-ot.de/" | ||
TEST_CASES = { | ||
"Bethenhausen Caasen 15A": { | ||
"city": "Bethenhausen OT Caasen", | ||
"street": "Caasen", | ||
"hnr": "15A", | ||
}, | ||
"Kraftsdorf OT Oberndorf, Klosterlausnitzer Straße 5/1": { | ||
"city": "Kraftsdorf OT Oberndorf", | ||
"street": "Klosterlausnitzer Straße", | ||
"hnr": "5/1", | ||
}, | ||
"Gera, Aga Birkenstraße 9": { | ||
"city": "Gera", | ||
"street": "Aga Birkenstraße", | ||
"hnr": "9", | ||
}, | ||
} | ||
|
||
|
||
ICON_MAP = { | ||
"Hausmuelltonne": "mdi:trash-can", | ||
"Biotonne": "mdi:leaf", | ||
"Papiertonne": "mdi:package-variant", | ||
"Gelbe Tonne": "mdi:recycle", | ||
} | ||
|
||
|
||
API_URL = "https://www.awv-ot.de/tourenauskunft/auskunftbatix.php" | ||
ICS_URL = "https://www.awv-ot.de/tourenauskunft/ics/ics.php" | ||
|
||
|
||
class Source: | ||
def __init__(self, city: str, street: str, hnr: str): | ||
self._city: str = city | ||
self._street: str = street | ||
self._hnr: str = hnr | ||
self._ics = ICS() | ||
|
||
def fetch(self) -> list[Collection]: | ||
now = datetime.now() | ||
entries = self.fetch_year(now.year) | ||
if now.month == 12: | ||
try: | ||
entries.extend(self.fetch_year(now.year + 1)) | ||
except Exception: | ||
pass | ||
return entries | ||
|
||
def fetch_year(self, year: int) -> list[Collection]: | ||
args = { | ||
"JAHR": str(year), | ||
"Ort": self._city, | ||
"Strasse": self._street, | ||
"Step": "3", | ||
"HSN": self._hnr, | ||
} | ||
|
||
session = requests.Session() | ||
r = session.post( | ||
API_URL, | ||
data=urlencode(args, encoding="latin-1"), | ||
headers={"Content-Type": "application/x-www-form-urlencoded"}, | ||
) | ||
r.raise_for_status() | ||
r = session.get(ICS_URL) | ||
r.raise_for_status() | ||
dates = self._ics.convert(r.text) | ||
entries = [] | ||
for d in dates: | ||
bin_type = d[1].removeprefix("Leerung").strip() | ||
entries.append(Collection(d[0], bin_type, ICON_MAP.get(bin_type))) | ||
|
||
if not entries: | ||
raise Exception( | ||
"No entries found Make sure the address matches exactly with an address suggested here: https://www.awv-ot.de/www/awvot/abfuhrtermine/leerungstage/" | ||
) | ||
|
||
return 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,43 @@ | ||
# AWV: Abfall Wirtschaftszweckverband Ostthüringen | ||
|
||
Support for schedules provided by [AWV: Abfall Wirtschaftszweckverband Ostthüringen](https://www.awv-ot.de/), serving Ostthüringen, Germany. | ||
|
||
## Configuration via configuration.yaml | ||
|
||
```yaml | ||
waste_collection_schedule: | ||
sources: | ||
- name: awv_ot_de | ||
args: | ||
city: CITY (Ort) | ||
street: STREET (Straße) | ||
hnr: HNR (Housenummer) | ||
|
||
``` | ||
### Configuration Variables | ||
**city** | ||
*(String) (required)* | ||
**street** | ||
*(String) (required)* | ||
**hnr** | ||
*(String) (required)* | ||
## Example | ||
```yaml | ||
waste_collection_schedule: | ||
sources: | ||
- name: awv_ot_de | ||
args: | ||
city: Bethenhausen OT Caasen | ||
street: Caasen | ||
hnr: 15A | ||
``` | ||
## How to get the source argument | ||
Find the parameter of your address using [https://www.awv-ot.de/www/awvot/abfuhrtermine/leerungstage/](https://www.awv-ot.de/www/awvot/abfuhrtermine/leerungstage/) and write them exactly like on the web page. |
Oops, something went wrong.