-
Notifications
You must be signed in to change notification settings - Fork 0
/
printUsers.py
69 lines (61 loc) · 2.91 KB
/
printUsers.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
import connectToDatabase
from printUser import getUserBioSummaryString
__author__ = 'ashaw'
def fetchAdditionalProfileInfo(l, internalCursor):
internalCursor.execute("SELECT operating_system FROM user_operating_systems " +
"WHERE user_operating_systems.userid = %s " +
"ORDER BY operating_system ASC", [l['userid']])
l['user_operating_systems'] = internalCursor.fetchall()
internalCursor.execute("SELECT operating_system FROM user_operating_system_wanted " +
"WHERE user_operating_system_wanted.userid = %s " +
"ORDER BY operating_system ASC", [l['userid']])
l['user_operating_systems_wanted'] = internalCursor.fetchall()
internalCursor.execute("SELECT programming_language FROM user_programming_languages " +
"WHERE user_programming_languages.userid = %s " +
"ORDER BY programming_language ASC", [l['userid']])
l['user_programming_languages'] = internalCursor.fetchall()
internalCursor.execute("SELECT programming_language FROM user_programming_languages_wanted " +
"WHERE user_programming_languages_wanted.userid = %s " +
"ORDER BY programming_language ASC", [l['userid']])
l['user_programming_languages_wanted'] = internalCursor.fetchall()
return l
def printUserProfilesInternal(query, values):
string = ''
conn = connectToDatabase.connect(dictCon=True)
users = conn.cursor()
internalCursor = conn.cursor()
users.execute(query, values)
for user in users:
l = user
l = fetchAdditionalProfileInfo(l, internalCursor)
string += getUserBioSummaryString(l)
internalCursor.close()
users.close()
conn.close()
return string
def escape(search):
return search.replace('`','``').replace('_','`_').replace('%','`%')
def getUserProfiles(search, prefix,postfix, limit,page):
return printUserProfilesInternal("SELECT * FROM USERS WHERE userid ILIKE and account_status = 'Active' %s ESCAPE '`' ORDER BY userid ASC LIMIT %s OFFSET %s", [prefix + escape(search) + postfix, limit, page*limit ])
def countUserProfiles(search, prefix,postfix):
conn = connectToDatabase.connect()
count = conn.cursor()
count.execute("SELECT count(*) FROM USERS WHERE userid and account_status = 'Active' ILIKE %s ESCAPE '`'", [prefix + escape(search) + postfix])
countValue = count.fetchone()[0]
count.close()
conn.close()
return countValue
def getCount(query,values):
string = ''
conn = connectToDatabase.connect(dictCon=True)
users = conn.cursor()
internalCursor = conn.cursor()
users.execute(query, values)
for user in users:
l = user
l = fetchAdditionalProfileInfo(l, internalCursor)
string += getUserBioSummaryString(l)
internalCursor.close()
users.close()
conn.close()
return string