add Rapperswil Bern

This commit is contained in:
5ila5
2024-09-06 12:34:24 +02:00
committed by 5ila5
parent 23d0cacb2f
commit ba988fa109
5 changed files with 75 additions and 1 deletions

View File

@@ -1484,6 +1484,7 @@ If your service provider is not listed, feel free to open a [source request issu
- [Nieder-/Oberscherli](/doc/source/koeniz_ch.md) / koeniz.citymobile.ch
- [Niederwangen](/doc/source/koeniz_ch.md) / koeniz.citymobile.ch
- [Oberwangen](/doc/source/koeniz_ch.md) / koeniz.citymobile.ch
- [Rapperswil](/doc/source/rapperswil_be_ch.md) / rapperswil-be.ch
- [Real Luzern](/doc/source/real_luzern_ch.md) / real-luzern.ch
- [Real Luzern](/doc/source/sammelkalender_ch.md) / realluzern.ch
- [Rehetobel](/doc/source/a_region_ch.md) / a-region.ch

View File

@@ -8124,6 +8124,11 @@
"municipality": "Oberwangen"
}
},
{
"title": "Rapperswil",
"module": "rapperswil_be_ch",
"default_params": {}
},
{
"title": "Real Luzern",
"module": "real_luzern_ch",

View File

@@ -0,0 +1,57 @@
import requests
from bs4 import BeautifulSoup
from waste_collection_schedule import Collection
from waste_collection_schedule.service.ICS import ICS
TITLE = "Rapperswil"
DESCRIPTION = "Source for Rapperswil."
URL = "https://www.rapperswil-be.ch/"
TEST_CASES: dict[str, dict[str, str]] = {
"Rapperswil": {},
}
ICON_MAP = {
"Hauskehricht": "mdi:trash-can",
"Grüngut": "mdi:leaf",
"Papier und Karton": "mdi:package-variant",
}
BASE_URL = "https://www.rapperswil-be.ch"
API_URL = f"{BASE_URL}/de/abfallwirtschaft/abfallkalender/"
class Source:
def __init__(self):
self._ics = ICS()
def fetch(self) -> list[Collection]:
# get json file
r = requests.get(API_URL)
r.raise_for_status()
soup = BeautifulSoup(r.text, "html.parser")
ical_div = soup.select_one("div#icalTermine")
if ical_div is None:
raise Exception("No icalTermine found")
ical_link_a = ical_div.select_one("a")
if ical_link_a is None:
raise Exception("No ical link found")
href = ical_link_a["href"]
if not isinstance(href, str):
raise Exception("No href found")
if href.startswith("/"):
href = BASE_URL + href
if not href.startswith("http"):
href = API_URL + href
r = requests.get(href)
dates = self._ics.convert(r.text.replace("X-WR-TIMEZONE','EUROPE/BERLIN:", ""))
entries = []
for d in dates:
entries.append(Collection(d[0], d[1], ICON_MAP.get(d[1])))
return entries

View File

@@ -0,0 +1,11 @@
# Rapperswil
Support for schedules provided by [Rapperswil](https://www.rapperswil-be.ch/), serving Rapperswil, Switzerland.
## Configuration via configuration.yaml
```yaml
waste_collection_schedule:
sources:
- name: rapperswil_be_ch
```

File diff suppressed because one or more lines are too long