From 618f5a7a7dbd3879ec452552cc506141c2e78c29 Mon Sep 17 00:00:00 2001 From: nobbie2009 Date: Mon, 20 Jul 2020 13:15:33 +0200 Subject: [PATCH 1/6] Update config.template.ini MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Pluginconfig hinzugefügt. --- config/config.template.ini | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/config/config.template.ini b/config/config.template.ini index 3be9c60..4b7825e 100644 --- a/config/config.template.ini +++ b/config/config.template.ini @@ -129,7 +129,7 @@ notifyMyAndroid = 0 # for developing template-module template = 0 - +2calendar = 1 [MySQL] # MySQL configuration @@ -301,6 +301,10 @@ phonenumber1 = 0160321654987 # ! DO NOT USE ANY UMLAUT ! text1 = Rueckruf Leitstelle! +[2calendar] +# Config-Daten des Kalenderplugins +filepath2calendar = #Pfad zur Kalenderdatei + ##################### ##### Not ready yet # ##################### From 7c67590519331d26ae5301faf9efd4d0d358a82e Mon Sep 17 00:00:00 2001 From: nobbie2009 Date: Mon, 20 Jul 2020 13:16:28 +0200 Subject: [PATCH 2/6] Add files via upload --- 2calendar.py | 145 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 145 insertions(+) create mode 100644 2calendar.py diff --git a/2calendar.py b/2calendar.py new file mode 100644 index 0000000..23efd86 --- /dev/null +++ b/2calendar.py @@ -0,0 +1,145 @@ +#!/usr/bin/python +# -*- coding: UTF-8 -*- + +""" +Kalendereinträge für Alarmierungen + +@author: baderj +@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 + +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 MySQL-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 + # + logging.debug("Kalender wird instanziert") + cal = Calendar() + cal.add('proid', 'BOS') + cal.add('version', '2.0') + + except: + logging.error("Kann Kalender nicht erstellen") + else: + try: + # + # Erstelle das Event + # + logging.debug("Insert %s", typ) + + if typ == "ZVEI": + + + 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": + + logging.debug("Lese Event aus: "+component.get('SUMMARY') ) + event = Event() + event.add('summary', component.get('SUMMARY')) + print(component.get('SUMMARY')) + event.add('dtstart', component.get('DTSTART')) + print(component.get('DTSTART').dt) + event.add('dtend', component.get('dtend')) + print(component.get('dtend').dt) + event.add('dtstamp', component.get('dtstamp')) + print(component.get('dtstamp').dt) + event.add('location', component.get('location')) + print(component.get('LOCATION')) + event['uid'] = component.get('UID') + cal.add_component(event) + + g.close() + + + timestamp = datetime.fromtimestamp(data["timestamp"]) + event = Event() + event.add('summary', data["description"]) + event.add('dtstart',timestamp) + event.add('dtend',timestamp) + event.add('dtstamp',timestamp) + event.add('location', data["zvei"]) + event['uid'] = "{0}#{1}".format(timestamp,data["description"]) + cal.add_component(event) + # logging.debug("Schreibe in ZVEI-spezifische-Datei") + # with open(globalVars.config.get("2calendar", "filepath2calendar")+data["description"]+'.ics', 'wb') as f: + # f.write(cal.to_ical()) + logging.debug("Schreibe in Gesamt-Datei") + with open(globalVars.config.get("2calendar", "filepath2calendar")+'alle.ics', 'wb') as f: + f.write(cal.to_ical()) + else: + logging.warning("Nicht unterstützter Typ: %s", typ) + 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) From 50b5eb048dbaa8208659bbd7359ef617b91810b3 Mon Sep 17 00:00:00 2001 From: nobbie2009 Date: Mon, 20 Jul 2020 13:18:37 +0200 Subject: [PATCH 3/6] Update and rename 2calendar.py to plugins/2calendar/2calendar.py --- .../2calendar/2calendar.py | 39 ++++++------------- 1 file changed, 11 insertions(+), 28 deletions(-) rename 2calendar.py => plugins/2calendar/2calendar.py (83%) diff --git a/2calendar.py b/plugins/2calendar/2calendar.py similarity index 83% rename from 2calendar.py rename to plugins/2calendar/2calendar.py index 23efd86..d7d6d02 100644 --- a/2calendar.py +++ b/plugins/2calendar/2calendar.py @@ -3,15 +3,15 @@ """ Kalendereinträge für Alarmierungen - -@author: baderj +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. @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 @@ -37,9 +37,7 @@ 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 @@ -48,23 +46,20 @@ def onLoad(): ## # -# Main function of MySQL-plugin +# 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: @@ -74,11 +69,10 @@ def run(typ,freq,data): # # Kalender instanzieren # - logging.debug("Kalender wird instanziert") cal = Calendar() cal.add('proid', 'BOS') cal.add('version', '2.0') - + except: logging.error("Kann Kalender nicht erstellen") else: @@ -86,19 +80,14 @@ def run(typ,freq,data): # # Erstelle das Event # - logging.debug("Insert %s", typ) - + if typ == "ZVEI": - - 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": - - logging.debug("Lese Event aus: "+component.get('SUMMARY') ) event = Event() event.add('summary', component.get('SUMMARY')) print(component.get('SUMMARY')) @@ -112,10 +101,10 @@ def run(typ,freq,data): print(component.get('LOCATION')) event['uid'] = component.get('UID') cal.add_component(event) - + g.close() - - + + timestamp = datetime.fromtimestamp(data["timestamp"]) event = Event() event.add('summary', data["description"]) @@ -125,10 +114,6 @@ def run(typ,freq,data): event.add('location', data["zvei"]) event['uid'] = "{0}#{1}".format(timestamp,data["description"]) cal.add_component(event) - # logging.debug("Schreibe in ZVEI-spezifische-Datei") - # with open(globalVars.config.get("2calendar", "filepath2calendar")+data["description"]+'.ics', 'wb') as f: - # f.write(cal.to_ical()) - logging.debug("Schreibe in Gesamt-Datei") with open(globalVars.config.get("2calendar", "filepath2calendar")+'alle.ics', 'wb') as f: f.write(cal.to_ical()) else: @@ -138,8 +123,6 @@ def run(typ,freq,data): logging.debug("cannot Insert %s", typ, exc_info=True) return - - except: logging.error("unknown error") logging.debug("unknown error", exc_info=True) From 119ee21a92a1615a41f6e0bd96a432bc19779ea1 Mon Sep 17 00:00:00 2001 From: nobbie2009 Date: Mon, 20 Jul 2020 13:19:28 +0200 Subject: [PATCH 4/6] Update 2calendar.py --- plugins/2calendar/2calendar.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/plugins/2calendar/2calendar.py b/plugins/2calendar/2calendar.py index d7d6d02..ae7cb8e 100644 --- a/plugins/2calendar/2calendar.py +++ b/plugins/2calendar/2calendar.py @@ -90,15 +90,10 @@ def run(typ,freq,data): if component.name == "VEVENT": event = Event() event.add('summary', component.get('SUMMARY')) - print(component.get('SUMMARY')) event.add('dtstart', component.get('DTSTART')) - print(component.get('DTSTART').dt) event.add('dtend', component.get('dtend')) - print(component.get('dtend').dt) event.add('dtstamp', component.get('dtstamp')) - print(component.get('dtstamp').dt) event.add('location', component.get('location')) - print(component.get('LOCATION')) event['uid'] = component.get('UID') cal.add_component(event) From d5d549ed03cd0ff89c712928aea3695190c1dfdc Mon Sep 17 00:00:00 2001 From: nobbie2009 Date: Mon, 20 Jul 2020 16:45:55 +0200 Subject: [PATCH 5/6] Update 2calendar.py Schreibt Alarme in eine ICS-Datei --- plugins/2calendar/2calendar.py | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/plugins/2calendar/2calendar.py b/plugins/2calendar/2calendar.py index ae7cb8e..629dcb8 100644 --- a/plugins/2calendar/2calendar.py +++ b/plugins/2calendar/2calendar.py @@ -21,7 +21,7 @@ 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 @@ -82,22 +82,23 @@ def run(typ,freq,data): # if typ == "ZVEI": - g = open(globalVars.config.get("2calendar", "filepath2calendar")+'alle.ics','rb') - gcal = Calendar.from_ical(g.read()) + 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(): + 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) + 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() + g.close() timestamp = datetime.fromtimestamp(data["timestamp"]) From 15e1d7d15d58dcdf67993252310d4a49e2219d58 Mon Sep 17 00:00:00 2001 From: Florian Date: Tue, 21 Jul 2020 23:23:15 +0200 Subject: [PATCH 6/6] Update 2calendar.py Adding support for POCSAG by globalizing functionality --- plugins/2calendar/2calendar.py | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/plugins/2calendar/2calendar.py b/plugins/2calendar/2calendar.py index 629dcb8..5d03fac 100644 --- a/plugins/2calendar/2calendar.py +++ b/plugins/2calendar/2calendar.py @@ -80,8 +80,25 @@ def run(typ,freq,data): # # 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()) @@ -103,17 +120,17 @@ def run(typ,freq,data): timestamp = datetime.fromtimestamp(data["timestamp"]) event = Event() - event.add('summary', data["description"]) + event.add('summary', summary) event.add('dtstart',timestamp) event.add('dtend',timestamp) event.add('dtstamp',timestamp) - event.add('location', data["zvei"]) + 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()) - else: - logging.warning("Nicht unterstützter Typ: %s", typ) + except: logging.error("cannot Insert %s", typ) logging.debug("cannot Insert %s", typ, exc_info=True)