-
-
Notifications
You must be signed in to change notification settings - Fork 712
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* This pull request adds a new source for: TBV Velbert, Germany. Tests: ``` Testing source tbv_velbert_de ... found 9 entries for Lindenkamp 2023-10-25 : Restmüll-Gefäß [mdi:trash-can] 2023-11-08 : Restmüll-Gefäß [mdi:trash-can] 2023-11-22 : Restmüll-Gefäß [mdi:trash-can] 2023-10-30 : Gelbe Tonne [mdi:recycle] 2023-11-13 : Gelbe Tonne [mdi:recycle] 2023-11-27 : Gelbe Tonne [mdi:recycle] 2023-10-31 : Papier-Tonne [mdi:package-variant] 2023-11-28 : Papier-Tonne [mdi:package-variant] 2023-12-27 : Papier-Tonne [mdi:package-variant] found 12 entries for Rathaus 2023-10-27 : Restmüll-Gefäß [mdi:trash-can] 2023-11-04 : Restmüll-Gefäß [mdi:trash-can] 2023-11-10 : Restmüll-Gefäß [mdi:trash-can] 2023-11-02 : Gelbe Tonne [mdi:recycle] 2023-11-15 : Gelbe Tonne [mdi:recycle] 2023-11-29 : Gelbe Tonne [mdi:recycle] 2023-11-02 : Bio-Tonne [mdi:leaf] 2023-11-15 : Bio-Tonne [mdi:leaf] 2023-11-29 : Bio-Tonne [mdi:leaf] 2023-10-25 : Papier-Tonne [mdi:package-variant] 2023-11-22 : Papier-Tonne [mdi:package-variant] 2023-12-19 : Papier-Tonne [mdi:package-variant] ``` * reformatting
- Loading branch information
Showing
4 changed files
with
107 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
68 changes: 68 additions & 0 deletions
68
...m_components/waste_collection_schedule/waste_collection_schedule/source/tbv_velbert_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,68 @@ | ||
import datetime | ||
import logging | ||
|
||
import requests | ||
from bs4 import BeautifulSoup | ||
from waste_collection_schedule import Collection # type: ignore[attr-defined] | ||
|
||
TITLE = "TBV Velbert" | ||
DESCRIPTION = "Source script for tbv-velbert.de, germany" | ||
URL = "https://www.tbv-velbert.de" | ||
TEST_CASES = { | ||
"Lindenkamp": {"street": "Am Lindenkamp 33"}, | ||
"Rathaus": {"street": "Thomasstraße 1"}, | ||
} | ||
|
||
API_URL = "https://www.tbv-velbert.de/abfall/abfallkalender-und-abfuhrtermine/abfallabfuhr-suche" | ||
HEADERS = {"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64)"} | ||
ICON_MAP = { | ||
"Restmüll-Gefäß": "mdi:trash-can", | ||
"Gelbe Tonne": "mdi:recycle", | ||
"Bio-Tonne": "mdi:leaf", | ||
"Papier-Tonne": "mdi:package-variant", | ||
} | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
class Source: | ||
def __init__(self, street): | ||
self._street = street | ||
|
||
def fetch(self): | ||
r = requests.post( | ||
API_URL, | ||
headers=HEADERS, | ||
data={ | ||
"tx_tbvabfall_strassensuche[abgeschickt]": 1, | ||
"tx_tbvabfall_strassensuche[suchbegriff]": self._street, | ||
}, | ||
) | ||
_LOGGER.debug( | ||
f"Fetching waste schedule for '{self._street}' returned status: {r.status_code}." | ||
) | ||
r.raise_for_status() | ||
|
||
parser = BeautifulSoup(r.text, "html.parser") | ||
content_block = parser.find("div", class_="right-side") | ||
elements = content_block.find_all(["strong", "span"]) | ||
_LOGGER.debug(f"Found {len(elements)} elements in request.") | ||
|
||
entries = [] | ||
for i in range(0, len(elements), 2): | ||
waste_type = elements[i].get_text()[0:-1] # strip trailing colon | ||
waste_dates = ( | ||
elements[i + 1].get_text().split(":")[1] | ||
) # get dates after colon | ||
waste_dates = waste_dates.strip().split(" ") # convert to list | ||
waste_dates[:] = [w for w in waste_dates if w] # remove empty strings | ||
for d in waste_dates: | ||
entries.append( | ||
Collection( | ||
datetime.datetime.strptime(d, "%d.%m.%Y").date(), | ||
waste_type, | ||
ICON_MAP.get(waste_type), | ||
) | ||
) | ||
|
||
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,37 @@ | ||
# Technische Betriebe Velbert | ||
|
||
Support for schedules provided by [Technische Betriebe Velbert](https://www.tbv-velbert.de/), Germany. | ||
|
||
## Configuration via configuration.yaml | ||
|
||
```yaml | ||
waste_collection_schedule: | ||
sources: | ||
- name: tbv_velbert_de | ||
args: | ||
street: STRASSE | ||
``` | ||
### Configuration Variables | ||
**street** | ||
*(string) (required)* | ||
## Example | ||
```yaml | ||
waste_collection_schedule: | ||
sources: | ||
- name: tbv_velbert_de | ||
args: | ||
strasse: "Am Lindenkamp 33" | ||
|
||
``` | ||
|
||
## How to get the source arguments | ||
|
||
1. Go to your calendar at [TBV Velbert - Abfalltermine](https://www.tbv-velbert.de/abfall/abfallkalender-und-abfuhrtermine/abfallabfuhr-suche) | ||
2. Enter your street. | ||
3. Copy the exact values from the textboxes street in the source configuration. | ||
|
||
*IMPORTANT* - the string as strasse must match only 1 entry |
Oops, something went wrong.