Skip to content

Commit

Permalink
New Source: TBV Velbert, DE (#1347)
Browse files Browse the repository at this point in the history
* 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
ndt authored Oct 22, 2023
1 parent 13c5679 commit cbaae94
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,7 @@ Waste collection schedules in the following formats and countries are supported.
- [Städteservice Raunheim Rüsselsheim](/doc/source/staedteservice_de.md) / staedteservice.de
- [Südbrandenburgischer Abfallzweckverband](/doc/source/sbazv_de.md) / sbazv.de
- [TBR Remscheid](/doc/source/muellmax_de.md) / tbr-info.de
- [TBV Velbert](/doc/source/tbv_velbert_de.md) / tbv-velbert.de
- [Technischer Betriebsdienst Reutlingen](/doc/ics/tbr_reutlingen_de.md) / tbr-reutlingen.de
- [Tuttlingen](/doc/source/app_abfallplus_de.md) / Abfall+ App: abfallwecker
- [Tuttlingen](/doc/source/app_abfallplus_de.md) / Abfall+ App: unterallgaeu
Expand Down
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
37 changes: 37 additions & 0 deletions doc/source/tbv_velbert_de.md
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
Loading

0 comments on commit cbaae94

Please sign in to comment.