-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path#filter_tables.py#
68 lines (54 loc) · 1.79 KB
/
#filter_tables.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
from helper import generate_ui
from collections import OrderedDict
database = 'suggestion_box.db'
input_prompt = 'Select a function (enter a number or enter "q" to exit).\n'
again_prompt = 'Would you like to select another function (Enter "y" to ' +\
'start again)?\n'
def filter_active_users(conn):
is_active = input('Type 0 to view inactive users or 1 to view active ' +
'users.\n')
while is_active not in ('0', '1'):
is_active = input('Please enter 0 or 1.\n')
return conn.execute(
'''
SELECT username, full_name, email, password
FROM user WHERE is_active=%s
'''
% is_active
)
def find_user(conn):
username = input('Enter a username to lookup.\n')
return conn.execute(
'''
SELECT username, full_name, email, password
FROM user WHERE username=\'%s\'
'''
% username
)
def filter_unconcacted_suggestors(conn):
return conn.execute(
'''
SELECT author, email, phone, text, timestamp
FROM suggestion WHERE should_contact=1
'''
)
def filter_suggestions_without_responses(conn):
return conn.execute(
'''
SELECT author, email, phone, suggestion.text, suggestion.timestamp
FROM suggestion
LEFT JOIN response ON suggestion.id=suggestion_id
GROUP BY suggestion.id
HAVING COUNT(response.id)=0
'''
)
functions = OrderedDict([
('Filter Active Users', filter_active_users),
('Find User', find_user),
('Filter Suggestions With Contact Requests',
filter_unconcacted_suggestors),
('Filter Suggestions Without Responses',
filter_suggestions_without_responses)
])
if __name__ == '__main__':
generate_ui(database, functions, input_prompt, again_prompt)