add source for AWBKoeln.de

This commit is contained in:
mampfes
2020-04-19 09:36:34 +02:00
parent 98c8e00027
commit feb756bf00
5 changed files with 137 additions and 0 deletions

View File

@@ -29,6 +29,7 @@ Currently the following service providers are supported:
- [Abfall_Kreis_Tuebingen.de](./doc/source/abfall_kreis_tuebingen_de.md)
- [AbfallNavi / RegioIT.de](./doc/source/regioit_de.md)
- [AbfallPlus.de / Abfall.IO](./doc/source/abfall_io.md)
- [AWBKoeln.de](./doc/source/awbkoeln_de.md)
- [Jumomind.de](./doc/source/jumomind_de.md)
## Configuration via configuration.yaml

View File

@@ -0,0 +1,41 @@
import requests
import json
import datetime
from collections import OrderedDict
from ..helpers import CollectionAppointment
DESCRIPTION = "Source for AWB Koeln."
URL = "https://www.awbkoeln.de"
TEST_CASES = OrderedDict([("Koeln", {"street_code": 2, "building_number": 50})])
class Source:
def __init__(self, street_code, building_number):
self._street_code = street_code
self._building_number = building_number
def fetch(self):
args = {
"street_code": self._street_code,
"building_number": self._building_number,
}
now = datetime.datetime.now()
args["start_year"] = now.year
args["start_month"] = now.month
args["end_year"] = now.year + 1
args["end_month"] = now.month
# get json file
r = requests.get(f"https://www.awbkoeln.de/api/calendar", params=args)
data = json.loads(r.text)
entries = []
for d in data["data"]:
date = datetime.date(year=d["year"], month=d["month"], day=d["day"])
entries.append(CollectionAppointment(date, d["type"]))
return entries

View File

@@ -0,0 +1,53 @@
#!/usr/bin/python3
import inquirer
import requests
import json
def main():
questions = [
inquirer.Text("street_name", message="Enter street name (partial)"),
inquirer.Text("building_number", message="Enter building number (partial)"),
]
answers = inquirer.prompt(questions)
args = answers
args["form"] = "json"
r = requests.get(f"https://www.awbkoeln.de/api/streets", params=args)
# "data":[{"street_name":"Bahnhofplatz","building_number":"5","building_number_plain":"5","building_number_addition":"","street_code":"4270",
# "district":"Gremberghoven","zipcode":"51149","district_code":"4","area_code":"7","user_street_name":"Bahnhofplatz","user_building_number":"1"}
data = json.loads(r.text)
if len(data["data"]) == 0:
print("no matching address found")
return
choices = []
for d in data["data"]:
value = {
"street_code": d["street_code"],
"building_number": d["building_number"],
}
choices.append(
(
f"{d['user_street_name']} {d['user_building_number']}, {d['zipcode']} Köln - {d['district']}",
value,
)
)
questions = [inquirer.List("data", choices=choices, message="Select address")]
answers = inquirer.prompt(questions)
print("Copy the following statements into your configuration.yaml:\n")
print("# waste_collection_schedule source configuration")
print("waste_collection_schedule:")
print(" sources:")
print(" - name: awbkoeln_de")
print(" args:")
print(f" street_code: {answers['data']['street_code']}")
print(f" building_number: {answers['data']['building_number']}")
if __name__ == "__main__":
main()

41
doc/source/awbkoeln_de.md Normal file
View File

@@ -0,0 +1,41 @@
# AWBKoeln.de
Add support for schedules provided by `AWBKoeln.de`.
## Configuration via configuration.yaml
```yaml
waste_collection_schedule:
sources:
- name: awbkoeln_de
args:
street_code: STREET_CODE
building_number: BUILDING_NUMBER
```
### Configuration Variables
**street_code**<br>
*(string) (required)*
**building_number**<br>
*(string) (required)*
## Example
```yaml
waste_collection_schedule:
sources:
- name: awbkoeln_de
args:
street_code: 4272
building_number: 10
```
## 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/package/wizard/awbkoeln_de.py](https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/custom_components/waste_collection_schedule/package/wizard/awbkoeln_de.py).
Just run this script from a shell and answer the questions.

View File

@@ -31,4 +31,5 @@ Currently the following service providers are supported:
- Abfall_Kreis_Tuebingen.de
- AbfallNavi / RegioIT.de
- AbfallPlus.de / Abfall.IO
- AWBKoeln.de
- Jumomind.de