add landreis Rostock

This commit is contained in:
5ila5
2024-09-17 19:32:10 +02:00
committed by 5ila5
parent 9cef01c0f5
commit 97f800160f
8 changed files with 341 additions and 1 deletions

View File

@@ -1056,6 +1056,7 @@ If your service provider is not listed, feel free to open a [source request issu
- [Landkreis Reutlingen](/doc/source/abfall_io.md) / kreis-reutlingen.de - [Landkreis Reutlingen](/doc/source/abfall_io.md) / kreis-reutlingen.de
- [Landkreis Rhön Grabfeld](/doc/source/landkreis_rhoen_grabfeld.md) / abfallinfo-rhoen-grabfeld.de - [Landkreis Rhön Grabfeld](/doc/source/landkreis_rhoen_grabfeld.md) / abfallinfo-rhoen-grabfeld.de
- [Landkreis Rosenheim](/doc/source/awido_de.md) / abfall.landkreis-rosenheim.de - [Landkreis Rosenheim](/doc/source/awido_de.md) / abfall.landkreis-rosenheim.de
- [Landkreis Rostock](/doc/source/abfall_lro_de.md) / abfall-lro.de
- [Landkreis Rotenburg (Wümme)](/doc/source/abfall_io.md) / lk-awr.de - [Landkreis Rotenburg (Wümme)](/doc/source/abfall_io.md) / lk-awr.de
- [Landkreis Roth](/doc/source/awido_de.md) / landratsamt-roth.de - [Landkreis Roth](/doc/source/awido_de.md) / landratsamt-roth.de
- [Landkreis Roth](/doc/source/c_trace_de.md) / landratsamt-roth.de - [Landkreis Roth](/doc/source/c_trace_de.md) / landratsamt-roth.de

View File

@@ -6669,6 +6669,12 @@
}, },
"id": "awido_de" "id": "awido_de"
}, },
{
"title": "Landkreis Rostock",
"module": "abfall_lro_de",
"default_params": {},
"id": "abfall_lro_de"
},
{ {
"title": "Landkreis Rotenburg (W\u00fcmme)", "title": "Landkreis Rotenburg (W\u00fcmme)",
"module": "abfall_io", "module": "abfall_io",

View File

@@ -15484,6 +15484,45 @@
"year_field": "Jahresfeld" "year_field": "Jahresfeld"
}, },
"data_description": {} "data_description": {}
},
"args_abfall_lro_de": {
"title": "Quelle konfigurieren",
"description": "Konfiguriere deinen Service Provider. Mehr details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/abfall_lro_de.md",
"data": {
"calendar_title": "Kalender Titel",
"black_rhythm": "Schwarze Tonne Rythmus",
"black_seasonal": "Schwarze Tonne Saisonal",
"green_rhythm": "Gelbe Tonne Rythmus",
"green_seasonal": "Gelbe Tonne Saisonal",
"municipality": "Gemeinde"
},
"data_description": {
"calendar_title": "Ein lesbarerer oder benutzerfreundlicherer Name für den Müllkalender. Wenn nichts angegeben wird, wird der Name der Quelle verwendet.",
"black_rhythm": "Leerungsrythmus der schwarzen Tonne",
"black_seasonal": "Ankreuzen, wenn die schwarzen Tonnen nur saisonal geleert werden",
"green_rhythm": "Leerungsrythmus der grünen Tonne",
"green_seasonal": "Ankreuzen, wenn die Grünen Tonnen nur saisonal geleert werden",
"municipality": "Name der Gemeinde, sollte mit dem Namen auf https://www.abfall-lro.de/de/abfuhrtermine/ übereinstimmen (einschließlich Unterregion in Klammern)"
}
},
"reconfigure_abfall_lro_de": {
"title": "Quelle Neu Konfigurieren",
"description": "Konfiguriere deinen Service Provider. Mehr details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/abfall_lro_de.md",
"data": {
"calendar_title": "Kalender Titel",
"black_rhythm": "Schwarze Tonne Rythmus",
"black_seasonal": "Schwarze Tonne Saisonal",
"green_rhythm": "Gelbe Tonne Rythmus",
"green_seasonal": "Gelbe Tonne Saisonal",
"municipality": "Gemeinde"
},
"data_description": {
"black_rhythm": "Leerungsrythmus der schwarzen Tonne",
"black_seasonal": "Ankreuzen, wenn die schwarzen Tonnen nur saisonal geleert werden",
"green_rhythm": "Leerungsrythmus der grünen Tonne",
"green_seasonal": "Ankreuzen, wenn die Grünen Tonnen nur saisonal geleert werden",
"municipality": "Name der Gemeinde, sollte mit dem Namen auf https://www.abfall-lro.de/de/abfuhrtermine/ übereinstimmen (einschließlich Unterregion in Klammern)"
}
} }
}, },
"error": { "error": {

View File

@@ -15484,6 +15484,45 @@
"year_field": "Year Field" "year_field": "Year Field"
}, },
"data_description": {} "data_description": {}
},
"args_abfall_lro_de": {
"title": "Configure Source",
"description": "Configure your service provider. More details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/abfall_lro_de.md.",
"data": {
"calendar_title": "Calendar Title",
"black_rhythm": "Black Rhythm",
"black_seasonal": "Black Seasonal",
"green_rhythm": "Green Rhythm",
"green_seasonal": "Green Seasonal",
"municipality": "Municipality"
},
"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.",
"black_rhythm": "Rhythm of the black bin collection",
"black_seasonal": "Check if the black bins are only collected seasonally",
"green_rhythm": "Rhythm of the green bin collection",
"green_seasonal": "Check if the green bins are only collected seasonally",
"municipality": "Name of the municipality, should match the name shown https://www.abfall-lro.de/de/abfuhrtermine/ (including sub region in bracktes)"
}
},
"reconfigure_abfall_lro_de": {
"title": "Reconfigure Source",
"description": "Configure your service provider. More details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/abfall_lro_de.md.",
"data": {
"calendar_title": "Calendar Title",
"black_rhythm": "Black Rhythm",
"black_seasonal": "Black Seasonal",
"green_rhythm": "Green Rhythm",
"green_seasonal": "Green Seasonal",
"municipality": "Municipality"
},
"data_description": {
"black_rhythm": "Rhythm of the black bin collection",
"black_seasonal": "Check if the black bins are only collected seasonally",
"green_rhythm": "Rhythm of the green bin collection",
"green_seasonal": "Check if the green bins are only collected seasonally",
"municipality": "Name of the municipality, should match the name shown https://www.abfall-lro.de/de/abfuhrtermine/ (including sub region in bracktes)"
}
} }
}, },
"error": { "error": {

View File

@@ -15470,6 +15470,34 @@
"year_field": "Year Field" "year_field": "Year Field"
}, },
"data_description": {} "data_description": {}
},
"args_abfall_lro_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/abfall_lro_de.md.",
"data": {
"calendar_title": "Nome Calendario",
"black_rhythm": "Black Rhythm",
"black_seasonal": "Black Seasonal",
"green_rhythm": "Green Rhythm",
"green_seasonal": "Green Seasonal",
"municipality": "Municipality"
},
"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_abfall_lro_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/abfall_lro_de.md.",
"data": {
"calendar_title": "Nome Calendario",
"black_rhythm": "Black Rhythm",
"black_seasonal": "Black Seasonal",
"green_rhythm": "Green Rhythm",
"green_seasonal": "Green Seasonal",
"municipality": "Municipality"
},
"data_description": {}
} }
}, },
"error": { "error": {

View File

@@ -0,0 +1,175 @@
from datetime import datetime
from typing import Literal
import requests
from bs4 import BeautifulSoup, NavigableString, Tag
from waste_collection_schedule import Collection # type: ignore[attr-defined]
from waste_collection_schedule.exceptions import SourceArgumentNotFoundWithSuggestions
from waste_collection_schedule.service.ICS import ICS
TITLE = "Landkreis Rostock"
DESCRIPTION = "Source for Landkreis Rostock."
URL = "https://www.abfall-lro.de/"
TEST_CASES = {
"Alt Kätwin": {
"municipality": "Alt Kätwin",
"black_rhythm": "2w",
"green_rhythm": "4w",
},
"Altenhagen (Lohmen)": {
"municipality": "Altenhagen (Lohmen)",
"black_rhythm": "2w",
"green_rhythm": "2w",
},
"Qualitz": {
"municipality": "Qualitz",
"black_rhythm": "",
"green_rhythm": "2w",
"green_seasonal": True,
},
}
ICON_MAP = {
"Schwarze": "mdi:trash-can",
"Grüne": "mdi:leaf",
"Blaue": "mdi:package-variant",
"Gelbe": "mdi:recycle",
}
API_URL = "https://www.abfall-lro.de/de/abfuhrtermine/"
ICAL_URL = "https://www.abfall-lro.de/default-wGlobal/wGlobal/abfuhrtermine/ical.php"
RHYTHMS = Literal["2w", "4w", ""]
PARAM_TRANSLATIONS = {
"de": {
"municipality": "Gemeinde",
"black_rhythm": "Schwarze Tonne Rythmus",
"green_rhythm": "Gelbe Tonne Rythmus",
"black_seasonal": "Schwarze Tonne Saisonal",
"green_seasonal": "Gelbe Tonne Saisonal",
}
}
PARAM_DESCRIPTIONS = {
"en": {
"municipality": "Name of the municipality, should match the name shown https://www.abfall-lro.de/de/abfuhrtermine/ (including sub region in bracktes)",
"black_rhythm": "Rhythm of the black bin collection",
"green_rhythm": "Rhythm of the green bin collection",
"black_seasonal": "Check if the black bins are only collected seasonally",
"green_seasonal": "Check if the green bins are only collected seasonally",
},
"de": {
"municipality": "Name der Gemeinde, sollte mit dem Namen auf https://www.abfall-lro.de/de/abfuhrtermine/ übereinstimmen (einschließlich Unterregion in Klammern)",
"black_rhythm": "Leerungsrythmus der schwarzen Tonne",
"green_rhythm": "Leerungsrythmus der grünen Tonne",
"black_seasonal": "Ankreuzen, wenn die schwarzen Tonnen nur saisonal geleert werden",
"green_seasonal": "Ankreuzen, wenn die Grünen Tonnen nur saisonal geleert werden",
},
}
class Source:
def __init__(
self,
municipality: str,
black_rhythm: RHYTHMS,
green_rhythm: RHYTHMS,
black_seasonal: bool = False,
green_seasonal: bool = False,
) -> None:
self._municipality: str = municipality
self._ics = ICS(regex=r"Leerung (.*)")
self._letters: str | None = None
self._black_rhythm = black_rhythm
self._green_rhythm = green_rhythm
self._black_seasonal = black_seasonal
self._green_seasonal = green_seasonal
def fetch_letter(self) -> None:
r = requests.get(API_URL)
r.raise_for_status()
soup = BeautifulSoup(r.text, "html.parser")
links = soup.find_all("a")
relevant_links: list[Tag] = []
for link in links:
if (
isinstance(link, Tag)
and isinstance(href := link.get("href"), str)
and href.startswith("/default")
and href.endswith(".pdf")
):
relevant_links.append(link)
mun_link: str | None = None
municipalities = []
for link in relevant_links:
text = link.text.strip()
if isinstance(link.next_sibling, NavigableString):
text += " " + link.next_sibling.strip()
municipalities.append(text)
if self._municipality.lower().replace(" ", "").replace("(", "").replace(
")", ""
) == text.lower().replace(" ", "").replace("(", "").replace(")", ""):
mun_link = link.get("href")
break
if mun_link is None:
raise SourceArgumentNotFoundWithSuggestions(
"municipality", self._municipality, municipalities
)
self._letters = mun_link.split("/")[-1].split(".")[0]
def fetch(self) -> list[Collection]:
fresh_letter = False
if self._letters is None:
fresh_letter = True
self.fetch_letter()
try:
return self.get_collections_per_year()
except Exception:
if fresh_letter:
raise
return self.get_collections_per_year()
def get_collections_per_year(self) -> list[Collection]:
now = datetime.now()
year = now.year
collections = self.get_collections(year)
if now.month != 12:
return collections
try:
collections += self.get_collections(year + 1)
except Exception:
pass
return collections
def get_collections(self, year: int) -> list[Collection]:
args = {
"letters": self._letters,
"year": year,
"black": self._black_rhythm,
"green": self._green_rhythm,
"yellow": "y",
"blue": "y",
}
if self._black_seasonal:
args["bsaison"] = "y"
if self._green_seasonal:
args["gsaison"] = "y"
# get json file
r = requests.get(ICAL_URL, params=args)
r.raise_for_status()
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

View File

@@ -0,0 +1,52 @@
# Landkreis Rostock
Support for schedules provided by [Landkreis Rostock](https://www.abfall-lro.de/), serving Landkreis Rostock, Germany.
## Configuration via configuration.yaml
```yaml
waste_collection_schedule:
sources:
- name: abfall_lro_de
args:
municipality: MUNICIPALITY (Gemeinde)
black_rhythm: BLACK BIN RHYTHM
green_rhythm: GREEN BIN RHYTHM
black_seasonal: GREEN BIN SEASONAL (Optional)
green_seasonal: GREEN BIN SEASONAL (Optional)
```
### Configuration Variables
**municipality**
*(String) (required)*
**black_rhythm**
*(String) (required)* Rhythm of the black bin, Should be `2w`, `4w` or empty string ("")
**green_rhythm**
*(String) (required)* Rhythm of the green bin, Should be `2w`, `4w` or empty string ("")
**black_seasonal**
*(Boolean) (optional)* Weather black bins are only collected Seasonal, Should be `True` or `False`
**green_seasonal**
*(Boolean) (optional)* Weather green bins are only collected Seasonal, Should be `True` or `False`
## Example
```yaml
waste_collection_schedule:
sources:
- name: abfall_lro_de
args:
municipality: Alt Kätwin
black_rythm: 2w
green_rythm: 2w
black_seasonal: False
green_seasonal: False
```
## How to get the source argument
Find the parameter of your address using [https://www.abfall-lro.de/de/abfuhrtermine/](https://www.abfall-lro.de/de/abfuhrtermine/) and write them exactly like on the web page.

File diff suppressed because one or more lines are too long