forked from mampfes/hacs_waste_collection_schedule
-
Notifications
You must be signed in to change notification settings - Fork 1
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
2 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
...om_components/waste_collection_schedule/waste_collection_schedule/source/kumberg_gv_at.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,55 @@ | ||
import re | ||
|
||
import requests | ||
from bs4 import BeautifulSoup | ||
from waste_collection_schedule import Collection # type: ignore[attr-defined] | ||
from waste_collection_schedule.service.ICS import ICS | ||
|
||
TITLE = "Kumberg" | ||
DESCRIPTION = "Source for Kumberg." | ||
URL = "https://www.kumberg.gv.at" | ||
TEST_CASES: dict[str, dict] = {"Whole Kumberg": {}} | ||
|
||
|
||
ICON_MAP = { | ||
"Restmüll": "mdi:trash-can", | ||
"Bio": "mdi:leaf", | ||
"Papier": "mdi:package-variant", | ||
"Gelber Sack": "mdi:recycle", | ||
"Sperrmüll": "mdi:sofa", | ||
} | ||
|
||
|
||
API_URL = "https://www.kumberg.gv.at/kalender/" | ||
|
||
|
||
class Source: | ||
def __init__(self): | ||
self._ics_urls = set[str]() | ||
self._ics = ICS() | ||
|
||
def _first_setup(self): | ||
r = requests.get(API_URL) | ||
soup = BeautifulSoup(r.text, "html.parser") | ||
cal_icons = soup.select("i.fa-calendar-plus") | ||
for icon in cal_icons: | ||
if "abfalltyp" in icon.parent["href"]: | ||
self._ics_urls.add(icon.parent["href"]) | ||
|
||
def fetch(self) -> list[Collection]: | ||
if not self._ics_urls: | ||
self._first_setup() | ||
|
||
collections = [] | ||
for ics_url in self._ics_urls: | ||
r = requests.get(ics_url) | ||
for date_, bin_type in self._ics.convert(r.text): | ||
# remove time like "7.00 - 9.30 Uhr" from bin_type | ||
if re.search(r"\d{1,2}\.\d{2} - \d{1,2}\.\d{2} Uhr", bin_type): | ||
bin_type = re.sub( | ||
r"\d{1,2}\.\d{2} - \d{1,2}\.\d{2} Uhr", "", bin_type | ||
).strip() | ||
|
||
icon = ICON_MAP.get(bin_type) | ||
collections.append(Collection(date_, bin_type, icon)) | ||
return collections |
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,11 @@ | ||
# Kumberg | ||
|
||
Support for schedules provided by [Kumberg](https://www.kumberg.gv.at), serving Kumberg, Austria. | ||
|
||
## Configuration via configuration.yaml | ||
|
||
```yaml | ||
waste_collection_schedule: | ||
sources: | ||
- name: kumberg_gv_at | ||
``` |