-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdbbindings.py
executable file
·65 lines (46 loc) · 1.48 KB
/
dbbindings.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
#!/usr/bin/env python
#So we load in the terms that allow the API implementation to happen for now.
from datetime import datetime
from bookworm.general_API import *
import os
import cgitb
#import MySQLdb
cgitb.enable()
def headers(method):
if method!="return_tsv":
print "Content-type: text/html\n"
elif method=="return_tsv":
print "Content-type: text; charset=utf-8"
print "Content-Disposition: filename=Bookworm-data.txt"
print "Pragma: no-cache"
print "Expires: 0\n"
def debug(string):
"""
Makes it easier to debug through a web browser by handling the headers
No calls should be permanently left in the code ever, or they will break things badly.
"""
print headers('1')
print "<br>"
print string
print "<br>"
def main(JSONinput):
query = JSONinput
try:
#Whether there are multiple search terms, as in the highcharts method.
usingSuccinctStyle = isinstance(query['search_limits'],dict)
except:
#If there are no search limits, it might be a returnPossibleFields query
usingSuccinctStyle = True
headers(query['method'])
p = SQLAPIcall(query)
result = p.execute()
print result
return True
if __name__=="__main__":
form = cgi.FieldStorage()
#Still supporting two names for the passed parameter.
try:
JSONinput = form["queryTerms"].value
except KeyError:
JSONinput = form["query"].value
main(json.loads(JSONinput))