forked from kmehant/cts_server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
78 lines (63 loc) · 1.86 KB
/
utils.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import uuid
from flask import Flask
from datetime import date
from initializer import mysql
import json
import traceback
def present_date():
"""
Utility method to return present date as a string in the format "YYYY-MM-DD"
"""
return str(date.today())
def otp():
"""
Utility method to return a unique permutation of characters as a string
"""
return uuid.uuid1()
def executeSQL(sqlQuery, fetchOne=True, *params):
"""
Helper method to run any SQL query
returns the result as a list
"""
cur = mysql.connection.cursor()
try:
print("db:" + sqlQuery%params)
cur.execute(sqlQuery % params)
mysql.connection.commit()
except Exception as e:
ex = e
print("db: failed")
traceback_str = ''.join(traceback.format_tb(e.__traceback__))
print(traceback_str)
print(ex)
mysql.connection.rollback()
return "Failure"
result=None
try:
if fetchOne:
result=list(cur.fetchone())
else:
result=list(cur.fetchall())
return result
except:
pass
finally:
cur.close()
def svalidate(token):
"""
Validatation method to validate the user's login via the token
returns uid, username and email as a list
"""
return executeSQL('select sid,Semail from students where spin="%s"',True,str(token))
def tvalidate(token):
"""
Validatation method to validate the user's login via the token
returns uid, username and email as a list
"""
return executeSQL('select tid,temail from teachers where tpin="%s"',True,str(token))
def rvalidate(token):
"""
Validatation method to validate the user's login via the token
returns uid, username and email as a list
"""
return executeSQL('select rid,remail, rposition from resolvers where rpin="%s"',True,str(token))