-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
103 lines (86 loc) · 2.97 KB
/
app.py
File metadata and controls
103 lines (86 loc) · 2.97 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
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
import flask
from flask import render_template, request, send_file, jsonify
import json
import os
import io
import pandas as pd
import time
import warnings
import xport
import xpt_to_json
from xpt_to_json import *
warnings.filterwarnings("ignore")
app = flask.Flask(__name__)
app.secret_key = "Hello"
# global IE_base, domain, study_name, filetype, inputFile, path
@app.route("/")
def index():
"""Renders first page of application"""
return render_template("JSON.html")
@app.route("/Navigation/<PageName>")
def Navigation(PageName):
"""Navigates between different pages of the application"""
global currPage
currPage = PageName
return render_template(PageName + ".html")
@app.route("/generate_target_file/", methods=["GET", "POST"])
def generate_target_file():
"""
Get the required inputs from the User (StudyName, Domain, FileType, Input File)
Generate the target file based on User Input
"""
# global IE_base, domain, study_name, filetype, inputFile, path
if request.method == "POST":
global filetype, inputFile, path, target, myfile, data, dict_, meta_dict
filetype = request.form["filetype"]
inputFile = request.files["sourcefile"]
path = inputFile.filename
inputFile.save(path)
if filetype == "JSON":
target, dict_, meta_dict = json_(path)
message = "JSON is Generated successfully"
if filetype == "NDJSON":
target, dict_, meta_dict = ndjson_(path)
message = "NDJSON is Generated successfully"
print(target)
# with open(target, "r") as myfile:
# data = myfile.read()
# JSON = data.to_html(classes='table table-stripped')
return render_template("JSON.html", message=message, targetdataset=target)
@app.route("/generate_target_file/JSONfile.html")
def JSONfile():
data_d = {key: dict_[key] for key in ["rows"]}
return render_template("JSONfile.html", title="JSON file", jsonfile=data_d)
@app.route("/generate_target_file/JSONMeta.html")
def JSONMeta():
data_m = {
key: dict_[key]
for key in [
"creationDateTime",
"datasetJSONVersion",
"fileOID",
"name",
"label",
"originator",
"sourceSystem",
"sourceSystemVersion",
"records",
"columns",
"metaDataRef",
"itemGroupOID",
]
}
return render_template("JSONMeta.html", title="JSON file", jsonfile=data_m)
@app.route("/download_file/", methods=["GET", "POST"])
def download_file():
"""
Download the Result files in XPT / JSON format
"""
if request.method == "POST":
# filetype = request.form.getlist('target_filetype')
# filetype = request.form['target_filetype']
return send_file(target, as_attachment=True)
# elif i == 'ndjson':
# return send_file(filepath_json, as_attachment=True)
if __name__ == "__main__":
app.run(debug=True)