Skip to content

Commit

Permalink
add GFA Lüneburg, Germany
Browse files Browse the repository at this point in the history
  • Loading branch information
5ila5 committed Sep 27, 2024
1 parent 5ef8e82 commit aff0d1b
Show file tree
Hide file tree
Showing 8 changed files with 268 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -906,6 +906,7 @@ If your service provider is not listed, feel free to open a [source request issu
- [Gemeinde Roetgen](/doc/source/abfallnavi_de.md) / roetgen.de
- [Gemeinde Schutterwald](/doc/source/cmcitymedia_de.md) / cmcitymedia.de
- [Gemeinde Unterhaching](/doc/source/awido_de.md) / unterhaching.de
- [GFA Lüneburg](/doc/source/gfa_lueneburg_de.md) / gfa-lueneburg.de
- [Gipsprojekt](/doc/ics/gipsprojekt_de.md) / gipsprojekt.de
- [Großkrotzenburg (MyMuell App)](/doc/source/jumomind_de.md) / mymuell.de
- [GSAK APP / Krefeld](/doc/source/insert_it_de.md) / insert-it.de/BmsAbfallkalenderKrefeld
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 @@ -5508,6 +5508,12 @@
},
"id": "awido_de"
},
{
"title": "GFA L\u00fcneburg",
"module": "gfa_lueneburg_de",
"default_params": {},
"id": "gfa_lueneburg_de"
},
{
"title": "Gipsprojekt",
"module": "ics",
Expand Down
24 changes: 24 additions & 0 deletions custom_components/waste_collection_schedule/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -15724,6 +15724,30 @@
"street": "Straße"
},
"data_description": {}
},
"args_gfa_lueneburg_de": {
"title": "Quelle konfigurieren",
"description": "Konfiguriere deinen Service Provider. \n\nStellen Sie sicher, dass die Adresse genau der entspricht, die vom Website-Formular automatisch vervollständigt wird: https://www.gfa-lueneburg.de/service/abfuhrkalender.html\n\nMehr details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/gfa_lueneburg_de.md",
"data": {
"calendar_title": "Kalender Titel",
"city": "Ort",
"house_number": "Hausnummer",
"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_gfa_lueneburg_de": {
"title": "Quelle Neu Konfigurieren",
"description": "Konfiguriere deinen Service Provider. \n\nStellen Sie sicher, dass die Adresse genau der entspricht, die vom Website-Formular automatisch vervollständigt wird: https://www.gfa-lueneburg.de/service/abfuhrkalender.html\n\nMehr details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/gfa_lueneburg_de.md",
"data": {
"calendar_title": "Kalender Titel",
"city": "Ort",
"house_number": "Hausnummer",
"street": "Straße"
},
"data_description": {}
}
},
"error": {
Expand Down
24 changes: 24 additions & 0 deletions custom_components/waste_collection_schedule/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -15724,6 +15724,30 @@
"street": "Street"
},
"data_description": {}
},
"args_gfa_lueneburg_de": {
"title": "Configure Source",
"description": "Configure your service provider. \n\nMake sure that the address exactly matches the one auto-completed by the website form: https://www.gfa-lueneburg.de/service/abfuhrkalender.html\n\nMore details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/gfa_lueneburg_de.md.",
"data": {
"calendar_title": "Calendar Title",
"city": "City",
"house_number": "House Number",
"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_gfa_lueneburg_de": {
"title": "Reconfigure Source",
"description": "Configure your service provider. \n\nMake sure that the address exactly matches the one auto-completed by the website form: https://www.gfa-lueneburg.de/service/abfuhrkalender.html\n\nMore details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/gfa_lueneburg_de.md.",
"data": {
"calendar_title": "Calendar Title",
"city": "City",
"house_number": "House Number",
"street": "Street"
},
"data_description": {}
}
},
"error": {
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 @@ -15699,6 +15699,30 @@
"street": "Via/Piazza/Corso"
},
"data_description": {}
},
"args_gfa_lueneburg_de": {
"title": "Configurazione Sorgente",
"description": "Compila i campi per ottenere le informazioni sul tuo servizio di raccolta. \n\nMake sure that the address exactly matches the one auto-completed by the website form: https://www.gfa-lueneburg.de/service/abfuhrkalender.html\n\nMaggiori informazioni: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/gfa_lueneburg_de.md.",
"data": {
"calendar_title": "Nome Calendario",
"city": "Città",
"house_number": "Civico",
"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_gfa_lueneburg_de": {
"title": "Riconfigurazione Sorgente",
"description": "Compila i campi per ottenere le informazioni sul tuo servizio di raccolta. \n\nMake sure that the address exactly matches the one auto-completed by the website form: https://www.gfa-lueneburg.de/service/abfuhrkalender.html\n\nPer maggiori informazioni: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/gfa_lueneburg_de.md.",
"data": {
"calendar_title": "Nome Calendario",
"city": "Città",
"house_number": "Civico",
"street": "Strada"
},
"data_description": {}
}
},
"error": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
# Nearly direct copy of source awn_de, awb_emsland_de

from html.parser import HTMLParser

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

TITLE = "GFA Lüneburg"
DESCRIPTION = "Source for GFA Lüneburg."
URL = "https://www.gfa-lueneburg.de/"
TEST_CASES = {
"Andervenne Am Gallenberg": {
"city": "Dahlem",
"street": "Hauptstr.",
"house_number": 7,
},
"Wendish Evern Kückenbrook 5 A": {
"city": "Wendish Evern",
"street": "Kückenbrook",
"house_number": "5 A",
},
}
SERVLET = "https://portal.gfa-lueneburg.de:8443/WasteManagementLueneburg/WasteManagementServlet"

ICON_MAP = {
"Restabfallbehaelter": "mdi:trash-can",
"Restmuell": "mdi:trash-can",
"Papiertonne": "mdi:package-variant",
"Gelber Sack": "mdi:recycle",
"Gruenabfall": "mdi:leaf",
"Biotonne": "mdi:leaf",
"Sperrmuell Altmetall": "mdi:recycle",
}


HOW_TO_GET_ARGUMENTS_DESCRIPTION = { # Optional dictionary to describe how to get the arguments, will be shown in the GUI configuration form above the input fields, does not need to be translated in all languages
"en": "Make sure that the address exactly matches the one auto-completed by the website form: https://www.gfa-lueneburg.de/service/abfuhrkalender.html",
"de": "Stellen Sie sicher, dass die Adresse genau der entspricht, die vom Website-Formular automatisch vervollständigt wird: https://www.gfa-lueneburg.de/service/abfuhrkalender.html",
}


# Parser for HTML input (hidden) text
class HiddenInputParser(HTMLParser):
def __init__(self):
super().__init__()
self._args = {}

@property
def args(self):
return self._args

def handle_starttag(self, tag, attrs):
if tag == "input":
d = dict(attrs)
if str(d["type"]).lower() == "hidden":
self._args[d["name"]] = d["value"] if "value" in d else ""


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


class Source:
def __init__(self, city: str, street: str, house_number: int | str):
self._city = city
self._street = street
self._hnr = house_number
self._ics = ICS()

def fetch(self):
session = requests.session()

r = session.get(
SERVLET,
params={"SubmitAction": "wasteDisposalServices", "InFrameMode": "FALSE"},
)
r.raise_for_status()
r.encoding = "utf-8"
with open("test1.html", "w") as f:
f.write(r.text)

parser = HiddenInputParser()
parser.feed(r.text)

args = parser.args
args["Ort"] = self._city
args["Strasse"] = self._street
args["Hausnummer"] = str(self._hnr)
args["Method"] = "POST"
args["SubmitAction"] = "CITYCHANGED"
args["Focus"] = "Ort"
r = session.post(
SERVLET,
data=args,
)
r.raise_for_status()

args["SubmitAction"] = "forward"
r = session.post(
SERVLET,
data=args,
)
r.raise_for_status()

args[
"ApplicationName"
] = "com.athos.kd.lueneburg.WasteDisposalServicesBusinessCase"
args["SubmitAction"] = "filedownload_ICAL"
args["IsLastPage"] = "true"
args["Method"] = "POST"
args["PageName"] = "Terminliste"
del args["Ort"]
del args["Strasse"]
del args["Hausnummer"]
r = session.post(
SERVLET,
data=args,
)

r.raise_for_status()

dates = self._ics.convert(r.text)

entries = []
for d in dates:
bin_type = d[1].strip()
entries.append(Collection(d[0], bin_type, icon=ICON_MAP.get(bin_type)))

return entries
53 changes: 53 additions & 0 deletions doc/source/gfa_lueneburg_de.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Abfallwirtschaftsbetrieb Emsland

Support for schedules provided by [Emsland Abfallwirtschaftsbetrieb](https://www.awb-emsland.de/), Germany.

## Configuration via configuration.yaml

```yaml
waste_collection_schedule:
sources:
- name: awb_emsland_de
args:
city: CITY
street: STREET
house_number: HNR
```
### Configuration Variables
**city**
*(string) (required)*
**street**
*(string) (required)*
**house_number**
*(integer) (required)*
## Example
```yaml
waste_collection_schedule:
sources:
- name: awb_emsland_de
args:
city: "Dahlem"
street: "Hauptstr"
house_number: 7
```
```yaml
waste_collection_schedule:
sources:
- name: awb_emsland_de
args:
city: Wendish Evern
street: Kückenbrook
house_number: 5 A
```
## How to get the source arguments
These values are the location you want to query for. Make sure, the writing is exactly as it is on <https://www.gfa-lueneburg.de/service/abfuhrkalender.html>. Typos will result in an parsing error which is printed in the log.
Loading

0 comments on commit aff0d1b

Please sign in to comment.