-
-
Notifications
You must be signed in to change notification settings - Fork 640
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
268 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
135 changes: 135 additions & 0 deletions
135
...components/waste_collection_schedule/waste_collection_schedule/source/gfa_lueneburg_de.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
Oops, something went wrong.