-
-
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
8 changed files
with
189 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
89 changes: 89 additions & 0 deletions
89
...onents/waste_collection_schedule/waste_collection_schedule/source/bad_eisenkappel_info.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,89 @@ | ||
from datetime import datetime | ||
|
||
import requests | ||
from bs4 import BeautifulSoup | ||
from waste_collection_schedule import Collection | ||
from waste_collection_schedule.exceptions import SourceArgumentNotFoundWithSuggestions | ||
|
||
TITLE = "Eisenkappel-Vellach" | ||
DESCRIPTION = "Source for Eisenkappel-Vellach." | ||
URL = "https://www.bad-eisenkappel.info/" | ||
TEST_CASES = {"Leppen": {"region": "Leppen"}} | ||
COUNTRY = "at" | ||
|
||
ICON_MAP = { | ||
"Restmüll": "mdi:trash-can", | ||
"Glasbehälter": "mdi:bottle-soda", | ||
"Biomüll": "mdi:leaf", | ||
"Altpapiertonne": "mdi:package-variant", | ||
"Recycle": "mdi:recycle", | ||
"Recyclinghof": "mdi:factory", | ||
"Gelbe": "mdi:recycle", | ||
} | ||
|
||
|
||
API_URL = "https://www.bad-eisenkappel.info/gemeinde/onlineservice/abfuhrtermine.html" | ||
|
||
PARAM_TRANSLATIONS = { | ||
"de": { | ||
"region": "Ortsteil", | ||
} | ||
} | ||
|
||
|
||
class Source: | ||
def __init__(self, region: str): | ||
self._region: str = region | ||
|
||
def fetch(self) -> list[Collection]: | ||
# get json file | ||
r = requests.get(API_URL) | ||
r.raise_for_status() | ||
|
||
soup = BeautifulSoup(r.text, "html.parser") | ||
tables = soup.select("table") | ||
entries = [] | ||
regions = set[str]() | ||
for table in tables: | ||
trs = table.select("tr") | ||
for tr in trs: | ||
tds = tr.select("td") | ||
if len(tds) < 3: | ||
continue | ||
date_str = tds[0].text.strip().split(". ")[1] | ||
|
||
date = datetime.strptime(date_str, "%d.%m.%y").date() | ||
bin_type = ( | ||
tds[1] | ||
.text.strip() | ||
.removeprefix("Abholung") | ||
.removeprefix("Entleerung") | ||
.strip() | ||
.removeprefix("von") | ||
.strip() | ||
.removeprefix("der") | ||
.strip() | ||
) | ||
icon = ICON_MAP.get(bin_type.split()[0].strip(", ")) | ||
region_str = tds[2].text.strip() | ||
for region in region_str.split(","): | ||
regions.add(region.strip()) | ||
|
||
if ( | ||
region_str.lower() == "Gesamtes Gemeindegebiet".lower() | ||
or self._region.lower().replace(" ", "") | ||
in region_str.lower().replace(" ", "").split(",") | ||
): | ||
entries.append(Collection(date=date, t=bin_type, icon=icon)) | ||
|
||
regions.remove("Gesamtes Gemeindegebiet") | ||
if self._region.lower().replace(" ", "") not in map( | ||
lambda x: x.lower().replace(" ", ""), regions | ||
): | ||
raise SourceArgumentNotFoundWithSuggestions( | ||
argument="region", | ||
value=self._region, | ||
suggestions=regions, | ||
) | ||
|
||
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,32 @@ | ||
# Eisenkappel-Vellach / Bad Eisenkappel | ||
|
||
Support for schedules provided by [Bad Eisenkappel](https://www.bad-eisenkappel.info/), serving Eisenkappel-Vellach, Germany. | ||
|
||
## Configuration via configuration.yaml | ||
|
||
```yaml | ||
waste_collection_schedule: | ||
sources: | ||
- name: bad_eisenkappel_info | ||
args: | ||
region: REGION | ||
``` | ||
### Configuration Variables | ||
**region** | ||
*(String) (required)* | ||
## Example | ||
```yaml | ||
waste_collection_schedule: | ||
sources: | ||
- name: bad_eisenkappel_info | ||
args: | ||
region: Leppen | ||
``` | ||
## How to get the source argument | ||
The region should match one of the regions listed in the third column of the table at <https://www.bad-eisenkappel.info/gemeinde/onlineservice/abfuhrtermine.html> |