mirror of
https://github.com/sascha-hemi/hacs_waste_collection_schedule.git
synced 2026-03-21 00:04:11 +01:00
Adding awlneuss de (#1738)
* add awlneuss_de * remove print statement * add the option to define a street_name * minor reformatting --------- Co-authored-by: 5ila5 <5ila5@users.noreply.github.com>
This commit is contained in:
@@ -600,6 +600,7 @@ Waste collection schedules in the following formats and countries are supported.
|
||||
- [AWIGO Abfallwirtschaft Landkreis Osnabrück GmbH](/doc/source/awigo_de.md) / awigo.de
|
||||
- [AWISTA Düsseldorf](/doc/source/muellmax_de.md) / awista.de
|
||||
- [Awista Starnberg](/doc/ics/awista_starnberg_de.md) / awista-starnberg.de
|
||||
- [AWL Neuss](/doc/source/awlneuss_de.md) / buergerportal.awl-neuss.de
|
||||
- [Bad Arolsen (MyMuell App)](/doc/source/jumomind_de.md) / mymuell.de
|
||||
- [Bad Homburg vdH](/doc/source/jumomind_de.md) / bad-homburg.de
|
||||
- [Bad Kissingen](/doc/source/app_abfallplus_de.md) / Abfall+ App: abfallappbk
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
import datetime
|
||||
import json
|
||||
|
||||
import requests
|
||||
from waste_collection_schedule import Collection # type: ignore[attr-defined]
|
||||
|
||||
TITLE = "AWL Neuss" # Title will show up in README.md and info.md
|
||||
DESCRIPTION = (
|
||||
"Source for Bürgerportal AWL Neuss waste collection." # Describe your source
|
||||
)
|
||||
URL = "https://buergerportal.awl-neuss.de/" # Insert url to service homepage. URL will show up in README.md and info.md
|
||||
TEST_CASES = { # Insert arguments for test cases to be used by test_sources.py script
|
||||
"Neuss, Theodor-Heuss-Platz 13": {"street_code": 8650, "building_number": 13},
|
||||
"Neuss, Niederstrasse 42": {"street_code": 6810, "building_number": 42},
|
||||
"Neuss, Bahnhofstrasse 67": {
|
||||
"street_name": "Bahnhofstrasse",
|
||||
"building_number": 67,
|
||||
},
|
||||
"Neuss, Bismarckstrasse 52": {
|
||||
"street_name": "Bismarckstrasse",
|
||||
"building_number": 52,
|
||||
},
|
||||
}
|
||||
|
||||
API_URL = "https://buergerportal.awl-neuss.de/api/v1/calendar"
|
||||
ICON_MAP = {
|
||||
"grau": "mdi:trash-can",
|
||||
"pink": "mdi:trash-can",
|
||||
"braun": "mdi:leaf",
|
||||
"blau": "mdi:package-variant",
|
||||
"gelb": "mdi:recycle",
|
||||
}
|
||||
|
||||
|
||||
class Source:
|
||||
def __init__(
|
||||
self,
|
||||
building_number: int,
|
||||
street_name: str | None = None,
|
||||
street_code: int | None = None,
|
||||
):
|
||||
self._street_name: str | None = street_name
|
||||
self._street_code: int | None = street_code
|
||||
self._building_number: int = building_number
|
||||
|
||||
if not self._street_name and not self._street_code:
|
||||
raise Exception("Please provide either street_name or street_code")
|
||||
|
||||
def fetch(self):
|
||||
# get street code if not set with street
|
||||
if self._street_code is None:
|
||||
t = requests.get(API_URL + "/townarea-streets")
|
||||
data_street = json.loads(t.text)
|
||||
|
||||
street_list = []
|
||||
for item in data_street:
|
||||
if item["strasseBezeichnung"] == self._street_name:
|
||||
street_list.append(item)
|
||||
|
||||
if len(street_list) == 0:
|
||||
raise Exception(
|
||||
"No street found! Please check the spelling of the street or use the street_code"
|
||||
)
|
||||
self._street_code = street_list[0]["strasseNummer"]
|
||||
|
||||
args = {
|
||||
"streetNum": self._street_code,
|
||||
"homeNummber": self._building_number,
|
||||
}
|
||||
|
||||
now = datetime.datetime.now()
|
||||
args["startMonth"] = now.year
|
||||
args["isTreeMonthRange"] = "true"
|
||||
args["isYear"] = "false"
|
||||
|
||||
# get json file
|
||||
r = requests.get(API_URL, params=args)
|
||||
|
||||
data = json.loads(r.text)
|
||||
|
||||
entries = [] # List that holds collection schedule
|
||||
for key, value in data.items():
|
||||
month_year: list[str] = key.split("-")
|
||||
month: int = int(month_year[0]) + 1
|
||||
year: int = int(month_year[1])
|
||||
|
||||
for dayValue, wastes in value.items():
|
||||
day: int = int(dayValue)
|
||||
for waste in wastes:
|
||||
entries.append(
|
||||
Collection(
|
||||
date=datetime.date(year, month, day), # Collection date
|
||||
t=waste, # Collection type
|
||||
icon=ICON_MAP.get(waste), # Collection icon
|
||||
)
|
||||
)
|
||||
|
||||
return entries
|
||||
56
doc/source/awlneuss_de.md
Normal file
56
doc/source/awlneuss_de.md
Normal file
@@ -0,0 +1,56 @@
|
||||
# Bürgerportal AWL Neuss
|
||||
|
||||
Support for schedules provided by [buergerportal.awl-neuss.de](https://buergerportal.awl-neuss.de).
|
||||
|
||||
## Configuration via configuration.yaml
|
||||
|
||||
```yaml
|
||||
waste_collection_schedule:
|
||||
sources:
|
||||
- name: awlneuss_de
|
||||
args:
|
||||
street_name: STREET_NAME
|
||||
street_code: STREET_CODE
|
||||
building_number: BUILDING_NUMBER
|
||||
```
|
||||
|
||||
### Configuration Variables
|
||||
|
||||
**street_name**
|
||||
*(string) (required)*
|
||||
|
||||
**building_number**
|
||||
*(int) (required)*
|
||||
|
||||
**street_code**
|
||||
*(int) (optional)*
|
||||
|
||||
## Example
|
||||
|
||||
```yaml
|
||||
waste_collection_schedule:
|
||||
sources:
|
||||
- name: awlneuss_de
|
||||
args:
|
||||
street_name: "Theodor-Heuss-Platz"
|
||||
building_number: 13
|
||||
```
|
||||
|
||||
```yaml
|
||||
waste_collection_schedule:
|
||||
sources:
|
||||
- name: awlneuss_de
|
||||
args:
|
||||
street_code: 8650
|
||||
building_number: 13
|
||||
```
|
||||
|
||||
## How to get the source arguments
|
||||
|
||||
### use the parameter street_name
|
||||
|
||||
Please go to the website [https://buergerportal.awl-neuss.de/calendar]([https://buergerportal.awl-neuss.de/calendar) and search for your street and enter it exactly as it appears in the textbox.
|
||||
|
||||
### use the parameter street_code
|
||||
|
||||
To obtain the street parameter, a GET request must be made against the URL [https://buergerportal.awl-neuss.de/api/v1/calendar/townarea-streets](https://buergerportal.awl-neuss.de/api/v1/calendar/townarea-streets). The street must be searched for in the response. The value "strasseNummer" must be specified as a parameter `street_code`, as well as the house number as `building_number`. If the `street_code` parameter is set the parameter `street` is optional.
|
||||
Reference in New Issue
Block a user