mirror of
https://github.com/sascha-hemi/hacs_waste_collection_schedule.git
synced 2026-03-21 04:06:03 +01:00
add source awsh.de
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -5,3 +5,5 @@ __pycache__
|
||||
.mypy_cache/
|
||||
venv/
|
||||
custom_components/waste_collection_schedule/waste_collection_schedule/test/secrets.yaml
|
||||
.DS_Store
|
||||
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
import requests
|
||||
from waste_collection_schedule import Collection # type: ignore[attr-defined]
|
||||
from waste_collection_schedule.service.ICS import ICS
|
||||
|
||||
TITLE = "AWSH"
|
||||
DESCRIPTION = "Source for Abfallwirtschaft Südstormarn"
|
||||
URL = "https://www.awsh.de"
|
||||
TEST_CASES = {
|
||||
"Reinbek": {"ortId": 560, "strId": 860, "waste_types": "R02-B02-D02-P04"},
|
||||
}
|
||||
|
||||
class Source:
|
||||
def __init__(self, ortId, strId, waste_types=[]):
|
||||
self.ortId = ortId
|
||||
self.strId = strId
|
||||
self.waste_types = waste_types
|
||||
self.ics = ICS()
|
||||
|
||||
def fetch(self):
|
||||
|
||||
_waste_types = "-".join(map(lambda x: str(x), self.waste_types))
|
||||
# get ics file
|
||||
r = requests.get(f"https://www.awsh.de/api_v2/collection_dates/1/ort/{self.ortId}/strasse/{self.strId}/hausnummern/0/abfallarten/{_waste_types}/kalender.ics")
|
||||
return self.convert(r.text)
|
||||
|
||||
def convert(self, data):
|
||||
dates = self.ics.convert(data)
|
||||
|
||||
entries = []
|
||||
for d in dates:
|
||||
entries.append(Collection(d[0], d[1]))
|
||||
return entries
|
||||
@@ -0,0 +1,93 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import inquirer
|
||||
import requests
|
||||
import sys
|
||||
import json
|
||||
|
||||
def get_cities():
|
||||
r = requests.get("https://www.awsh.de/api_v2/collection_dates/1/orte")
|
||||
return json.loads(r.text)
|
||||
|
||||
def get_strassen(ort):
|
||||
r = requests.get(f"https://www.awsh.de/api_v2/collection_dates/1/ort/{ort}/strassen")
|
||||
return json.loads(r.text)
|
||||
|
||||
def get_waste_types(ort):
|
||||
r = requests.get(f"https://www.awsh.de/api_v2/collection_dates/1/ort/{ort}/abfallarten")
|
||||
return json.loads(r.text)
|
||||
|
||||
def main():
|
||||
ortsnummer = None
|
||||
strassennummer = None
|
||||
abfallarten = []
|
||||
|
||||
cities = get_cities()
|
||||
choices = []
|
||||
for d in cities["orte"]:
|
||||
value = {
|
||||
"ortsnummer": d["ortsnummer"],
|
||||
"ortsbezeichnung": d["ortsbezeichnung"],
|
||||
"plz": d["plz"],
|
||||
}
|
||||
choices.append(
|
||||
(
|
||||
f"{d['plz']} {d['ortsbezeichnung']}",
|
||||
value,
|
||||
)
|
||||
)
|
||||
questions = [inquirer.List("city", choices=choices, message="Select City")]
|
||||
answers = inquirer.prompt(questions)
|
||||
ortsnummer = answers["city"]["ortsnummer"]
|
||||
strassen = get_strassen(ortsnummer)
|
||||
choices.clear()
|
||||
|
||||
for d in strassen["strassen"]:
|
||||
value = {
|
||||
"strassennummer": d["strassennummer"],
|
||||
"strassenbezeichnung": d["strassenbezeichnung"],
|
||||
}
|
||||
choices.append(
|
||||
(
|
||||
f"{d['strassennummer']} {d['strassenbezeichnung']}",
|
||||
value,
|
||||
)
|
||||
)
|
||||
|
||||
questions = [inquirer.List("address", choices=choices, message="Select address")]
|
||||
answers = inquirer.prompt(questions)
|
||||
strassennummer = answers["address"]["strassennummer"]
|
||||
waste_types = get_waste_types(ortsnummer)
|
||||
choices.clear()
|
||||
|
||||
for d in waste_types["abfallarten"]:
|
||||
value = {
|
||||
"bezeichnung": d["bezeichnung"],
|
||||
"zyklus": d["zyklus"],
|
||||
"id": d["id"],
|
||||
}
|
||||
choices.append(
|
||||
(
|
||||
f"{d['bezeichnung']} {d['zyklus']}",
|
||||
value,
|
||||
)
|
||||
)
|
||||
|
||||
questions = [inquirer.Checkbox("wastetypes", choices=choices, message="Select Types")]
|
||||
answers = inquirer.prompt(questions)
|
||||
for d in answers["wastetypes"]:
|
||||
abfallarten.append(d["id"])
|
||||
|
||||
print("Copy the following statements into your configuration.yaml:\n")
|
||||
print("# waste_collection_schedule source configuration")
|
||||
print("waste_collection_schedule:")
|
||||
print(" sources:")
|
||||
print(" - name: awsh")
|
||||
print(" args:")
|
||||
print(f" ortId: {ortsnummer}")
|
||||
print(f" strId: {strassennummer}")
|
||||
for d in abfallarten:
|
||||
print(f" waste_types: - {d}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
42
doc/source/awsh.md
Normal file
42
doc/source/awsh.md
Normal file
@@ -0,0 +1,42 @@
|
||||
# AWSH
|
||||
|
||||
Support for schedules provided by [AWSH](https://www.awsh.de)
|
||||
|
||||
## Configuration via configuration.yaml
|
||||
|
||||
```yaml
|
||||
waste_collection_schedule:
|
||||
sources:
|
||||
- name: awsh
|
||||
args:
|
||||
ortId: Ort ID
|
||||
strId: Strassen ID
|
||||
waste_types:
|
||||
- R..
|
||||
- D..
|
||||
- B..
|
||||
```
|
||||
|
||||
## Example
|
||||
|
||||
```yaml
|
||||
waste_collection_schedule:
|
||||
sources:
|
||||
- name: awsh
|
||||
args:
|
||||
ortId: 560
|
||||
strId: 860
|
||||
waste_types:
|
||||
- R02
|
||||
- B02
|
||||
- D02
|
||||
- P04
|
||||
```
|
||||
|
||||
## How to get the source arguments
|
||||
|
||||
There is a script with an interactive command line interface which generates the required source configuration:
|
||||
|
||||
[https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/custom_components/waste_collection_schedule/waste_collection_schedule/wizard/awsh.py](https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/custom_components/waste_collection_schedule/waste_collection_schedule/wizard/awsh.py).
|
||||
|
||||
Just run this script from a shell and answer the questions.
|
||||
Reference in New Issue
Block a user