Skip to content

Commit

Permalink
add Source for MZV Rotenburg Bebra
Browse files Browse the repository at this point in the history
  • Loading branch information
5ila5 committed Nov 28, 2024
1 parent 74e412a commit 1eba25a
Show file tree
Hide file tree
Showing 8 changed files with 258 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1165,6 +1165,7 @@ If your service provider is not listed, feel free to open a [source request issu
- [Minden](/doc/source/jumomind_de.md) / minden.de
- [Mossautal](/doc/source/reso_gmbh_de.md) / reso-gmbh.de
- [MZV Biedenkopf](/doc/source/buergerportal_de.md) / mzv-biedenkopf.de
- [MZV Rotenburg](/doc/source/mzv_rotenburg_bebra_de.md) / mzv-rotenburg-bebra.de
- [Mörfelden-Walldorf](/doc/ics/moerfelden_walldorf_de.md) / moerfelden-walldorf.de
- [Mühlheim am Main (MyMuell App)](/doc/source/jumomind_de.md) / mymuell.de
- [Müllabfuhr Deutschland](/doc/source/muellabfuhr_de.md) / portal.muellabfuhr-deutschland.de
Expand Down
6 changes: 6 additions & 0 deletions custom_components/waste_collection_schedule/sources.json
Original file line number Diff line number Diff line change
Expand Up @@ -7488,6 +7488,12 @@
},
"id": "buergerportal_de"
},
{
"title": "MZV Rotenburg",
"module": "mzv_rotenburg_bebra_de",
"default_params": {},
"id": "mzv_rotenburg_bebra_de"
},
{
"title": "M\u00f6rfelden-Walldorf",
"module": "ics",
Expand Down
31 changes: 31 additions & 0 deletions custom_components/waste_collection_schedule/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -7485,6 +7485,37 @@
},
"data_description": {}
},
"args_mzv_rotenburg_bebra_de": {
"title": "Quelle konfigurieren",
"description": "Konfiguriere deinen Service Provider. Mehr details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/mzv_rotenburg_bebra_de.md",
"data": {
"calendar_title": "Kalender Titel",
"city": "Ort",
"paper_route": "Papier Rute",
"yellow_route": "Gelbe Tonne Rute"
},
"data_description": {
"calendar_title": "Ein lesbarerer oder benutzerfreundlicherer Name für den Müllkalender. Wenn nichts angegeben wird, wird der Name der Quelle verwendet.",
"city": "Genau wie in der `ort` URL-Parameter des Links auf der Website: https://www.mzv-rotenburg-bebra.de//webapp.html. Z.B. `lisp`, `rot`, `bebra`, ...",
"paper_route": "Wird verwendet, wenn es mehrere Routen für die Papierabholung gibt. Z.B. hat 'Rotenburg - Kernstadt' Papierabholrouten `West` und `Ost`.",
"yellow_route": "Wird verwendet, wenn es mehrere Routen für die Gelbe Tonne gibt. Z.B. hat 'Rotenburg - Kernstadt' Gelbe Tonne Routen `1`,`2`,`3` und `4`."
}
},
"reconfigure_mzv_rotenburg_bebra_de": {
"title": "Quelle Neu Konfigurieren",
"description": "Konfiguriere deinen Service Provider. Mehr details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/mzv_rotenburg_bebra_de.md",
"data": {
"calendar_title": "Kalender Titel",
"city": "Ort",
"paper_route": "Papier Rute",
"yellow_route": "Gelbe Tonne Rute"
},
"data_description": {
"city": "Genau wie in der `ort` URL-Parameter des Links auf der Website: https://www.mzv-rotenburg-bebra.de//webapp.html. Z.B. `lisp`, `rot`, `bebra`, ...",
"paper_route": "Wird verwendet, wenn es mehrere Routen für die Papierabholung gibt. Z.B. hat 'Rotenburg - Kernstadt' Papierabholrouten `West` und `Ost`.",
"yellow_route": "Wird verwendet, wenn es mehrere Routen für die Gelbe Tonne gibt. Z.B. hat 'Rotenburg - Kernstadt' Gelbe Tonne Routen `1`,`2`,`3` und `4`."
}
},
"args_ics_moerfelden_walldorf_de": {
"title": "Quelle konfigurieren",
"description": "Konfiguriere deinen Service Provider. \n\n- Besuchen Sie https://abfallkalender.regioit.de/kalender-moerfelden-walldorf/index.jsp und wählen Sie Ihre Straße aus.\n- Klicken Sie auf `Herunterladen (ICS)` und wählen Sie `Keine Erinnerung`.\n- Einfacher Weg (Firefox):\n - Klicken Sie auf `Herunterladen (ICS)` um den Download zu starten.\n - Klicken Sie auf das Download Icon von Firefox und rechtsklick -> `Download-Link kopieren` auf die ics Datei.\n- Schwieriger Weg (Alle Browser):\n - Öffnen Sie die Entwicklerwerkzeuge Ihres Browsers (F12) und gehen Sie zum Netzwerk-Tab.\n - Klicken Sie auf `Herunterladen (ICS)` und suchen Sie nach dem Request, der zum Herunterladen der ics-Datei führt.\n - Kopieren Sie die URL des Requests.\n- Verwenden Sie diese URL als `url`-Parameter.\n- Ersetzen Sie das Jahr in der URL durch '{%Y}', damit es automatisch durch das aktuelle Jahr ersetzt wird.\n\n\nMehr details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/ics/moerfelden_walldorf_de.md",
Expand Down
31 changes: 31 additions & 0 deletions custom_components/waste_collection_schedule/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -7491,6 +7491,37 @@
},
"data_description": {}
},
"args_mzv_rotenburg_bebra_de": {
"title": "Configure Source",
"description": "Configure your service provider. More details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/mzv_rotenburg_bebra_de.md.",
"data": {
"calendar_title": "Calendar Title",
"city": "City",
"paper_route": "Paper Route",
"yellow_route": "Yellow Route"
},
"data_description": {
"calendar_title": "A more readable, or user-friendly, name for the waste calendar. If nothing is provided, the name returned by the source will be used.",
"city": "Should be spelled exactly like in the `ort` URL parameter of the link url shown on the website: https://www.mzv-rotenburg-bebra.de//webapp.html Like: `lisp`, `rot`, `bebra`, ...",
"paper_route": "Used if there are multiple routes for the paper collection. E.g 'Rotenburg - Kernstadt' has paper collection routes `West` and `Ost`.",
"yellow_route": "Used if there are multiple routes for the yellow bin collection. E.g 'Rotenburg - Kernstadt' has yellow bin collection routes `1`,`2`,`3` and `4`."
}
},
"reconfigure_mzv_rotenburg_bebra_de": {
"title": "Reconfigure Source",
"description": "Configure your service provider. More details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/mzv_rotenburg_bebra_de.md.",
"data": {
"calendar_title": "Calendar Title",
"city": "City",
"paper_route": "Paper Route",
"yellow_route": "Yellow Route"
},
"data_description": {
"city": "Should be spelled exactly like in the `ort` URL parameter of the link url shown on the website: https://www.mzv-rotenburg-bebra.de//webapp.html Like: `lisp`, `rot`, `bebra`, ...",
"paper_route": "Used if there are multiple routes for the paper collection. E.g 'Rotenburg - Kernstadt' has paper collection routes `West` and `Ost`.",
"yellow_route": "Used if there are multiple routes for the yellow bin collection. E.g 'Rotenburg - Kernstadt' has yellow bin collection routes `1`,`2`,`3` and `4`."
}
},
"args_ics_moerfelden_walldorf_de": {
"title": "Configure Source",
"description": "Configure your service provider. \n\n- Visit https://abfallkalender.regioit.de/kalender-moerfelden-walldorf/index.jsp and select your street. \n- Click on `Herunterladen (ICS)` and select `Keine Erinnerung`.\n- Easy way (firefox):\n - Click on `Herunterladen (ICS)` to start the download.\n - Click on the download icon of Firefox and right click -> `Copy Download Link` on the ics file.\n- Harder Way (All Browsers):\n - Open your browsers developer tools (F12) and go to the network tab.\n - Click on `Herunterladen (ICS)` and look for the request that is made to download the ics file.\n - Copy the URL of the request.\n- Use this URL as `url` parameter.\n- Replace the year in the URL with '{%Y}', so it will be automatically replaced by the current year.\n\n\nMore details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/ics/moerfelden_walldorf_de.md.",
Expand Down
24 changes: 24 additions & 0 deletions custom_components/waste_collection_schedule/translations/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -7474,6 +7474,30 @@
},
"data_description": {}
},
"args_mzv_rotenburg_bebra_de": {
"title": "Configurazione Sorgente",
"description": "Compila i campi per ottenere le informazioni sul tuo servizio di raccolta. Maggiori informazioni: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/mzv_rotenburg_bebra_de.md.",
"data": {
"calendar_title": "Nome Calendario",
"city": "Città",
"paper_route": "Paper Route",
"yellow_route": "Yellow Route"
},
"data_description": {
"calendar_title": "Puoi cambiare il nome del calendario della raccolta dei rifiuti, altrimenti di default verra' utilizzato il nome del tuo fornitore di servizi."
}
},
"reconfigure_mzv_rotenburg_bebra_de": {
"title": "Riconfigurazione Sorgente",
"description": "Compila i campi per ottenere le informazioni sul tuo servizio di raccolta. Per maggiori informazioni: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/mzv_rotenburg_bebra_de.md.",
"data": {
"calendar_title": "Nome Calendario",
"city": "Città",
"paper_route": "Paper Route",
"yellow_route": "Yellow Route"
},
"data_description": {}
},
"args_ics_moerfelden_walldorf_de": {
"title": "Configurazione Sorgente",
"description": "Compila i campi per ottenere le informazioni sul tuo servizio di raccolta. \n\n- Visit https://abfallkalender.regioit.de/kalender-moerfelden-walldorf/index.jsp and select your street. \n- Click on `Herunterladen (ICS)` and select `Keine Erinnerung`.\n- Easy way (firefox):\n - Click on `Herunterladen (ICS)` to start the download.\n - Click on the download icon of Firefox and right click -> `Copy Download Link` on the ics file.\n- Harder Way (All Browsers):\n - Open your browsers developer tools (F12) and go to the network tab.\n - Click on `Herunterladen (ICS)` and look for the request that is made to download the ics file.\n - Copy the URL of the request.\n- Use this URL as `url` parameter.\n- Replace the year in the URL with '{%Y}', so it will be automatically replaced by the current year.\n\n\nMaggiori informazioni: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/ics/moerfelden_walldorf_de.md.",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
import requests
from bs4 import BeautifulSoup
from waste_collection_schedule import Collection # type: ignore[attr-defined]
from waste_collection_schedule.exceptions import (
SourceArgumentNotFound,
SourceArgumentNotFoundWithSuggestions,
)
from waste_collection_schedule.service.ICS import ICS

TITLE = "MZV Rotenburg"
DESCRIPTION = "Source for MZV Rotenburg."
URL = "https://www.mzv-rotenburg-bebra.de"
TEST_CASES = {
# "Rotenburg an der Fulda 2 Ost": {
# "city": "rote",
# "yellow_route": "2",
# "paper_route": "Ost",
# },
"bullshit": {
"city": "asdf",
"yellow_route": "2",
"paper_route": "Ost",
},
}


ICON_MAP = {
"Trash": "mdi:trash-can",
"Glass": "mdi:bottle-soda",
"Bio": "mdi:leaf",
"Paper": "mdi:package-variant",
"Recycle": "mdi:recycle",
}

PARAM_TRANSLATIONS = {
"de": {
"city": "Ort",
"yellow_route": "Gelbe Tonne Rute",
"paper_route": "Papier Rute",
}
}

PARAM_DESCRIPTIONS = { # Optional dict to describe the arguments, will be shown in the GUI configuration below the respective input field
"en": {
"yellow_route": "Used if there are multiple routes for the yellow bin collection. E.g 'Rotenburg - Kernstadt' has yellow bin collection routes `1`,`2`,`3` and `4`.",
"paper_route": "Used if there are multiple routes for the paper collection. E.g 'Rotenburg - Kernstadt' has paper collection routes `West` and `Ost`.",
"city": "Should be spelled exactly like in the `ort` URL parameter of the link url shown on the website: https://www.mzv-rotenburg-bebra.de//webapp.html Like: `lisp`, `rot`, `bebra`, ...",
},
"de": {
"city": "Genau wie in der `ort` URL-Parameter des Links auf der Website: https://www.mzv-rotenburg-bebra.de//webapp.html. Z.B. `lisp`, `rot`, `bebra`, ...",
"yellow_route": "Wird verwendet, wenn es mehrere Routen für die Gelbe Tonne gibt. Z.B. hat 'Rotenburg - Kernstadt' Gelbe Tonne Routen `1`,`2`,`3` und `4`.",
"paper_route": "Wird verwendet, wenn es mehrere Routen für die Papierabholung gibt. Z.B. hat 'Rotenburg - Kernstadt' Papierabholrouten `West` und `Ost`.",
},
}


API_URL = "https://www.mzv-rotenburg-bebra.de/entsorgung.php"


class Source:
def __init__(
self, city: str, yellow_route: str | None = None, paper_route: str | None = None
):
self._city: str = city
self._yellow_route: str | None = yellow_route
self._paper_route: str | None = paper_route
self._ics = ICS(title_template="{{date.summary}}\n\t{{date.location}}")

def _get_possible_cities(self) -> list[str]:
r = requests.get(
"https://www.mzv-rotenburg-bebra.de//webapp.html",
headers={"User-Agent": "Mozilla/5.0"},
)
r.raise_for_status()

soup = BeautifulSoup(r.content, "html.parser")
links = soup.find_all(
lambda tag: tag
and tag.name == "a"
and tag.get("href")
and "entsorgung.php?ort=" in tag["href"]
)
return [link["href"].split("?ort=")[1] for link in links]

def fetch(self) -> list[Collection]:
args = {
"ort": self._city,
}
r = requests.get(API_URL, params=args, headers={"User-Agent": "Mozilla/5.0"})
r.raise_for_status()

try:
dates = self._ics.convert(r.text)
except ValueError:
try:
cities = self._get_possible_cities()
except Exception:
raise SourceArgumentNotFound(
"city",
self._city,
"make sure the city is spelled exactly like in the link of the website https://www.mzv-rotenburg-bebra.de//webapp.html",
)
raise SourceArgumentNotFoundWithSuggestions(
"city",
self._city,
cities,
)

entries = []

for d in dates:
bin_type, location = d[1].split("\n\t", 1)
bin_type = bin_type.removeprefix("Entsorgung").strip()
if bin_type.lower().replace(" ", "") == "gelbetonne" and self._yellow_route:
if self._yellow_route not in location:
continue
if bin_type.lower().replace(" ", "") == "papier" and self._paper_route:
if self._paper_route not in location:
continue
entries.append(Collection(d[0], bin_type, ICON_MAP.get(bin_type)))

return entries
42 changes: 42 additions & 0 deletions doc/source/mzv_rotenburg_bebra_de.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# MZV Rotenburg

Support for schedules provided by [MZV Rotenburg](https://www.mzv-rotenburg-bebra.de), serving Bebra, Ronshausen, Rotenburg an der Fulda, Germany.

## Configuration via configuration.yaml

```yaml
waste_collection_schedule:
sources:
- name: mzv_rotenburg_bebra_de
args:
city: CITY (Stadt/Ort)
yellow_route: "YELLOW ROUTE (Rutennummer für Gelbe Tonne)"
paper_route: PAPER ROUTE (Rute für Blaue Tonne)

```
### Configuration Variables
**city**
*(String) (required)*
Short form of you city. It should match the URL parameter of the ics link of your city here: <https://www.mzv-rotenburg-bebra.de//webapp.html>
**yellow_route**
*(String) (optional)*
Used if there are multiple routes for the yellow bin collection. E.g 'Rotenburg - Kernstadt' has yellow bin collection routes `1`,`2`,`3` and `4`.

**paper_route**
*(String) (optional)*
Used if there are multiple routes for the paper collection. E.g 'Rotenburg - Kernstadt' has paper collection routes `West` and `Ost`.

## Example

```yaml
waste_collection_schedule:
sources:
- name: mzv_rotenburg_bebra_de
args:
city: Rotenburg an der Fulda
yellow_route: "2"
paper_route: Ost
```
Loading

0 comments on commit 1eba25a

Please sign in to comment.