-
-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Alarmierungen in ICS-Kalender übernehmen #462
Open
nobbie2009
wants to merge
7
commits into
Schrolli91:develop
Choose a base branch
from
nobbie2009:develop
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
618f5a7
Update config.template.ini
nobbie2009 7c67590
Add files via upload
nobbie2009 50b5eb0
Update and rename 2calendar.py to plugins/2calendar/2calendar.py
nobbie2009 119ee21
Update 2calendar.py
nobbie2009 d5d549e
Update 2calendar.py
nobbie2009 55e4a28
Merge branch 'develop' into develop
nobbie2009 15e1d7d
Update 2calendar.py
flothi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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,141 @@ | ||
#!/usr/bin/python | ||
# -*- coding: UTF-8 -*- | ||
|
||
""" | ||
Kalendereinträge für Alarmierungen | ||
Erstellt eine Icalendar (ICS)-Datei, diese kann in Kalender wie Outlook etc. importiert werden. | ||
Aktuell wird jeder Alarm der via Regex dieses Plugin anspricht, in eine "Gesamtdatei" geschrieben. Denkbar wäre aber auch | ||
für jeden Filter eine seperate Datei anzulegen. | ||
Auch wird aktuell nur ZVEI, aus mangel an Erfahrung, ausgewertet. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Der Kommentar wäre mit der Anpassung von @flothi überflüssig bzw. nur noch FMS ist ausgeschlossen There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @flothi wieso |
||
@author: Norbert Jahn | ||
@author: Bastian Schroll | ||
@requires: icalendar https://pypi.org/project/icalendar/ | ||
@requires: dateutil https://github.com/dateutil/dateutil/ | ||
@requires: pytz https://pypi.org/project/pytz/ | ||
""" | ||
|
||
import logging # Global logger | ||
import time | ||
import requests | ||
import re | ||
from icalendar import Calendar, Event | ||
from datetime import datetime, timedelta | ||
import pytz | ||
import os.path | ||
from includes import globalVars # Global variables | ||
from includes.helper import configHandler | ||
|
||
|
||
|
||
|
||
## | ||
# | ||
# onLoad (init) function of plugin | ||
# will be called one time by the pluginLoader on start | ||
# | ||
def onLoad(): | ||
""" | ||
While loading the plugins by pluginLoader.loadPlugins() | ||
this onLoad() routine is called one time for initialize the plugin | ||
@requires: nothing | ||
@return: nothing | ||
""" | ||
# nothing to do for this plugin | ||
return | ||
|
||
|
||
## | ||
# | ||
# Main function of Calendar-plugin | ||
# will be called by the alarmHandler | ||
# | ||
def run(typ,freq,data): | ||
""" | ||
This function is the implementation of a Calendar-Plugin | ||
It will write Alarms in an ics-File. | ||
@type typ: string (FMS|ZVEI|POC) | ||
@param typ: Typ of the dataset for sending to BosMon | ||
@type data: map of data (structure see readme.md in plugin folder) | ||
@param data: Contains the parameter for dispatch to BosMon. | ||
@type freq: string | ||
@keyword freq: frequency is not used in this plugin | ||
@requires: | ||
@return: nothing | ||
""" | ||
try: | ||
if configHandler.checkConfig("2calendar"): #read and debug the config | ||
|
||
try: | ||
# | ||
# Kalender instanzieren | ||
# | ||
cal = Calendar() | ||
cal.add('proid', 'BOS') | ||
cal.add('version', '2.0') | ||
|
||
except: | ||
logging.error("Kann Kalender nicht erstellen") | ||
else: | ||
try: | ||
# | ||
# Erstelle das Event | ||
# | ||
|
||
summary = "" | ||
location = "" | ||
msg = "" | ||
enterEvent = False | ||
|
||
if typ == "ZVEI": | ||
summary = data["description"] | ||
location = data["zvei"] | ||
enterEvent = True | ||
elif typ == "POC": | ||
summary = data["description"] | ||
location = data["ric"] + data["functionChar"] | ||
msg = data["msg"] | ||
enterEvent = True | ||
else: | ||
logging.warning("Nicht unterstützter Typ: %s", typ) | ||
|
||
if enterEvent == True: | ||
if os.path.exists(globalVars.config.get("2calendar", "filepath2calendar")+'alle.ics'): | ||
g = open(globalVars.config.get("2calendar", "filepath2calendar")+'alle.ics','rb') | ||
gcal = Calendar.from_ical(g.read()) | ||
|
||
for component in gcal.walk(): | ||
|
||
if component.name == "VEVENT": | ||
event = Event() | ||
event.add('summary', component.get('SUMMARY')) | ||
event.add('dtstart', component.get('DTSTART')) | ||
event.add('dtend', component.get('dtend')) | ||
event.add('dtstamp', component.get('dtstamp')) | ||
event.add('location', component.get('location')) | ||
event['uid'] = component.get('UID') | ||
cal.add_component(event) | ||
|
||
g.close() | ||
|
||
|
||
timestamp = datetime.fromtimestamp(data["timestamp"]) | ||
event = Event() | ||
event.add('summary', summary) | ||
event.add('dtstart',timestamp) | ||
event.add('dtend',timestamp) | ||
event.add('dtstamp',timestamp) | ||
event.add('location', location) | ||
event.add('description', msg) | ||
event['uid'] = "{0}#{1}".format(timestamp,data["description"]) | ||
cal.add_component(event) | ||
with open(globalVars.config.get("2calendar", "filepath2calendar")+'alle.ics', 'wb') as f: | ||
f.write(cal.to_ical()) | ||
|
||
except: | ||
logging.error("cannot Insert %s", typ) | ||
logging.debug("cannot Insert %s", typ, exc_info=True) | ||
return | ||
|
||
except: | ||
logging.error("unknown error") | ||
logging.debug("unknown error", exc_info=True) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Das sollte aber noch über den template Eintrag
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@flothi wieso
resolved
?