-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathController.py
More file actions
56 lines (43 loc) · 1.74 KB
/
Copy pathController.py
File metadata and controls
56 lines (43 loc) · 1.74 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
47
48
49
50
51
52
53
54
55
56
import psycopg2
class Controller(object):
def __init__(self, db_url):
self.conn = psycopg2.connect(db_url)
self.cursor = self.conn.cursor()
def close(self):
self.cursor.close()
self.conn.close()
def add_so(self, user, so):
self.cursor.execute('INSERT INTO user_so (id, so) VALUES(%s, %s)', (
user, so))
self.conn.commit()
def get_so(self, user):
try:
self.cursor.execute('SELECT DISTINCT so FROM user_so WHERE id =' + str(user))
return self.cursor.fetchall()
except Exception as error:
print("Oops! An exception has occured:", error)
print("Exception TYPE:", type(error))
return [[]]
def delete_so(self, user):
self.cursor.execute('DELETE FROM user_so WHERE id =' + str(user))
self.conn.commit()
def get_soinfo(self, so):
try:
self.cursor.execute('SELECT information FROM so_info WHERE number =' + str(so))
return self.cursor.fetchall()
except Exception as error:
print("Oops! An exception has occured:", error)
print("Exception TYPE:", type(error))
return [[]]
def get_soinfo_fromuser(self, user):
try:
self.cursor.execute(
'SELECT so, information FROM so_info WHERE so in (SELECT DISTINCT so FROM user_so WHERE id = %s)', ([user]))
return self.cursor.fetchall()
except Exception as error:
print("Oops! An exception has occured:", error)
print("Exception TYPE:", type(error))
return [[]]
def normalization(self):
self.cursor.execute('UPDATE user_so SET so = REPLACE(so,\'*\',\'\')', )
self.conn.commit()