add abfall_havelland_de as dedicated source isntead of ics source

The ICS source did not work as the ICS file is generated when searching for the address
but not stored permanently and removed after a few days
This commit is contained in:
5ila5
2024-07-02 19:05:22 +02:00
committed by 5ila5
parent 0136703139
commit c477d3eb12
6 changed files with 101 additions and 33 deletions

View File

@@ -571,7 +571,7 @@ Waste collection schedules in the following formats and countries are supported.
- [Abfall Stuttgart](/doc/source/stuttgart_de.md) / service.stuttgart.de
- [Abfall-Wirtschafts-Verband Nordschwaben](/doc/source/awido_de.md) / awv-nordschwaben.de
- [Abfall.IO / AbfallPlus](/doc/source/abfall_io.md) / abfallplus.de
- [Abfallbehandlungsgesellschaft Havelland mbH (abh)](/doc/ics/abfall_havelland_de.md) / abfall-havelland.de
- [Abfallbehandlungsgesellschaft Havelland mbH (abh)](/doc/source/abfall_havelland_de.md) / abfall-havelland.de
- [Abfallbewirtschaftung Ostalbkreis](/doc/source/abfall_io.md) / goa-online.de
- [Abfallentsorgung Kreis Kassel](/doc/ics/abfall_kreis_kassel_de.md) / abfall-kreis-kassel.de
- [Abfallkalender Hattingen](/doc/source/insert_it_de.md) / insert-it.de/BmsAbfallkalenderHattingen

View File

@@ -0,0 +1,61 @@
# There was an ICS source but the ICS file was not stored permanently and would be removed after a few days.
import requests
from bs4 import BeautifulSoup, Tag
from waste_collection_schedule import Collection # type: ignore[attr-defined]
from waste_collection_schedule.service.ICS import ICS
TITLE = "Abfallbehandlungsgesellschaft Havelland mbH (abh)"
DESCRIPTION = "Source for Abfallbehandlungsgesellschaft Havelland mbH."
URL = "https://abfall-havelland.de/"
TEST_CASES = {
"Wustermark Drosselgasse": {
"ort": "Wustermark",
"strasse": "Drosselgasse",
},
"Milow Friedhofstr.": {"ort": "Milow", "strasse": "Friedhofstr."},
}
ICON_MAP = {
"mülltonne": "mdi:trash-can",
"bio-tonne": "mdi:leaf",
"papier": "mdi:package-variant",
"gelbe": "mdi:recycle",
}
API_URL = "https://www.abfall-havelland.de//groups/public/modules/ajax_tourenplan.php"
BASE_URL = "https://www.abfall-havelland.de/"
class Source:
def __init__(self, ort: str, strasse: str):
self._ort: str = ort
self._strasse: str = strasse
self._ics = ICS(split_at=", ")
def fetch(self) -> list[Collection]:
args = {"city": self._ort, "street": self._strasse}
# get json file
r = requests.get(API_URL, params=args)
r.raise_for_status()
soup = BeautifulSoup(r.text, "html.parser")
ics_link_tag = soup.find("a", id="ical")
if not isinstance(ics_link_tag, Tag):
raise Exception("No ics link found")
ics_link = ics_link_tag.attrs["onclick"].split("'")[1]
if not isinstance(ics_link, str):
raise Exception("No ics link found")
r = requests.get(BASE_URL + ics_link)
r.raise_for_status()
r.encoding = "utf-8"
dates = self._ics.convert(r.text)
entries = []
for d in dates:
bin_type = d[1].replace(" - Abholtermin", "")
entries.append(
Collection(d[0], bin_type, ICON_MAP.get(bin_type.split()[0].lower()))
)
return entries

View File

@@ -1,22 +0,0 @@
# Abfallbehandlungsgesellschaft Havelland mbH (abh)
Abfallbehandlungsgesellschaft Havelland mbH (abh) is supported by the generic [ICS](/doc/source/ics.md) source. For all available configuration options, please refer to the source description.
## How to get the configuration arguments
- Goto <https://www.abfall-havelland.de/index.php?page_id=543#> and select your location.
- Click on `Export der Kalenderdaten` to download the .ics file, then copy the download link of the downloaded file. If your browser does not support to directly copy the download url you can use the developer tools there you can find the path of the file in the onklick section of the a tag for the download button.
- Replace the `url` in the example configuration with this link.
## Examples
### Brieselang, Am Nest
```yaml
waste_collection_schedule:
sources:
- name: ics
args:
url: https://www.abfall-havelland.de/UserFiles/Files/Abfuhrtermine%20Am%20Nest%20Brieselang.ics
```

View File

@@ -1,9 +0,0 @@
title: Abfallbehandlungsgesellschaft Havelland mbH (abh)
url: https://www.abfall-havelland.de/
howto: |
- Goto <https://www.abfall-havelland.de/index.php?page_id=543#> and select your location.
- Click on `Export der Kalenderdaten` to download the .ics file, then copy the download link of the downloaded file. If your browser does not support to directly copy the download url you can use the developer tools there you can find the path of the file in the onklick section of the a tag for the download button.
- Replace the `url` in the example configuration with this link.
test_cases:
Brieselang, Am Nest:
url: "https://www.abfall-havelland.de/UserFiles/Files/Abfuhrtermine%20Am%20Nest%20Brieselang.ics"

View File

@@ -0,0 +1,39 @@
# Abfallbehandlungsgesellschaft Havelland mbH
Support for schedules provided by [Abfallbehandlungsgesellschaft Havelland mbH](https://abfall-havelland.de/), serving Havelland, Germany.
## Configuration via configuration.yaml
```yaml
waste_collection_schedule:
sources:
- name: abfall_havelland_de
args:
ort: ORT
strasse: STRAßE
```
### Configuration Variables
**ort**
*(String) (required)*
**strasse**
*(String) (required)*
## Example
```yaml
waste_collection_schedule:
sources:
- name: abfall_havelland_de
args:
ort: Wustermark
strasse: Drosselgasse
```
## How to get the source argument
Find the parameter of your address using [https://www.abfall-havelland.de/index.php?page_id=543](https://www.abfall-havelland.de/index.php?page_id=543) and write them exactly like on the web page.

View File

@@ -153,7 +153,6 @@ This source has been successfully tested with the following service providers:
- [Aballwirtschaft Ludwigslust-Parchim AöR](/doc/ics/alp_lup_de.md) / alp-lup.de
- [Abfall App](/doc/ics/abfall_app_net.md) / abfall-app.net
- [Abfall IO ICS Version](/doc/ics/abfall_io_ics.md) / abfallplus.de
- [Abfallbehandlungsgesellschaft Havelland mbH (abh)](/doc/ics/abfall_havelland_de.md) / abfall-havelland.de
- [Abfallentsorgung Kreis Kassel](/doc/ics/abfall_kreis_kassel_de.md) / abfall-kreis-kassel.de
- [Abfallwirtschaft Dithmarschen (AWD)](/doc/ics/awd_online_de.md) / awd-online.de
- [Abfallwirtschaft Enzkreis](/doc/ics/entsorgung_regional_de.md) / entsorgung-regional.de