Skip to content

Commit

Permalink
add Landreis Verden, Germany
Browse files Browse the repository at this point in the history
  • Loading branch information
5ila5 committed Dec 26, 2024
1 parent 3df02fe commit 5c81813
Show file tree
Hide file tree
Showing 8 changed files with 304 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1147,6 +1147,7 @@ If your service provider is not listed, feel free to open a [source request issu
- [Landkreis Südliche Weinstraße](/doc/source/awido_de.md) / suedliche-weinstrasse.de
- [Landkreis Tirschenreuth](/doc/source/awido_de.md) / kreis-tir.de
- [Landkreis Tübingen](/doc/source/awido_de.md) / abfall-kreis-tuebingen.de
- [Landkreis Verden](/doc/source/landkreis_verden_de.md) / landkreis-verden.de
- [Landkreis Vogtland](/doc/ics/vogtlandkreis_de.md) / vogtlandkreis.de
- [Landkreis Weißenburg-Gunzenhausen](/doc/source/abfall_io.md) / landkreis-wug.de
- [Landkreis Wittenberg](/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 @@ -7338,6 +7338,12 @@
},
"id": "awido_de"
},
{
"title": "Landkreis Verden",
"module": "landkreis_verden_de",
"default_params": {},
"id": "landkreis_verden_de"
},
{
"title": "Landkreis Vogtland",
"module": "ics",
Expand Down
26 changes: 26 additions & 0 deletions custom_components/waste_collection_schedule/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -7422,6 +7422,32 @@
},
"data_description": {}
},
"args_landkreis_verden_de": {
"title": "Quelle konfigurieren",
"description": "Konfiguriere deinen Service Provider. Mehr details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/landkreis_verden_de.md",
"data": {
"calendar_title": "Kalender Titel",
"city": "Ort",
"house_number": "Hausnummer",
"house_number_addition": "Hausnummerzusatz",
"street": "Straße"
},
"data_description": {
"calendar_title": "Ein lesbarerer oder benutzerfreundlicherer Name für den Müllkalender. Wenn nichts angegeben wird, wird der Name der Quelle verwendet."
}
},
"reconfigure_landkreis_verden_de": {
"title": "Quelle Neu Konfigurieren",
"description": "Konfiguriere deinen Service Provider. Mehr details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/landkreis_verden_de.md",
"data": {
"calendar_title": "Kalender Titel",
"city": "Ort",
"house_number": "Hausnummer",
"house_number_addition": "Hausnummerzusatz",
"street": "Straße"
},
"data_description": {}
},
"args_ics_vogtlandkreis_de": {
"title": "Quelle konfigurieren",
"description": "Konfiguriere deinen Service Provider. \n\n- Go to https://vogtlandkreis.de/Bürgerservice-und-Verwaltung/Infos-und-Services/Abfallentsorgung/Abfuhrtermine and select your location. \n- Click on `URL ANZEIGEN` to get a ical link. If the button is broken use the `URL in Zwichenablage kopieren` button.\n- Replace the `url` in the example configuration with this link.\n\n\nMehr details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/ics/vogtlandkreis_de.md",
Expand Down
26 changes: 26 additions & 0 deletions custom_components/waste_collection_schedule/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -7434,6 +7434,32 @@
},
"data_description": {}
},
"args_landkreis_verden_de": {
"title": "Configure Source",
"description": "Configure your service provider. More details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/landkreis_verden_de.md.",
"data": {
"calendar_title": "Calendar Title",
"city": "City",
"house_number": "House Number",
"house_number_addition": "House Number Addition",
"street": "Street"
},
"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."
}
},
"reconfigure_landkreis_verden_de": {
"title": "Reconfigure Source",
"description": "Configure your service provider. More details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/landkreis_verden_de.md.",
"data": {
"calendar_title": "Calendar Title",
"city": "City",
"house_number": "House Number",
"house_number_addition": "House Number Addition",
"street": "Street"
},
"data_description": {}
},
"args_ics_vogtlandkreis_de": {
"title": "Configure Source",
"description": "Configure your service provider. \n\n- Go to https://vogtlandkreis.de/Bürgerservice-und-Verwaltung/Infos-und-Services/Abfallentsorgung/Abfuhrtermine and select your location. \n- Click on `URL ANZEIGEN` to get a ical link. If the button is broken use the `URL in Zwichenablage kopieren` button.\n- Replace the `url` in the example configuration with this link.\n\n\nMore details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/ics/vogtlandkreis_de.md.",
Expand Down
26 changes: 26 additions & 0 deletions custom_components/waste_collection_schedule/translations/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -7411,6 +7411,32 @@
},
"data_description": {}
},
"args_landkreis_verden_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/landkreis_verden_de.md.",
"data": {
"calendar_title": "Nome Calendario",
"city": "Città",
"house_number": "Civico",
"house_number_addition": "House Number Addition",
"street": "Strada"
},
"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_landkreis_verden_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/landkreis_verden_de.md.",
"data": {
"calendar_title": "Nome Calendario",
"city": "Città",
"house_number": "Civico",
"house_number_addition": "House Number Addition",
"street": "Strada"
},
"data_description": {}
},
"args_ics_vogtlandkreis_de": {
"title": "Configurazione Sorgente",
"description": "Compila i campi per ottenere le informazioni sul tuo servizio di raccolta. \n\n- Go to https://vogtlandkreis.de/Bürgerservice-und-Verwaltung/Infos-und-Services/Abfallentsorgung/Abfuhrtermine and select your location. \n- Click on `URL ANZEIGEN` to get a ical link. If the button is broken use the `URL in Zwichenablage kopieren` button.\n- Replace the `url` in the example configuration with this link.\n\n\nMaggiori informazioni: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/ics/vogtlandkreis_de.md.",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
from datetime import datetime

import requests
from waste_collection_schedule import Collection # type: ignore[attr-defined]
from waste_collection_schedule.service.ICS import ICS

TITLE = "Landkreis Verden"
DESCRIPTION = "Source for Landkreis Verden waste collection."
URL = "https://www.landkreis-verden.de/"
TEST_CASES = {
"Achim": {"city": "Achim", "street": "Am Schießstand", "house_number": 10},
"Blender": {
"city": "Blender",
"street": "Buchenweg",
"house_number": "8",
"house_number_addition": "a",
},
"Riede": {"city": "Riede", "street": "An der Reihe", "house_number": 11},
}

API_URL = "https://lkv.landkreis-verden.de/WasteManagementVerden/WasteManagementServlet"

HEADERS = {
"User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64)",
}

ICON_MAP = {
"Gelber": "mdi:recycle",
"Restabfallbehaelter": "mdi:trash-can",
"Papierbehaelter": "mdi:newspaper",
"Kompostbehaelter": "mdi:leaf",
"Weihnachtsbaum": "mdi:pine-tree",
}

PARAM_TRANSLATIONS = {
"de": {
"city": "Ort",
"street": "Straße",
"house_number": "Hausnummer",
"house_number_addition": "Hausnummerzusatz",
},
}


class Source:
def __init__(
self,
city: str,
street: str,
house_number: int | str,
house_number_addition: str | None = None,
) -> None:
self.city: str = city
self.street: str = street
self.house_number: str | int = house_number
self.house_number_addition: str = (
house_number_addition if house_number_addition else ""
)
self._ics = ICS()

def fetch(self) -> list[Collection]:
now = datetime.now()
year = now.year
entries = self.get_collection(year)
if now.month == 12:
entries += self.get_collection(year + 1)
return entries

def get_collection(self, year: int) -> list[Collection]:
# Use a session to keep cookies
session = requests.Session()

payload: dict[str, str | int] = {
"SubmitAction": "wasteDisposalServices",
"ApplicationName": "com.athos.nl.mvc.abfterm.AbfuhrTerminModel",
}
r = session.get(API_URL, headers=HEADERS, params=payload)
r.raise_for_status()

payload = {
"ApplicationName": "com.athos.nl.mvc.abfterm.CheckAbfuhrTermineParameterBusinessCase",
"SubmitAction": "CITYCHANGED",
"Ort": self.city,
"Strasse": "",
"Hausnummer": "",
"Hausnummerzusatz": "",
"Zeitraum": f"Jahresübersicht {year}",
}
r = session.post(API_URL, headers=HEADERS, data=payload)
r.raise_for_status()

payload = {
"ApplicationName": "com.athos.nl.mvc.abfterm.CheckAbfuhrTermineParameterBusinessCase",
"SubmitAction": "STREETCHANGED",
"Ort": self.city,
"Strasse": self.street,
"Hausnummer": "",
}
r = session.post(API_URL, headers=HEADERS, data=payload)
r.raise_for_status()

payload = {
"ApplicationName": "com.athos.nl.mvc.abfterm.CheckAbfuhrTermineParameterBusinessCase",
"ContainerGewaehltR": "on",
"ContainerGewaehlt4": "on",
"ContainerGewaehltK": "on",
"ContainerGewaehltP": "on",
"ContainerGewaehltG": "on",
"ContainerGewaehltW": "on",
"ContainerGewaehltB": "on",
"SubmitAction": "forward",
"Ort": self.city,
"Strasse": self.street,
"Hausnummer": self.house_number,
"Hausnummerzusatz": self.house_number_addition,
"Zeitraum": f"Jahresübersicht {year}",
}
r = session.post(API_URL, headers=HEADERS, data=payload)

r.raise_for_status()

payload = {
"ApplicationName": "com.athos.nl.mvc.abfterm.CheckAbfuhrTermineParameterBusinessCase",
"ContainerGewaehltR": "on",
"ContainerGewaehlt4": "on",
"ContainerGewaehltK": "on",
"ContainerGewaehltP": "on",
"ContainerGewaehltG": "on",
"ContainerGewaehltW": "on",
"ContainerGewaehltB": "on",
"SubmitAction": "forward",
"Ort": self.city,
"Strasse": self.street,
"Hausnummernwahl": str(self.house_number) + self.house_number_addition,
"Zeitraum": f"Jahresübersicht {year}",
}
r = session.post(API_URL, headers=HEADERS, data=payload)
r.raise_for_status()

payload = {
"ApplicationName": "com.athos.nl.mvc.abfterm.AbfuhrTerminModel",
"ContainerGewaehltR": "on",
"ContainerGewaehlt4": "on",
"ContainerGewaehltK": "on",
"ContainerGewaehltP": "on",
"ContainerGewaehltG": "on",
"ContainerGewaehltW": "on",
"ContainerGewaehltB": "on",
"ICalErinnerung": "keine Erinnerung",
"ICalZeit": "06:00 Uhr",
"SubmitAction": "filedownload_ICAL",
}
r = session.post(API_URL, headers=HEADERS, data=payload)
r.raise_for_status()

# Parse ics file
dates = self._ics.convert(r.text)

entries = []
for d in dates:
entries.append(Collection(d[0], d[1], ICON_MAP.get(d[1].split()[0])))
return entries
56 changes: 56 additions & 0 deletions doc/source/landkreis_verden_de.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Landkreis Verden

Support for schedules provided by [Landkreis Verden](https://landkreis-verden.de/), Germany.

## Configuration via configuration.yaml

```yaml
waste_collection_schedule:
sources:
- name: landkreis_verden_de
args:
city: CITY
street: STREET
house_number: HOUSE_NUMBER
```
### Configuration Variables
**city**
*(string) (required)*
**street**
*(string) (required)*
**house_number**
*(string | number) (required)*
**house_number_addition**
*(string) (optional)*
## Example
```yaml
waste_collection_schedule:
sources:
- name: landkreis_verden_de
args:
city: Achim
street: Am Schießstand
house_number: 10
```
```yaml
waste_collection_schedule:
sources:
- name: landkreis_verden_de
args:
city: Blender
street: Buchenweg
house_number: 8
house_number_addition: a
```
## How to get the source arguments
Go to <https://lkv.landkreis-verden.de/WasteManagementVerden/WasteManagementServlet/>, to get the correct values for the three address arguments.
Loading

0 comments on commit 5c81813

Please sign in to comment.