-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWebBasedQuerySystem.py
114 lines (95 loc) · 3.62 KB
/
WebBasedQuerySystem.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import bottle
import pymongo
import helper
#This is the default route, our index page. Here we need to read the documents from MongoDB.
@bottle.route('/')
def return_api_results():
names = helper_fn.fetch_results()
return bottle.template('test1', dict (mynames1=names ))
#We will post new entries to this route so we can insert them into MongoDB
@bottle.route('/search1api', method = 'POST')
def api_queryparams():
params = {}
year = bottle.request.forms.get("year")
year_opt = bottle.request.forms.get("year_opt")
if year != '':
if year_opt == '1':
params['year']=int(year)
elif year_opt == '2':
params['year'] = {"$gt":int(year)}
else:
params['year'] = {"$lt": int(year)}
protocols = bottle.request.forms.get("protocols")
if protocols != '':
params['protocols'] = protocols
category = bottle.request.forms.get("category")
if category != '':
params['category'] = category
rating = bottle.request.forms.get("rating")
rating_opt = bottle.request.forms.get("rating_opt")
if rating != '':
if rating_opt == '1':
params['rating']=float(rating)
elif rating_opt == '2':
params['rating'] = {"$gt":float(rating)}
else:
params['rating'] = {"$lt": float(rating)}
tags = bottle.request.forms.get("tags")
if tags != '':
temp = tags.strip().split(',')
params['tag'] = {'$all': temp}
keywords = bottle.request.forms.get("keywords")
if keywords != '':
temp = keywords.strip().split(',')
params['$or'] = []
for i in temp:
reg = '(?=^.*' + i + '.*$)'
params['$or'].append({'$and': [{'title': {'$regex': reg},
'summary': {'$regex': reg},
'description': {'$regex': reg}}]})
helper_fn.get_param_api(params, 'api')
bottle.redirect('/')
#We will post new entries to this route so we can insert them into MongoDB
@bottle.route('/search1mash', method = 'POST')
def mash_queryparams():
params = {}
year = bottle.request.forms.get("year")
year_opt = bottle.request.forms.get("year_opt")
if year != '':
if year_opt == '1':
params['year']=int(year)
elif year_opt == '2':
params['year'] = {"$gt":int(year)}
else:
params['year'] = {"$lt": int(year)}
APIs = bottle.request.forms.get("APIs")
if APIs != '':
temp = APIs.strip().split(',')
for api in temp:
params['APIs.'+api] = {'$exists':'true'}
tags = bottle.request.forms.get("tags")
if tags != '':
temp = tags.strip().split(',')
params['tag'] = {'$all': temp}
#{$or:[{$and:[{title: {$regex: '(?=^.*api.*$)' } ,
# summary:{$regex: '(?=^.*api.*$)' }}]},
# {$and:[{title: {$regex: '(?=^.*api.*$)' } ,
# summary:{$regex: '(?=^.*api.*$)' }}]}]}
keywords = bottle.request.forms.get("keywords")
if keywords != '':
temp = keywords.strip().split(',')
params['$or'] = []
for i in temp:
reg = '(?=^.*'+i+'.*$)'
params['$or'].append({'$and':[{'title': {'$regex': reg} ,
'summary':{'$regex': reg},'description':{'$regex': reg}}]})
helper_fn.get_param_mash(params, 'mashup')
bottle.redirect('/')
#setup the connection
connection_string = "mongodb://localhost"
connection = pymongo.MongoClient(connection_string)
database = connection.webservice
#guestbook = guestbookDAO.GuestbookDAO(database)
helper_fn = helper.helper(database)
bottle.debug(True)
bottle.run(host='localhost', port=8082)