Added INI conf file

This commit is contained in:
giuliof 2018-11-07 22:00:56 +01:00
parent c18c9165cd
commit d9cf74b749
5 changed files with 32 additions and 12 deletions

6
.gitignore vendored
View File

@ -1,2 +1,6 @@
config.py
__pycache__/
conf/*custom.ini
.directory
*.swp
*~
*.pyc

19
conf/conf.ini Normal file
View File

@ -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 =

View File

@ -1,8 +0,0 @@
UNIX_SOCKET=''
HOST=''
USER=''
PASSWORD=''
DB=''
CALENDAR_NAME=''

View File

@ -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()

5
glob.py Normal file
View File

@ -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'])