-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper.py
32 lines (28 loc) · 973 Bytes
/
helper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import web
import ConfigParser
import json
import decimal
import datetime
configFileDir = 'config.cfg'
config = ConfigParser.ConfigParser()
def logEntry(nodeId, module,severity, message, database):
print("::" + severity.upper() + "::" + " in " + module + "(" + str(nodeId) + ")" + ": " + message)
database.insert('Logs', nodeId=nodeId, logType=severity, module=module,message=message) #Add additional entries!
def addConfig(section, key, default):
config.read(configFileDir)
#Node Config
if not (config.has_section(section)):
config.add_section(section)
if not (config.has_option(section, key)):
config.set(section, key, default)
configFile = open(configFileDir, 'w')
config.write(configFile)
configFile.close()
class jsonExtraEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, decimal.Decimal):
return float(obj)
elif isinstance(obj, datetime.datetime):
return str(obj)
else:
return json.JSONEncoder.default(self, obj)