Skip to content

Commit

Permalink
Merge pull request #815 from 5ila5/adding_zakb_de
Browse files Browse the repository at this point in the history
implemented zakb_de
  • Loading branch information
mampfes authored Mar 29, 2023
2 parents b1dca59 + aef0060 commit 374fb02
Show file tree
Hide file tree
Showing 4 changed files with 151 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ Waste collection schedules in the following formats and countries are supported.
- [Wolfsburger Abfallwirtschaft und Straßenreinigung](/doc/source/was_wolfsburg_de.md) / was-wolfsburg.de
- [WZV Kreis Segeberg](/doc/source/c_trace_de.md) / wzv.de
- [ZAW Darmstadt-Dieburg](/doc/source/zaw_online_de.md) / zaw-online.de
- [Zweckverband Abfallwirtschaft Kreis Bergstraße](/doc/source/zakb_de.md) / zakb.de
- [Zweckverband Abfallwirtschaft Saale-Orla](/doc/source/awido_de.md) / zaso-online.de
- [Zweckverband Abfallwirtschaft Schwalm-Eder-Kreis](/doc/source/zva_sek_de.md) / zva-sek.de
- [Zweckverband München-Südost](/doc/source/awido_de.md) / zvmso.de
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import requests
from waste_collection_schedule import Collection # type: ignore[attr-defined]
from waste_collection_schedule.service.ICS import ICS

TITLE = "Zweckverband Abfallwirtschaft Kreis Bergstraße"
DESCRIPTION = "Source for Zweckverband Abfallwirtschaft Kreis Bergstraße."
URL = "https://www.zakb.de"
TEST_CASES = {
"Abtsteinach, Am Hofböhl 1 ": {
"ort": "Abtsteinach",
"strasse": "Am Hofböhl",
"hnr": "1",
"hnr_zusatz": ""
},
"Gorxheimertal, Am Herrschaftswald 10": {
"ort": "Gorxheimertal",
"strasse": "Am Herrschaftswald",
"hnr": "10",
},
"Rimbach, Ahornweg 1 B": {
"ort": "Rimbach",
"strasse": "Ahornweg",
"hnr": "1",
"hnr_zusatz": "B"
},
"Zwingenberg, Diefenbachstraße 57": {
"ort": "Zwingenberg",
"strasse": "Diefenbachstraße",
"hnr": 57,
"hnr_zusatz": ""
},
}


ICON_MAP = {
"Restabfallbehaelter": "mdi:trash-can",
"Restabfallcontainer": "mdi:trash-can",
"Bioabfallbehaelter": "mdi:leaf",
"Papierbehaelter": "mdi:package-variant",
"Papiercontainer": "mdi:package-variant",
"Gelber Sack": "mdi:recycle",
"Gruensperrmuell": "mdi:forest",
}


API_URL = "https://www.zakb.de/online-service/abfallkalender/"


class Source:
def __init__(self, ort: str, strasse: str, hnr: str | int, hnr_zusatz: str = ""):
self._ort: str = ort.replace(" ", "+")
self._strasse: str = strasse.replace(" ", "+")
self._hnr: str = str(hnr)
self._hnr_zusatz: str = hnr_zusatz.replace(" ", "+")
self._ics = ICS()

def fetch(self):

# inizilize session
session = requests.Session()

# make request to get session cookie
r = session.get(API_URL)
r.raise_for_status()

args = {
"aos[Ort]": self._ort,
"aos[Strasse]": self._strasse,
"aos[Hausnummer]": self._hnr,
"aos[Hausnummerzusatz]": self._hnr_zusatz,
"aos[CheckBoxRestabfallbehaelter]": "on",
"aos[CheckBoxRestabfallcontainer]": "on",
"aos[CheckBoxBioabfallbehaelter]": "on",
"aos[CheckBoxPapierbehaelter]": "on",
"aos[CheckBoxPapiercontainer]": "on",
"aos[CheckBoxGruensperrmuell]": "on",
"aos[CheckBoxGelber+Sack]": "on",
"aos[CheckBoxDSD-Container]": "on",
"submitAction": "CITYCHANGED",
"pageName": "Lageadresse",
}

# make request to call CITYCHANGED
r = session.post(API_URL, data=args)
r.raise_for_status()

# make request to set data for session
args["submitAction"] = "nextPage"
r = session.post(API_URL, data=args)
r.raise_for_status()

# make request to get ical file
r = session.post(
API_URL, data={"submitAction": "filedownload_ICAL", "pageName": "Terminliste"})
r.raise_for_status()

dates = self._ics.convert(r.text)
entries = []
for d in dates:
entries.append(Collection(d[0], d[1].strip(), ICON_MAP.get(d[1].strip())))
return entries
47 changes: 47 additions & 0 deletions doc/source/zakb_de.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Zweckverband Abfallwirtschaft Kreis Bergstraße

Support for schedules provided by [Zweckverband Abfallwirtschaft Kreis Bergstraße](https://www.zakb.de), serving Kreis Bergstraße, Germany.

## Configuration via configuration.yaml

```yaml
waste_collection_schedule:
sources:
- name: zakb_de
args:
ort: ORT
strasse: STRAßE
hnr: HAUSNUMMER
hnr_zusatz: HAUSNUMMERZUSATZ
```
### Configuration Variables
**ort**
*(String) (required)*
**strasse**
*(String) (required)*
**hnr**
*(String | Integer) (required)*
**hnr_zusatz**
*(String) (optional)*
## Example
```yaml
waste_collection_schedule:
sources:
- name: zakb_de
args:
ort: Abtsteinach
strasse: Am Hofböhl
hnr: 1
hnr_zusatz:
```
## How to get the source argument
Find the parameter of your address using [https://www.zakb.de/online-service/abfallkalender/](https://www.zakb.de/online-service/abfallkalender/) and write them exactly like on the web page.
Loading

0 comments on commit 374fb02

Please sign in to comment.