Add support for AWN

This commit is contained in:
Timo S
2022-10-13 21:30:13 +02:00
parent 2c3c39928b
commit 3905fe0c74
3 changed files with 166 additions and 0 deletions

View File

@@ -85,6 +85,7 @@ Currently the following service providers are supported:
- [Abfallkalender Würzburg](./doc/source/wuerzburg_de.md)
- [Abfallwirtschaft Landkreis Harburg](./doc/source/aw_harburg_de.md)
- [Abfallwirtschaft Landkreis Wolfenbüttel](./doc/source/alw_wf_de.md)
- [Abfallwirtschaft Neckar-Odenwald-Kreis](./doc/source/awn_de.md)
- [Abfallwirtschaft Rendsburg](./doc/source/awr_de.md)
- [Abfallwirtschaft Stuttgart](./doc/source/stuttgart_de.md)
- [Abfallwirtschaft Südholstein](./doc/source/awsh_de.md)

View File

@@ -0,0 +1,117 @@
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 = "AWN"
DESCRIPTION = "Source for AWN (Abfallwirtschaft Neckar-Odenwald-Kreis)."
URL = "https://www.awn-online.de"
TEST_CASES = {
"Adelsheim": {
"city": "Adelsheim",
"street": "Badstr.",
"house_number": 1,
},
"Mosbach": {
"city": "Mosbach",
"street": "Hauptstr.",
"house_number": 53,
"address_suffix": "/1",
},
"Billigheim": {
"city": "Billigheim",
"street": "Marienhöhe",
"house_number": 5,
"address_suffix": "A",
},
}
SERVLET = (
"https://athos.awn-online.de/WasteManagementNeckarOdenwald/WasteManagementServlet"
)
# 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 ""
class Source:
def __init__(
self, city: str, street: str, house_number: int, address_suffix: str = ""
):
self._city = city
self._street = street
self._hnr = house_number
self._suffix = address_suffix
self._ics = ICS()
def fetch(self):
session = requests.session()
r = session.get(
SERVLET,
params={"SubmitAction": "wasteDisposalServices", "InFrameMode": "TRUE"},
)
r.raise_for_status()
r.encoding = "utf-8"
parser = HiddenInputParser()
parser.feed(r.text)
args = parser.args
args["Ort"] = self._city
args["Strasse"] = self._street
args["Hausnummer"] = str(self._hnr)
args["Hausnummerzusatz"] = self._suffix
args["SubmitAction"] = "CITYCHANGED"
r = session.post(
SERVLET,
data=args,
)
r.raise_for_status()
args["SubmitAction"] = "forward"
args["ContainerGewaehlt_1"] = "on"
args["ContainerGewaehlt_2"] = "on"
args["ContainerGewaehlt_3"] = "on"
args["ContainerGewaehlt_4"] = "on"
args["ContainerGewaehlt_5"] = "on"
args["ContainerGewaehlt_6"] = "on"
args["ContainerGewaehlt_7"] = "on"
args["ContainerGewaehlt_8"] = "on"
args["ContainerGewaehlt_9"] = "on"
args["ContainerGewaehlt_10"] = "on"
r = session.post(
SERVLET,
data=args,
)
r.raise_for_status()
args["ApplicationName"] = "com.athos.nl.mvc.abfterm.AbfuhrTerminModel"
args["SubmitAction"] = "filedownload_ICAL"
r = session.post(
SERVLET,
data=args,
)
r.raise_for_status()
dates = self._ics.convert(r.text)
entries = []
for d in dates:
entries.append(Collection(d[0], d[1]))
return entries

48
doc/source/awn_de.md Normal file
View File

@@ -0,0 +1,48 @@
# Abfallwirtschaft Neckar-Odenwald-Kreis (AWN)
Support for schedules provided by [Abfallwirtschaft Neckar-Odenwald-Kreis](https://www.awn-online.de/) located in Baden-Württemberg, Germany.
## Configuration via configuration.yaml
```yaml
waste_collection_schedule:
sources:
- name: awn_de
args:
city: CITY
street: STREET
house_number: HNR
address_suffix: HNR_SUFFIX
```
### Configuration Variables
**city**<br>
*(string) (required)*
**street**<br>
*(string) (required)*
**house_number**<br>
*(integer) (required)*
**address_suffix**<br>
*(string) (optional) (default: "")*
## Example
```yaml
waste_collection_schedule:
sources:
- name: awn_de
args:
city: "Billigheim"
street: "Marienhöhe"
house_number: 5
address_suffix: "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.awn-online.de/abfuhrtermine](https://www.awn-online.de/abfuhrtermine). Typos will result in an parsing error which is printed in the log. As `house_number` expects a numeric input, address suffixes have to be provided via the `address_suffix` argument.
`address_suffix` could be for example a alpha-numeric character "A" or a additional house number like "/1".