added source awb_emsland_de

This commit is contained in:
5ila5
2023-07-31 17:30:31 +02:00
parent 30d1644830
commit f5e7724040
4 changed files with 184 additions and 1 deletions

View File

@@ -271,6 +271,7 @@ Waste collection schedules in the following formats and countries are supported.
- [Abfallwirtschaft Landkreis Landsberg am Lech](/doc/source/abfall_io.md) / abfallberatung-landsberg.de
- [Abfallwirtschaft Landkreis Wolfenbüttel](/doc/source/alw_wf_de.md) / alw-wf.de
- [Abfallwirtschaft Neckar-Odenwald-Kreis](/doc/source/awn_de.md) / awn-online.de
- [Abfallwirtschaft Neckar-Odenwald-Kreis](/doc/source/awb_emsland_de.md) / awn-online.de
- [Abfallwirtschaft Nürnberger Land](/doc/source/nuernberger_land_de.md) / nuernberger-land.de
- [Abfallwirtschaft Ortenaukreis](/doc/source/abfall_io.md) / abfallwirtschaft-ortenaukreis.de
- [Abfallwirtschaft Pforzheim](/doc/source/abfallwirtschaft_pforzheim_de.md) / abfallwirtschaft-pforzheim.de

View File

@@ -0,0 +1,124 @@
# Nearly direct copy of source awn_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 = "Abfallwirtschaft Neckar-Odenwald-Kreis"
DESCRIPTION = "Source for AWN (Abfallwirtschaft Neckar-Odenwald-Kreis)."
URL = "https://www.awn-online.de"
TEST_CASES = {
"Andervenne Am Gallenberg": {
"city": "Andervenne",
"street": "Am Gallenberg",
"house_number": "1",
},
"Neubörger Aschendorfer Straße 1 A": {
"city": "Neubörger",
"street": "Aschendorfer Straße",
"house_number": 1,
"address_suffix": "A",
},
"Lähden Ahornweg 15": {
"city": "Lähden",
"street": "Ahornweg",
"house_number": 15,
},
}
SERVLET = "https://portal.awb-emsland.de/WasteManagementEmsland/WasteManagementServlet"
ICON_MAP = {
"Restabfallbehaelter": "mdi:trash-can",
"Papierbehaelter": "mdi:package-variant",
"Wertstoffbehaelter": "mdi:recycle",
"Bioabfallbehaelter": "mdi:leaf",
}
# 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.kd.emsland.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:
bin_type = d[1].strip()
entries.append(Collection(d[0], bin_type, icon=ICON_MAP.get(bin_type)))
return entries

View File

@@ -0,0 +1,58 @@
# 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
address_suffix: HNR_SUFFIX
```
### Configuration Variables
**city**
*(string) (required)*
**street**
*(string) (required)*
**house_number**
*(integer) (required)*
**address_suffix**
*(string) (optional) (default: "")*
## Example
```yaml
waste_collection_schedule:
sources:
- name: awb_emsland_de
args:
city: "Andervenne"
street: "Am Gallenberg"
house_number: 1
```
```yaml
waste_collection_schedule:
sources:
- name: awb_emsland_de
args:
city: Neubörger
street: Aschendorfer Straße
house_number: 1
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.awb-emsland.de/service/abfuhrkalender/>. 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 alphanumeric character "A" or a additional house number like "/1".

File diff suppressed because one or more lines are too long