add ceb_coburg_de

This commit is contained in:
5ila5
2024-08-17 14:03:31 +02:00
committed by 5ila5
parent 9369b8e1b6
commit 0dd4d96745
5 changed files with 121 additions and 1 deletions

View File

@@ -740,6 +740,7 @@ If your service provider is not listed, feel free to open a [source request issu
- [Chiemgau Recycling - Landkreis Rosenheim](/doc/source/chiemgau_recycling_lk_rosenheim.md) / chiemgau-recycling.de
- [City of Karlsruhe](/doc/source/karlsruhe_de.md) / karlsruhe.de
- [CM City Media - Müllkalender](/doc/source/cmcitymedia_de.md) / cmcitymedia.de
- [Coburg Entsorgungs- und Baubetrieb CEB](/doc/source/ceb_coburg_de.md) / ceb-coburg.de
- [Darmstadt (MyMuell App)](/doc/source/jumomind_de.md) / mymuell.de
- [Darmstadt-Dieburg (ZAW)](/doc/source/jumomind_de.md) / zaw-online.de
- [Delbrück](/doc/source/lobbe_app.md) / lobbe.app

View File

@@ -3680,6 +3680,11 @@
"module": "cmcitymedia_de",
"default_params": {}
},
{
"title": "Coburg Entsorgungs- und Baubetrieb CEB",
"module": "ceb_coburg_de",
"default_params": {}
},
{
"title": "Darmstadt (MyMuell App)",
"module": "jumomind_de",

View File

@@ -0,0 +1,80 @@
from datetime import datetime
import requests
from bs4 import BeautifulSoup
from waste_collection_schedule import Collection # type: ignore[attr-defined]
TITLE = "Coburg Entsorgungs- und Baubetrieb CEB"
DESCRIPTION = "Source for Coburg Entsorgungs- und Baubetrieb CEB."
URL = "https://www.ceb-coburg.de/"
TEST_CASES = {
"Kanalstraße (Seite HUK)": {"street": "Kanalstraße (Seite HUK)"},
"Plattenäcker": {"street": "Plattenäcker"},
}
ICON_MAP = {
"Schwarz": "mdi:trash-can",
"Grün": "mdi:package-variant",
"Gelb": "mdi:recycle",
}
API_URL = "https://ceb-coburg.de/04_Stadtreinigung-Abfall/Abfallentsorgung-Recycling/Abfallbehaelter/muellabfuhrkalenderv2.php"
STREETS_URL = "https://ceb-coburg.de/04_Stadtreinigung-Abfall/Abfallentsorgung-Recycling/Abfallbehaelter/muellabfuhr.php"
class Source:
def __init__(self, street: str):
self._street: str = street
def _get_all_supported_streets(self) -> list[str]:
r = requests.get(STREETS_URL)
r.raise_for_status()
soup = BeautifulSoup(r.text, "html.parser")
streets: list[str] = []
accordion = soup.select_one("div#accordion")
if not accordion:
return streets
for panel in accordion.select("div.panel-collapse"):
for street in panel.select("a"):
streets.append(street.get_text(strip=True))
return streets
def fetch(self) -> list[Collection]:
args = {"s": self._street}
r = requests.get(API_URL, params=args)
r.raise_for_status()
soup = BeautifulSoup(r.text, "html.parser")
tables = soup.select("table")
entries = []
for table in tables:
for tr in table.select("tr"):
tds = tr.select("td")
if len(tds) != 2:
continue
bin_type_tag = tds[0]
date_tag = tds[1]
date_string = date_tag.get_text(strip=True)
bin_type = bin_type_tag.get_text(strip=True)
date = datetime.strptime(date_string, "%d.%m.%Y").date()
icon = ICON_MAP.get(bin_type)
entries.append(Collection(date=date, t=bin_type, icon=icon))
if not entries:
try:
supported_streets = self._get_all_supported_streets()
except Exception as e:
raise Exception(
f"Could not find any collections for street '{self._street}' and failed to fetch supported streets: {e}"
)
raise Exception(
f"Could not find any collections for street '{self._street}'. Supported streets are: {supported_streets}"
)
return entries

View File

@@ -0,0 +1,34 @@
# Coburg Entsorgungs- und Baubetrieb CEB
Support for schedules provided by [Coburg Entsorgungs- und Baubetrieb CEB](https://www.ceb-coburg.de/), serving City of Coburg, Germany.
Landkreis Coburg is not supported by this source but by the [awido_de source](/doc/source/awido_de.md).
## Configuration via configuration.yaml
```yaml
waste_collection_schedule:
sources:
- name: ceb_coburg_de
args:
street: STREET NAME
```
### Configuration Variables
**street**
*(String) (required)*
## Example
```yaml
waste_collection_schedule:
sources:
- name: ceb_coburg_de
args:
street: Kanalstraße (Seite HUK)
```
## How to get the source argument
You can validate your parameter by looking for your street here: <https://ceb-coburg.de/04_Stadtreinigung-Abfall/Abfallentsorgung-Recycling/Abfallbehaelter/muellabfuhr.php>

File diff suppressed because one or more lines are too long