-
-
Notifications
You must be signed in to change notification settings - Fork 740
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fb306ed
commit 7329c16
Showing
5 changed files
with
188 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 128 additions & 0 deletions
128
...omponents/waste_collection_schedule/waste_collection_schedule/source/ahk_heidekreis_de.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
import json | ||
import logging | ||
from datetime import datetime, timedelta, timezone | ||
|
||
import requests | ||
from waste_collection_schedule import Collection # type: ignore[attr-defined] | ||
from waste_collection_schedule.service.ICS import ICS | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
TITLE = "AHK Heidekreis" | ||
DESCRIPTION = "Source for Abfallwirtschaft Heidekreis." | ||
URL = "https://www.ahk-heidekreis.de/" | ||
TEST_CASES = { | ||
"Munster - Wagnerstr. 10-18": { | ||
"city": "Munster", | ||
"postcode": "29633", | ||
"street": "Wagnerstr.", | ||
"house_number": "10-18", | ||
}, | ||
"Fallingbostel - Konrad-Zuse-Str. 4": { | ||
"city": "Fallingbostel/Bad Fallingbostel", | ||
"postcode": 29683, | ||
"street": "Konrad-Zuse-Str.", | ||
"house_number": 4, | ||
}, | ||
} | ||
|
||
|
||
class Source: | ||
def __init__(self, city, postcode, street, house_number): | ||
self._city = city | ||
self._postcode = str(postcode) | ||
self._street = street | ||
self._house_number = str(house_number) | ||
self._ics = ICS() | ||
|
||
def fetch(self): | ||
params = { | ||
"PartialName": self._street, | ||
} | ||
|
||
# get list of streets and house numbers | ||
r = requests.get( | ||
"https://ahkwebapi.heidekreis.de/api/QMasterData/QStreetByPartialName", | ||
params=params, | ||
) | ||
|
||
data = json.loads(r.text) | ||
if len(data) == 0: | ||
raise Exception(f"street not found: {self._street}") | ||
|
||
street_entry = next( | ||
( | ||
item | ||
for item in data | ||
if item["name"] == self._street | ||
and item["plz"] == self._postcode | ||
and item["place"] == self._city | ||
), | ||
None, | ||
) | ||
|
||
if street_entry is None: | ||
raise Exception(f"street not found: {self._street}") | ||
|
||
params = {"StreetId": street_entry["id"]} | ||
r = requests.get( | ||
"https://ahkwebapi.heidekreis.de/api/QMasterData/QHouseNrEkal", | ||
params=params, | ||
) | ||
r.raise_for_status() | ||
|
||
data = json.loads(r.text) | ||
if len(data) == 0: | ||
raise Exception(f"No house_number not found: {self._street}") | ||
|
||
house_number_entry = next( | ||
( | ||
item | ||
for item in data | ||
if f"{item["houseNr"]}{item["houseNrAdd"]}" == self._house_number | ||
), | ||
None, | ||
) | ||
|
||
if house_number_entry is None: | ||
raise Exception(f"house_number not found: {self._house_number}") | ||
|
||
# get ics file | ||
params = { | ||
"von": datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%S.%f")[:-3] | ||
+ "Z", | ||
"bis": (datetime.now(timezone.utc) + timedelta(days=365)).strftime( | ||
"%Y-%m-%dT%H:%M:%S.%f" | ||
)[:-3] | ||
+ "Z", | ||
"benachrichtigungVorJederAbholung": False, | ||
"abholbenachrichtigungTageVorher": 1, | ||
"abholbenachrichtigungUhrzeit": { | ||
"ticks": 28800000, | ||
"sekunden": 28800, | ||
"minuten": 480, | ||
"stunden": 8, | ||
}, | ||
"benachrichtigungNächsterKalender": False, | ||
"kalenderBenachrichtigungTageVorEnde": 3, | ||
"kalenderbenachrichtigungUhrzeit": { | ||
"ticks": 28800000, | ||
"sekunden": 28800, | ||
"minuten": 480, | ||
"stunden": 8, | ||
}, | ||
} | ||
headers = {"content-type": "application/json"} | ||
|
||
r = requests.post( | ||
f"https://ahkwebapi.heidekreis.de/api/object/{house_number_entry["idObject"]}/QDisposalScheduler/asIcal", | ||
data=json.dumps(params), | ||
headers=headers, | ||
) | ||
dates = self._ics.convert(r.text) | ||
|
||
entries = [] | ||
for d in dates: | ||
_LOGGER.info("%s - %s", d[0], d[1]) | ||
entries.append(Collection(d[0], d[1].removesuffix(", "))) | ||
return entries |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# AHK Heidekreis | ||
|
||
Support for schedules provided by [ahk-heidekreis.de](https://www.ahk-heidekreis.de/). | ||
|
||
## Configuration via configuration.yaml | ||
|
||
```yaml | ||
waste_collection_schedule: | ||
sources: | ||
- name: ahk_heidekreis_de | ||
args: | ||
city: CITY | ||
postcode: POSTCODE | ||
street: STREET | ||
house_number: HOUSE_NUMBER | ||
``` | ||
### Configuration Variables | ||
**city** | ||
_(string) (required)_ | ||
**postcode** | ||
_(string) (required)_ | ||
**street** | ||
_(string) (required)_ | ||
**house_number** | ||
_(string) (required)_ | ||
## Example | ||
```yaml | ||
waste_collection_schedule: | ||
sources: | ||
- name: ahk_heidekreis_de | ||
args: | ||
city: Munster | ||
postcode: 29633 | ||
street: Wagnerstr. | ||
house_number: "10-18" | ||
- name: ahk_heidekreis_de | ||
args: | ||
city: Fallingbostel/Bad Fallingbostel | ||
postcode: "29683" | ||
street: Konrad-Zuse-Str. | ||
house_number: "4" | ||
``` | ||
## How to get the source argument | ||
Find the parameter of your address using [https://www.ahk-heidekreis.de/fuer-privatkunden/abfuhrzeiten.html](https://www.ahk-heidekreis.de/fuer-privatkunden/abfuhrzeiten.html), click on "Entsorgungskalender", use the address lookup and write them exactly like on the web page. |