Added a source for Eigenbetrieb Abfallwirtschaft Landkreis Spree-Neiße (#1925)

* Added source for Eigenbetrieb Abfallwirtschaft Landkreis Spree-Neiße.

* Updated the description for source for Eigenbetrieb Abfallwirtschaft Landkreis Spree-Neiße.

* Removed unused copy pasted code in source for Eigenbetrieb Abfallwirtschaft Landkreis Spree-Neiße.

* refactoring ifs + reformatting

---------

Co-authored-by: Silvio Mummert <testix@gmx.net>
Co-authored-by: 5ila5 <5ila5@users.noreply.github.com>
This commit is contained in:
homeassist24
2024-04-13 15:55:50 +02:00
committed by GitHub
parent fd9c013247
commit cde46d8eb6
4 changed files with 147 additions and 1 deletions

View File

@@ -662,6 +662,7 @@ Waste collection schedules in the following formats and countries are supported.
- [EGST Steinfurt](/doc/source/abfall_io.md) / egst.de
- [EGW Westmünsterland](/doc/source/abfallnavi_de.md) / egw.de
- [Eichsfeldwerke GmbH](/doc/source/hausmuell_info.md) / eichsfeldwerke.de
- [Eigenbetrieb Abfallwirtschaft Landkreis Spree-Neiße](/doc/source/eigenbetrieb_abfallwirtschaft_de.md) / eigenbetrieb-abfallwirtschaft.de
- [Eigenbetrieb Kommunalwirtschaftliche Dienstleistungen Suhl](/doc/source/hausmuell_info.md) / ebkds.de
- [EKM Mittelsachsen GmbH](/doc/ics/ekm_mittelsachsen_de.md) / ekm-mittelsachsen.de
- [Entsorgungs- und Wirtschaftsbetrieb Landau in der Pfalz](/doc/source/c_trace_de.md) / ew-landau.de

View File

@@ -0,0 +1,101 @@
import datetime
import requests
from bs4 import BeautifulSoup
from waste_collection_schedule import Collection # type: ignore[attr-defined]
from waste_collection_schedule.service.ICS import ICS
# URL, DESCRIPTION and TITLE of the website
TITLE = "Eigenbetrieb Abfallwirtschaft Landkreis Spree-Neiße"
DESCRIPTION = "Source for Eigenbetrieb Abfallwirtschaft Landkreis Spree-Neiße."
URL = "https://www.eigenbetrieb-abfallwirtschaft.de"
COUNTRY = "de"
TEST_CASES = {
"Forst (Lausitz), Rosenweg": {"city": "4", "street": "344"},
"Peitz, Am See": {"city": "8", "street": "1077"},
"Guben, Altsprucke": {"city": "5", "street": "410"},
"Spremberg, Gartenstrasse": {"city": 10, "street": 701},
}
ICON_MAP = {
"Restmüll": "mdi:trash-can",
"Biotonne": "mdi:leaf",
"Papiercontainer": "mdi:package-variant",
"Gelbe(r) Sack/Tonne": "mdi:recycle",
}
class Source:
def __init__(self, city: str, street: str):
self._city: str = city
self._street: str = street
self._ics = ICS()
def fetch(self):
# get the current year
now = datetime.datetime.now()
year = now.year
# build the urls and fetch the data ...
# for this year ...
url_this_year = (
f"{URL}/termine/abfuhrtermine/{year}/{self._city}/{self._street}.html"
)
entries = self.get_data(url_this_year)
# and in december for the next year
if now.month == 12:
try:
url_next_year = f"{URL}/termine/abfuhrtermine/{year +1 }/{self._city}/{self._street}.html"
entries += self.get_data(url_next_year)
except Exception:
pass
return entries
def get_data(self, url):
# download the site
response = requests.get(url)
# check if the request was successful
if response.status_code != 200:
raise Exception(
f"Error loading page {URL}, status code {response.status_code}."
)
# parse the response
soup = BeautifulSoup(response.text, "html.parser")
# check for an input element named 'ics'
input_element = soup.find("input", {"name": "ics"})
# check if the input element was found
if not input_element:
raise Exception("Didn't find the input named ics.")
# try to find the parent form
form = input_element.find_parent("form")
# check if the parent form was found
if not form:
raise Exception("Didn't find the ics request formular.")
# extract the formular inputs
form_data = {}
for input_tag in form.find_all("input"):
name = input_tag.get("name")
value = input_tag.get("value", "")
form_data[name] = value
# extract the url (convert the relative url to a complete one)
action_url = URL + form.get("action")
# send the formular to fetch the ics file
response = requests.post(action_url, data=form_data)
response.raise_for_status()
response.encoding = "utf-8"
# process the response
dates = self._ics.convert(response.text)
entries = []
for d in dates:
icon = ICON_MAP.get(d[1].split(" ")[0])
if icon is None:
icon = ICON_MAP.get(d[1])
entries.append(Collection(d[0], d[1], icon=icon))
return entries

View File

@@ -0,0 +1,44 @@
# ASPN
Support for schedules provided by [ASPN](https://www.eigenbetrieb-abfallwirtschaft.de/termine/abfuhrtermine.html)
1. Go to [ASPN](https://www.eigenbetrieb-abfallwirtschaft.de/termine/abfuhrtermine.html) and select your city and street.
2. The address of the browser window is changed by the website.
3. Use the ids in the address to configure your waste collection schedule.
**Example:**
- https://www.eigenbetrieb-abfallwirtschaft.de/termine/abfuhrtermine/2024/4/344.html
- for "Rosenweg" in "Forst (Lausitz)"
- **4** is the id of the city
- **344** is the id of the street
- the year will be entered automatically by the script
## Configuration via configuration.yaml
```yaml
waste_collection_schedule:
sources:
- name: eigenbetrieb_abfallwirtschaft_de
args:
city: CITY_ID
street: STREET_ID
```
### Configuration Variables
**city**
*(string) (required): The id of your city*
**street**
*(string) (required): The id of your street*
## Example
```yaml
waste_collection_schedule:
sources:
- name: eigenbetrieb_abfallwirtschaft_de
args:
city: "4"
street: "344"
```

File diff suppressed because one or more lines are too long