Skip to content

Commit

Permalink
umweltverbaende_at now supports more complex calendar arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
5ila5 committed Apr 6, 2024
1 parent 3c53abd commit 74fc48c
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,13 @@
"Hollabrunn": {"district": "hollabrunn", "municipal": "Retz"},
"Horn": {"district": "horn", "municipal": "Japons"},
"Klosterneuburg": {"district": "klosterneuburg", "municipal": "Klosterneuburg"},
"Korneuburg": {"district": "korneuburg", "municipal": "Bisamberg"},
"Korneuburg": {
"district": "korneuburg",
"municipal": "Bisamberg",
"calendar": "Zone B",
"calendar_title_separator": ",",
"calendar_splitter": ":",
},
"Krems": {"district": "krems", "municipal": "Aggsbach"},
"Stadt Krems Old Version": {"district": "kremsstadt", "municipal": "Rehberg"},
"Stadt Krems New Version": {"district": "kremsstadt", "calendar": "Rehberg"},
Expand Down Expand Up @@ -190,7 +196,14 @@


class Source:
def __init__(self, district, municipal=None, calendar=None):
def __init__(
self,
district,
municipal=None,
calendar=None,
calendar_title_separator=":",
calendar_splitter=None,
):
self._district = district.lower()
self._municipal = municipal

Expand All @@ -201,6 +214,9 @@ def __init__(self, district, municipal=None, calendar=None):
else:
self._calendars = None

self.calendar_title_separator = calendar_title_separator
self.calendar_splitter = calendar_splitter

if (
district == "kremsstadt" and not calendar
): # Keep compatibility with old configs
Expand Down Expand Up @@ -263,8 +279,16 @@ def get_data(self, year):
txt = day.text.strip().split(" \u00a0")
if self._calendars: # Filter for calendar if there are multiple calendars
if any(cal.upper() in txt[2].upper() for cal in self._calendars):
txt[2] = txt[2].split(":")[-1].strip()
self.append_entry(entries, txt)
for entry_text in (
[txt[2]]
if self.calendar_splitter is None
else txt[2].split(self.calendar_splitter)
):
new_txt = txt.copy()
new_txt[2] = entry_text.split(self.calendar_title_separator)[
-1
].strip()
self.append_entry(entries, new_txt)
else: # Process all other municipals
self.append_entry(entries, txt)

Expand Down
29 changes: 28 additions & 1 deletion doc/source/umweltverbaende_at.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ waste_collection_schedule:
district: DISTRICT_ARG
municipal: MUNICIPAL
calendar: CALENDAR
calendar_title_separator: CALENDAR_TITLE_SEPERATOR
calendar_splitter: CALENDAR_SPLITTER
```
**district**
Expand All @@ -30,10 +32,22 @@ Is not needed for Stadt Krems you should provide a calendar for each Rayon.
For Stadt Krems, the district is divided into 12 Rayon, so supply your Rayon name for the municipal arg. For example: _Rehberg (Rayon 30)_ would be `Rehberg`, whereas _Innenstadt 2 (Rayon 200)_ would be `Innenstadt 2`

**calendar**
(string) (optional)
(string) (optional)

If you see multiple collection calendars for your municipal (different streets or Rayons), you can specify the calendar name here. The calendar name should be spelt as it appears on the Abholtermine page below `Kalenderansicht`.

**calendar_title_separator**
(string) (optional | default: ":")

rarely needed, only works if `calendar` is set. This is the character that separates the calendar title from the collection dates. Like `Tour 1: Restmüll` (`:` is the separator which is the default value) or `Bisamberg Zone B, Restmüll 14-tägig` (`,` is the separator). You can see the text, the integration will use, at the Abholtermine page below `Kalenderansicht`

**calendar_splitter**
(string) (optional)

rarely needed, only works if `calendar` is set. Only needed if multiple collections are shown in one line. This is the character that separates the collection times, that are listed in one line. Like `Bisamberg Zone B, Restmüll 14-tägig: Gelber Sack` (`:` is the separator) You can see the text, the integration will use, at the Abholtermine page below `Kalenderansicht`



## Examples

```yaml
Expand Down Expand Up @@ -86,6 +100,19 @@ waste_collection_schedule:
- "Biotonne"
```

*Advanced calendar options are needed*

```yaml
waste_collection_schedule:
sources:
- name: umweltverbaende_at
args:
district: "korneuburg" # Korneuburg
municipal: "Bisamberg" # Municipal
calendar: "Zone B" # Rayon
calendar_title_separator: ","
calendar_splitter: ":"
```

*Old Version*
```yaml
Expand Down

0 comments on commit 74fc48c

Please sign in to comment.