mirror of
https://github.com/sascha-hemi/hacs_waste_collection_schedule.git
synced 2026-03-21 00:04:11 +01:00
add LK Neumarkt, Germany
This commit is contained in:
@@ -1047,6 +1047,7 @@ If your service provider is not listed, feel free to open a [source request issu
|
||||
- [Landkreis Main-Spessart](/doc/source/app_abfallplus_de.md) / Abfall+ App: abfallmsp
|
||||
- [Landkreis Mettmann (MyMuell App)](/doc/source/jumomind_de.md) / mymuell.de
|
||||
- [Landkreis Mühldorf a. Inn](/doc/source/awido_de.md) / lra-mue.de
|
||||
- [Landkreis Neumarkt](/doc/source/abfuhrplan_landkreis_neumarkt_de.md) / abfuhrplan-landkreis-neumarkt.de
|
||||
- [Landkreis Nordwestmecklenburg](/doc/source/geoport_nwm_de.md) / geoport-nwm.de
|
||||
- [Landkreis Northeim (unofficial)](/doc/ics/nerdbridge_de.md) / abfall.nerdbridge.de
|
||||
- [Landkreis Ostallgäu](/doc/source/abfall_io.md) / buerger-ostallgaeu.de
|
||||
|
||||
@@ -6607,6 +6607,12 @@
|
||||
},
|
||||
"id": "awido_de"
|
||||
},
|
||||
{
|
||||
"title": "Landkreis Neumarkt",
|
||||
"module": "abfuhrplan_landkreis_neumarkt_de",
|
||||
"default_params": {},
|
||||
"id": "abfuhrplan_landkreis_neumarkt_de"
|
||||
},
|
||||
{
|
||||
"title": "Landkreis Nordwestmecklenburg",
|
||||
"module": "geoport_nwm_de",
|
||||
|
||||
@@ -15591,6 +15591,28 @@
|
||||
"year_field": "Jahresfeld"
|
||||
},
|
||||
"data_description": {}
|
||||
},
|
||||
"args_abfuhrplan_landkreis_neumarkt_de": {
|
||||
"title": "Quelle konfigurieren",
|
||||
"description": "Konfiguriere deinen Service Provider. Mehr details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/abfuhrplan_landkreis_neumarkt_de.md",
|
||||
"data": {
|
||||
"calendar_title": "Kalender Titel",
|
||||
"city": "Stadt",
|
||||
"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_abfuhrplan_landkreis_neumarkt_de": {
|
||||
"title": "Quelle Neu Konfigurieren",
|
||||
"description": "Konfiguriere deinen Service Provider. Mehr details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/abfuhrplan_landkreis_neumarkt_de.md",
|
||||
"data": {
|
||||
"calendar_title": "Kalender Titel",
|
||||
"city": "Stadt",
|
||||
"street": "Straße"
|
||||
},
|
||||
"data_description": {}
|
||||
}
|
||||
},
|
||||
"error": {
|
||||
|
||||
@@ -15591,6 +15591,28 @@
|
||||
"year_field": "Year Field"
|
||||
},
|
||||
"data_description": {}
|
||||
},
|
||||
"args_abfuhrplan_landkreis_neumarkt_de": {
|
||||
"title": "Configure Source",
|
||||
"description": "Configure your service provider. More details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/abfuhrplan_landkreis_neumarkt_de.md.",
|
||||
"data": {
|
||||
"calendar_title": "Calendar Title",
|
||||
"city": "City",
|
||||
"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_abfuhrplan_landkreis_neumarkt_de": {
|
||||
"title": "Reconfigure Source",
|
||||
"description": "Configure your service provider. More details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/abfuhrplan_landkreis_neumarkt_de.md.",
|
||||
"data": {
|
||||
"calendar_title": "Calendar Title",
|
||||
"city": "City",
|
||||
"street": "Street"
|
||||
},
|
||||
"data_description": {}
|
||||
}
|
||||
},
|
||||
"error": {
|
||||
|
||||
@@ -15566,6 +15566,28 @@
|
||||
"year_field": "Year Field"
|
||||
},
|
||||
"data_description": {}
|
||||
},
|
||||
"args_abfuhrplan_landkreis_neumarkt_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/abfuhrplan_landkreis_neumarkt_de.md.",
|
||||
"data": {
|
||||
"calendar_title": "Nome Calendario",
|
||||
"city": "Città",
|
||||
"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_abfuhrplan_landkreis_neumarkt_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/abfuhrplan_landkreis_neumarkt_de.md.",
|
||||
"data": {
|
||||
"calendar_title": "Nome Calendario",
|
||||
"city": "Città",
|
||||
"street": "Strada"
|
||||
},
|
||||
"data_description": {}
|
||||
}
|
||||
},
|
||||
"error": {
|
||||
|
||||
@@ -0,0 +1,126 @@
|
||||
import requests
|
||||
from bs4 import BeautifulSoup
|
||||
from waste_collection_schedule import Collection
|
||||
from waste_collection_schedule.exceptions import SourceArgumentNotFoundWithSuggestions
|
||||
from waste_collection_schedule.service.ICS import ICS
|
||||
|
||||
TITLE = "Landkreis Neumarkt"
|
||||
DESCRIPTION = "Source for Landkreis Neumarkt."
|
||||
URL = "https://www.abfuhrplan-landkreis-neumarkt.de"
|
||||
TEST_CASES = {
|
||||
"dietfurt industriestrasse": {"city": "dietfurt", "street": "industriestrasse"},
|
||||
"Parsberg, Bogenmühle": {"city": "parsberg", "street": "bogenmuehle"},
|
||||
}
|
||||
|
||||
|
||||
ICON_MAP = {
|
||||
"Restmüll": "mdi:trash-can",
|
||||
"Papiertonne": "mdi:package-variant",
|
||||
"Gelber Sack": "mdi:recycle",
|
||||
}
|
||||
|
||||
|
||||
BASE_API_URL = "https://www.abfuhrplan-landkreis-neumarkt.de"
|
||||
DATA_ULR = BASE_API_URL + "/{city}/{street}"
|
||||
|
||||
|
||||
def _prepare_arg(arg: str) -> str:
|
||||
return (
|
||||
arg.lower()
|
||||
.strip()
|
||||
.replace(" ", "-")
|
||||
.replace("(", "")
|
||||
.replace(")", "")
|
||||
.replace("ä", "ae")
|
||||
.replace("ö", "oe")
|
||||
.replace("ü", "ue")
|
||||
.replace("ß", "ss")
|
||||
)
|
||||
|
||||
|
||||
class Source:
|
||||
def __init__(self, city: str, street: str):
|
||||
self._city: str = _prepare_arg(city)
|
||||
self._street: str = _prepare_arg(street)
|
||||
self._ics = ICS()
|
||||
|
||||
@staticmethod
|
||||
def _get_all_elements(url: str) -> list[str]:
|
||||
r = requests.get(url)
|
||||
r.raise_for_status()
|
||||
|
||||
soup = BeautifulSoup(r.text, "html.parser")
|
||||
items = soup.select("li.list-group-item")
|
||||
elements = []
|
||||
for item in items:
|
||||
a = item.select_one("a")
|
||||
if not a:
|
||||
continue
|
||||
href = a.get("href")
|
||||
if not isinstance(href, str):
|
||||
continue
|
||||
href_name = href.split("/")[-1]
|
||||
if href_name == _prepare_arg(item.text.lower().strip()):
|
||||
elements.append(item.text.strip())
|
||||
else:
|
||||
elements.append(href_name)
|
||||
return elements
|
||||
|
||||
@staticmethod
|
||||
def _get_all_cities() -> list[str]:
|
||||
return Source._get_all_elements(BASE_API_URL)
|
||||
|
||||
@staticmethod
|
||||
def _get_all_streets(city: str) -> list[str]:
|
||||
print(f"{BASE_API_URL}/{city}")
|
||||
try:
|
||||
return Source._get_all_elements(f"{BASE_API_URL}/{city}")
|
||||
except requests.exceptions.HTTPError as e:
|
||||
print("failed to get streets")
|
||||
print(e.response.status_code)
|
||||
if e.response.status_code == 404:
|
||||
cities = Source._get_all_elements(BASE_API_URL)
|
||||
raise SourceArgumentNotFoundWithSuggestions("city", city, cities)
|
||||
raise e
|
||||
|
||||
def fetch(self) -> list[Collection]:
|
||||
url = DATA_ULR.format(city=self._city, street=self._street)
|
||||
|
||||
# get json file
|
||||
r = requests.get(url)
|
||||
if r.status_code == 404:
|
||||
streets = Source._get_all_streets(self._city)
|
||||
raise SourceArgumentNotFoundWithSuggestions("street", self._street, streets)
|
||||
|
||||
r.raise_for_status()
|
||||
|
||||
soup = BeautifulSoup(r.text, "html.parser")
|
||||
form = soup.select_one('form[action="/getical"]')
|
||||
if not form:
|
||||
raise Exception("Form not found")
|
||||
|
||||
data: dict[str, str | int] = {}
|
||||
for input in form.select("input") + form.select("button"):
|
||||
name = input.get("name")
|
||||
value = input.get("value")
|
||||
if not isinstance(name, str):
|
||||
continue
|
||||
if not isinstance(value, str):
|
||||
continue
|
||||
data[name] = value
|
||||
|
||||
for selects in form.select("select"):
|
||||
name = selects.get("name")
|
||||
if not isinstance(name, str):
|
||||
continue
|
||||
data[name] = 0
|
||||
|
||||
r = requests.post(f"{BASE_API_URL}/getical", data=data)
|
||||
r.raise_for_status()
|
||||
|
||||
entries = []
|
||||
for date, bin_type in self._ics.convert(r.text):
|
||||
icon = ICON_MAP.get(bin_type) # Collection icon
|
||||
entries.append(Collection(date=date, t=bin_type, icon=icon))
|
||||
|
||||
return entries
|
||||
39
doc/source/abfuhrplan_landkreis_neumarkt_de.md
Normal file
39
doc/source/abfuhrplan_landkreis_neumarkt_de.md
Normal file
@@ -0,0 +1,39 @@
|
||||
# Landkreis Neumarkt
|
||||
|
||||
Support for schedules provided by [Landkreis Neumarkt](https://www.abfuhrplan-landkreis-neumarkt.de), serving Landkreis Neumarkt, Germany.
|
||||
|
||||
## Configuration via configuration.yaml
|
||||
|
||||
```yaml
|
||||
waste_collection_schedule:
|
||||
sources:
|
||||
- name: abfuhrplan_landkreis_neumarkt
|
||||
args:
|
||||
city: CITY (Gmeinde/Ort)
|
||||
street: STREET (Straße)
|
||||
|
||||
```
|
||||
|
||||
### Configuration Variables
|
||||
|
||||
**city**
|
||||
*(String) (required)*
|
||||
**street**
|
||||
*(String) (required)*
|
||||
|
||||
|
||||
## Example
|
||||
|
||||
```yaml
|
||||
waste_collection_schedule:
|
||||
sources:
|
||||
- name: abfuhrplan_landkreis_neumarkt
|
||||
args:
|
||||
city: dietfurt
|
||||
street: industriestrasse
|
||||
|
||||
```
|
||||
|
||||
## How to get the source argument
|
||||
|
||||
Find the parameter of your address using [https://www.abfuhrplan-landkreis-neumarkt.de](https://www.abfuhrplan-landkreis-neumarkt.de) and write them exactly like on the web page.
|
||||
Reference in New Issue
Block a user