diff --git a/.gitignore b/.gitignore index 079572f..9ed2123 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,6 @@ -config.py +__pycache__/ +conf/*custom.ini .directory +*.swp +*~ +*.pyc \ No newline at end of file diff --git a/conf/conf.ini b/conf/conf.ini new file mode 100644 index 0000000..4ad699a --- /dev/null +++ b/conf/conf.ini @@ -0,0 +1,19 @@ +# zerocalcare - Zero Optimized Caldav Calendar Reader Engine +# Main configuration file +# +# Do not edit this file directly if you want to keep your git repository clean. +# Copy/Rename it as `conf.custom.ini` and edit it. +# It will override this file's values, and it will not be tracked. +################################################################################ + +# Database and tables settings +[mysql] + unix_socket = + host = + user = + password = + db = + +# Calendar related variables +[caldav] + cal_name = \ No newline at end of file diff --git a/config.py b/config.py deleted file mode 100644 index 5411de4..0000000 --- a/config.py +++ /dev/null @@ -1,8 +0,0 @@ -UNIX_SOCKET='' -HOST='' -USER='' -PASSWORD='' -DB='' -CALENDAR_NAME='' - - diff --git a/getInfo.py b/getInfo.py index fb15209..f4d11f4 100755 --- a/getInfo.py +++ b/getInfo.py @@ -3,7 +3,7 @@ import mysql.connector as sql import datetime as dt import sys import re -from config import * +import glob def parseOptions(arr): if len(arr) == 1: @@ -27,11 +27,11 @@ def getEvents(baseDay, interval): raise ValueError('Invalid argument passed to getEvents') leftLimit = baseDay.strftime('%s') - c = sql.connect(unix_socket=UNIX_SOCKET, host=HOST, user=USER, password=PASSWORD, db=DB) + c = sql.connect(unix_socket=glob.cfg['mysql']['unix_socket'], host=glob.cfg['mysql']['host'], user=glob.cfg['mysql']['user'], password=glob.cfg['mysql']['password'], db=glob.cfg['mysql']['db']) mycursor = c.cursor() # For repeated events (not yet supported) #sql = "SELECT obj.calendardata FROM oc_calendarobjects AS obj INNER JOIN oc_calendars AS cal ON obj.calendarid = cal.id WHERE cal.displayname='prova'AND obj.firstoccurence < %s AND obj.lastoccurence > %s" % (leftLimit, rightLimit) - query = "SELECT obj.calendardata FROM oc_calendarobjects AS obj INNER JOIN oc_calendars AS cal ON obj.calendarid = cal.id WHERE cal.displayname='%s' AND obj.firstoccurence < %s AND obj.firstoccurence > %s" % (CALENDAR_NAME, rightLimit, leftLimit) + query = "SELECT obj.calendardata FROM oc_calendarobjects AS obj INNER JOIN oc_calendars AS cal ON obj.calendarid = cal.id WHERE cal.displayname='%s' AND obj.firstoccurence < %s AND obj.firstoccurence > %s" % (glob.cfg['caldav']['cal_name'], rightLimit, leftLimit) mycursor.execute(query) result = mycursor.fetchall() c.close() diff --git a/glob.py b/glob.py new file mode 100644 index 0000000..d48a9d2 --- /dev/null +++ b/glob.py @@ -0,0 +1,5 @@ +import configparser + +# Read configuration files (latest files in list override previous settings) +cfg = configparser.ConfigParser() +cfg.read(['conf/conf.ini', 'conf/conf.custom.ini']) \ No newline at end of file