-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.py
More file actions
46 lines (37 loc) · 1.7 KB
/
start.py
File metadata and controls
46 lines (37 loc) · 1.7 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
from flask import Flask, render_template, request, redirect, url_for
import runner
app = Flask(__name__)
@app.route('/')
def input():
return render_template('input.html')
@app.route('/', methods=['POST'])
def input_post():
global keyword, number, filter_options, list
keyword = request.form['keyword_input']
number = request.form['number_input']
filter_options = request.form.getlist('options')
try:
list = runner.pubmed(keyword, number, filter_options)
# add hyperlink for each ID
list['ID'] = ('<a href=https://pubmed.ncbi.nlm.nih.gov/' + list['ID'] + '/ >' + list['ID'] + '</a>')
return render_template('output.html', key=keyword, tables=[list.to_html(classes='data', header="true", escape=False)],
titles=list.columns.values, options=filter_options, check='score')
except (AttributeError):
return render_template('outputError.html', key=keyword)
@app.route('/output', methods=['POST'])
def sorting():
# just sorting the dataframe ba a column
sort_by = request.form['sorting']
#score needs to be reversed
if sort_by=='score' or sort_by=='date':
sorted_list = list.sort_values(by=[sort_by], ascending=[False])
else: #everything else is fine
sorted_list = list.sort_values(by=[sort_by])
return render_template('output.html', key=keyword, tables=[sorted_list.to_html(classes='data', header="true", escape=False)],
titles=list.columns.values, options=filter_options,check=sort_by)
@app.route('/restart/')
def my_link():
print ('I got clicked!')
return render_template('input.html')
if __name__ == '__main__':
app.run(debug=True)#set false when put online