-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathform.py
More file actions
49 lines (36 loc) · 1.23 KB
/
form.py
File metadata and controls
49 lines (36 loc) · 1.23 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
47
48
49
import os
from flask import Flask, request, send_from_directory
# App config.
#form = Flask('formapp', static_url_path='')
DEBUG = True
app = Flask(__name__, static_url_path='')
@app.route("/")
def root():
return app.send_static_file('index.html')
@app.route("/_images/<path:path>")
def uimages(path):
return send_from_directory('output_html/html/_images', path)
@app.route("/_static/<path:path>")
def ustatic(path):
return send_from_directory('output_html/html/_static', path)
@app.route("/output_nbs/<path:path>")
def output_nbs(path):
return send_from_directory('output_nbs', path)
@app.route('/notebook_magic')
def notebook_magic():
#target = request.args.get('target', default=None, type=str)
import book_maker
cleaned_dict = {}
for k, v in request.args.items():
cleaned_dict[k] = v
outnbfn = book_maker.make_notebook_from_params(cleaned_dict)
outhtmlfn = outnbfn.replace('.ipynb', '.html')
if os.path.exists(outhtmlfn):
os.unlink(outhtmlfn)
genres = book_maker.generate_html_from_notebook()
if genres != 0:
return 'nb generation failed!'
return send_from_directory('output_html/html/', outhtmlfn)
if __name__ == "__main__":
app.debug = True
app.run()