-
-
Notifications
You must be signed in to change notification settings - Fork 766
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
133 additions
and
0 deletions.
There are no files selected for viewing
93 changes: 93 additions & 0 deletions
93
...omponents/waste_collection_schedule/waste_collection_schedule/source/dillingen_saar_de.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import datetime | ||
import requests | ||
from waste_collection_schedule import Collection | ||
from waste_collection_schedule.service.ICS import ICS | ||
from urllib.parse import quote | ||
from datetime import datetime | ||
|
||
|
||
|
||
TITLE = "Dillingen Saar" # Title will show up in README.md and info.md | ||
DESCRIPTION = "Source script for waste collection Dillingen Saar" # Describe your source | ||
URL = "https://www.dillingen-saar.de/" # Insert url to service homepage. URL will show up in README.md and info.md | ||
TEST_CASES = { # Insert arguments for test cases to be used by test_sources.py script | ||
"Am Fischerberg": {"street": "Am Fischerberg"}, #https://service-dillingen-saar.fbo.de/date/Am%20Fischerberg/2023-01-01/+1%20year/?format=ics&type=rm,gs,bio,pa | ||
"Odilienplatz": {"street": "Odilienplatz"}, #https://service-dillingen-saar.fbo.de/date/Odilienplatz/2023-01-01/+1%20year/?format=ics&type=rm,gs,bio,pa | ||
"Lilienstraße": {"street": "Lilienstraße"}, #https://service-dillingen-saar.fbo.de/date/Lilienstra%C3%9Fe/2023-01-01/+1%20year/?format=ics&type=rm,gs,bio,pa | ||
"Joseph-Roederer-Straße": {"street": "Joseph-Roederer-Straße"} #https://service-dillingen-saar.fbo.de/date/Joseph-Roederer-Stra%C3%9Fe/2023-01-01/+1%20year/?format=ics&type=rm,gs,bio,pa | ||
} | ||
|
||
API_URL = "https://service-dillingen-saar.fbo.de/date/" | ||
REMINDER_DAY = ( | ||
"0" # The calendar event should be on the same day as the waste collection | ||
) | ||
REMINDER_TIME = "0600" # The calendar event should start on any hour of the correct day, so this does not matter much | ||
ICON_MAP = { | ||
"Altpapier": "mdi:package-variant", | ||
"Restmüll": "mdi:trash-can", | ||
"Gelber Sack": "mdi:recycle", | ||
} | ||
|
||
SPECIAL_CHARS = str.maketrans( | ||
{ | ||
" ": "%20", | ||
"ä": "ae", | ||
"ß": "%C3%9F", | ||
"ü": "ue", | ||
"ö": "oe", | ||
"ß": "ss", | ||
"(": None, | ||
")": None, | ||
",": None, | ||
".": None, | ||
} | ||
) | ||
|
||
class Source: | ||
def __init__(self, street: str): # argX correspond to the args dict in the source configuration | ||
# self._street = quote( | ||
# street.lower().translate(SPECIAL_CHARS).strip() | ||
# ) | ||
self._street = street | ||
self._ics = ICS() | ||
#LATER self._ics = ICS(regex=r" ...\n (.*)", split_at=r" & ") # remove trailing ...\n from SUMMARY field | ||
# 'r' at the start of the pattern string designates a python "raw" string which passes through backslashes without change | ||
|
||
|
||
def fetch(self): | ||
|
||
# the url contains the current year, but this doesn't really seems to matter at least for the ical, since the result is always the same | ||
# still replace it for compatibility sake | ||
now = datetime.now() | ||
|
||
url = f"{API_URL}/{self._street}/{str(now.year)}-01-01/+1%20year/?format=ics&type=rm,gs,bio,pa" | ||
res = requests.get(url) | ||
res.raise_for_status() | ||
|
||
|
||
|
||
# Fix issue with a mix of Windows/Mac line breaks | ||
ics_data = res.text.replace("\r", "\n") | ||
ics_data = ics_data.replace("\n\n", "\n") | ||
|
||
# Remove Line Breaks ...\n | ||
# ics_data = res.text.split("...")[0] | ||
#ics_data = res.text.replace("...","").replace("\r", "") | ||
|
||
|
||
|
||
# Convert ICS String to events | ||
dates = self._ics.convert(ics_data) | ||
|
||
|
||
entries = [] | ||
for d in dates: | ||
icon = ICON_MAP.get(d[1], "mdi:trash-can") | ||
entries.append(Collection( | ||
date=d[0], | ||
t=d[1].split("...")[0], # string of all characters up to but not including the first "..." | ||
icon=icon | ||
) | ||
) | ||
|
||
return entries |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Stadt Dillingen Saar Abfuhr | ||
|
||
Support for schedules provided by <https://www.dillingen-saar.de/rathaus/buergerservice/abfuhrkalender/>. | ||
|
||
## Configuration via configuration.yaml | ||
|
||
```yaml | ||
waste_collection_schedule: | ||
sources: | ||
- name: dillingen_saar_de | ||
args: | ||
street: <Straße> | ||
``` | ||
### Configuration Variables | ||
**street** | ||
_(string) (required)_ | ||
## Example | ||
**Configuration via configuration.yaml** | ||
```yaml | ||
waste_collection_schedule: | ||
sources: | ||
- name: dillingen_saar_de | ||
args: | ||
street: "Odilienplatz" | ||
``` | ||
## How to get the source arguments | ||
1. Open <https://www.dillingen-saar.de/rathaus/buergerservice/abfuhrkalender/>. | ||
2. Fill out the search field "Straßenname" to verify your street can be found (field is found below the colored icons). | ||
3. Click on the proposed street name in the call out box displayed after entering of (2). | ||
4. Copy the _complete_ name of the street of this field and paste it to the field `street` in your config.yaml of wastecalendar |