#!/usr/local/bin/python
import sys
sys.path.extend(["/home/protected/ternadim_central"])
from time import gmtime, strftime
ts = strftime("%y-%m-%d %H:%M:%S", gmtime())
try:
	import main
	main.run()
	import os
	logf = open("/tmp/ternadim_central_main.log", 'a')
	logf.write(ts+" Succesful request: "+str(os.environ["QUERY_STRING"])+"\n")
	logf.close()
except Exception as e:
	print('{"error": "Exception occurred."}')
	import traceback
	import os
	logf = open("/tmp/ternadim_central_main.log", 'a')
	logf.write(ts+" Failed request: "+str(os.environ["QUERY_STRING"])+"\n")
	logf.write("Exception occurred:\n")
	logf.write(str(e)+"\n")
	logf.write(traceback.format_exc()+"\n")
	logf.close()

