-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
46 lines (41 loc) · 1.17 KB
/
test.py
File metadata and controls
46 lines (41 loc) · 1.17 KB
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
import MySQLdb as mydb
import sys
class Database:
user = 'root'
passwd = 'root'
host = 'localhost'
db = 'TrustModel'
def __init__(self):
self.connection = mydb.connect(user = self.user, passwd=self.passwd,host=self.host,db=self.db)
def query(self,q):
cursor = self.connection.cursor(mydb.cursors.DictCursor)
cursor.execute(q)
self.connection.commit()
return cursor.fetchall()
def __del__(self):
self.connection.close()
if __name__ == '__main__':
try:
db = Database()
qj = input("Enter quality:")
l = int(input("Enter level:"))
w = int(input("Enter interest:"))
q = '''insert into Requirment(quality,level,interest,time_stamp) values({0},{1},{2},now())'''.format(qj,l,w)
db.query(q)
except KeyboardInterrupt:
print 'You cancelled the execution ..!!'
except IOError:
print 'Error: input error ..!!'
sys.exit(1)
print '\nThe current entry is:'
print '\n'
p = db.query('''SELECT id,quality,level,interest, DATE_FORMAT( time_stamp, '%W %H:%i' )
FROM Requirment
ORDER BY id DESC
LIMIT 1
''')
for item in p:
print 'Id:%s'%item['id']
print 'Quality:%s'%item['quality']
print 'Level:%s'%item['level']
print 'Interest:%s'%item['interest']