2020-06-24 19:09:05 +01:00
|
|
|
"""
|
|
|
|
Flask Documentation: http://flask.pocoo.org/docs/
|
|
|
|
Jinja2 Documentation: http://jinja.pocoo.org/2/documentation/
|
|
|
|
Werkzeug Documentation: http://werkzeug.pocoo.org/documentation/
|
|
|
|
"""
|
|
|
|
import os
|
|
|
|
from app import app
|
2020-09-09 20:19:32 +01:00
|
|
|
from flask import render_template, request, flash, send_file
|
2020-06-24 19:09:05 +01:00
|
|
|
from werkzeug.utils import secure_filename
|
2020-07-06 14:26:16 +01:00
|
|
|
from random import choice, shuffle
|
|
|
|
from string import digits, ascii_lowercase
|
2020-08-24 11:32:32 +01:00
|
|
|
from pymed import PubMed
|
2020-09-10 07:34:25 +01:00
|
|
|
from datetime import datetime,date
|
2020-08-24 11:32:32 +01:00
|
|
|
import json
|
2020-08-29 14:55:45 +01:00
|
|
|
import subprocess
|
2020-06-24 19:09:05 +01:00
|
|
|
|
2020-09-10 07:34:25 +01:00
|
|
|
import logging
|
|
|
|
import logzero
|
|
|
|
from logzero import logger
|
|
|
|
logzero.loglevel(logging.DEBUG)
|
|
|
|
if app.config['SAVE_LOGS']:
|
|
|
|
logFile = app.config['LOG_FOLDER'] + date.today().strftime("%m-%d-%y") + ".log"
|
|
|
|
logzero.logfile(logFile, maxBytes=1e6, backupCount=3)
|
|
|
|
|
|
|
|
import configparser
|
|
|
|
misc = configparser.ConfigParser()
|
|
|
|
misc.read('app/misc.ini')
|
|
|
|
errors = misc['ERRORS']
|
|
|
|
|
2020-06-24 19:09:05 +01:00
|
|
|
# Note: that when using Flask-WTF we need to import the Form Class that we created
|
|
|
|
# in forms.py
|
2020-09-09 20:19:32 +01:00
|
|
|
from .forms import MyForm, curieForm, statusForm, generateSMILES, PyMedSearch, dockSingleForm, generatePDBQTS
|
2020-06-24 19:09:05 +01:00
|
|
|
|
2020-09-10 07:34:25 +01:00
|
|
|
def log(message,logType="INFO"):
|
|
|
|
if app.config['LOG']:
|
|
|
|
if logType == "INFO":
|
|
|
|
logger.info(message)
|
|
|
|
elif logType == "DEBUG":
|
|
|
|
logger.debug(message)
|
|
|
|
elif logType == "EXCEPTION":
|
|
|
|
logger.exception(message)
|
|
|
|
elif logType == "DANGER":
|
|
|
|
logger.error(message)
|
|
|
|
return None
|
|
|
|
|
2020-07-06 14:26:16 +01:00
|
|
|
def gen_word(N, min_N_dig, min_N_low):
|
|
|
|
choose_from = [digits]*min_N_dig + [ascii_lowercase]*min_N_low
|
|
|
|
choose_from.extend([digits + ascii_lowercase] * (N-min_N_low-min_N_dig))
|
|
|
|
chars = [choice(bet) for bet in choose_from]
|
|
|
|
shuffle(chars)
|
|
|
|
return ''.join(chars)
|
|
|
|
|
|
|
|
def convertToBinaryData(filename):
|
|
|
|
# Convert digital data to binary format
|
|
|
|
with open(filename, 'rb') as file:
|
|
|
|
binaryData = file.read()
|
|
|
|
return binaryData
|
|
|
|
|
2020-06-24 19:09:05 +01:00
|
|
|
###
|
|
|
|
# Routing for your application.
|
|
|
|
###
|
|
|
|
|
|
|
|
@app.route('/')
|
|
|
|
def home():
|
|
|
|
"""Render website's home page."""
|
|
|
|
return render_template('home.html')
|
|
|
|
|
2020-06-25 17:44:07 +01:00
|
|
|
@app.route('/About')
|
|
|
|
def about():
|
|
|
|
"""Render about page."""
|
|
|
|
return render_template('about.html')
|
|
|
|
|
2020-08-29 20:22:21 +01:00
|
|
|
@app.route('/Editor')
|
|
|
|
def editor():
|
|
|
|
"""Render Molecular Editor"""
|
|
|
|
return render_template('molecule_editor.html')
|
|
|
|
|
2020-07-06 10:36:48 +01:00
|
|
|
@app.route('/Visualise')
|
|
|
|
def visualise():
|
|
|
|
"""Render visualisation page."""
|
|
|
|
return render_template('visualise.html')
|
|
|
|
|
2020-08-24 11:32:32 +01:00
|
|
|
@app.route('/Search',methods=['GET','POST'])
|
|
|
|
def pubmed():
|
|
|
|
"""Query PubMed"""
|
|
|
|
form = PyMedSearch()
|
|
|
|
pubmed = PubMed(tool="Curie", email="navanchauhan@gmail.com")
|
|
|
|
|
|
|
|
if request.method == 'POST' and form.validate_on_submit():
|
|
|
|
q = form.query.data
|
2020-09-10 07:34:25 +01:00
|
|
|
log(form,"DEBUG")
|
|
|
|
log(pubmed,"DEBUG")
|
2020-08-24 11:32:32 +01:00
|
|
|
results = pubmed.query(q,max_results=100)
|
|
|
|
search = []
|
|
|
|
for x in results:
|
|
|
|
search.append(x.toDict())
|
|
|
|
|
|
|
|
return render_template('search.html',result=search,form=form)
|
|
|
|
|
|
|
|
flash_errors(form)
|
|
|
|
return render_template('search.html',form=form)
|
|
|
|
|
2020-07-07 17:50:03 +01:00
|
|
|
@app.route('/Status',methods=['GET','POST'])
|
|
|
|
def status():
|
|
|
|
taskStatusForm = statusForm()
|
|
|
|
|
|
|
|
if request.method == 'POST':
|
|
|
|
if taskStatusForm.validate_on_submit():
|
|
|
|
jobID = taskStatusForm.jobID.data
|
|
|
|
import mysql.connector as con
|
|
|
|
mycon = con.connect(host=app.config['DB_HOST'],user=app.config['DB_USER'],password=app.config['DB_PASSWORD'],port=app.config['DB_PORT'],database=app.config['DB_NAME'])
|
|
|
|
mycursor = mycon.cursor()
|
2020-08-30 12:15:47 +01:00
|
|
|
sqlQuery = 'select id, protein_name, ligand_name, date, description, done, pdb from curieweb where id="%s"' % (jobID)
|
2020-07-07 17:50:03 +01:00
|
|
|
mycursor.execute(sqlQuery)
|
|
|
|
records = mycursor.fetchall()
|
|
|
|
if records == []:
|
|
|
|
return render_template('job_status_error.html',job=jobID)
|
2020-07-07 18:01:15 +01:00
|
|
|
r = records[0]
|
|
|
|
protein_name = r[1]
|
|
|
|
ligand_name = r[2]
|
|
|
|
date = r[3]
|
|
|
|
description = r[4]
|
|
|
|
done = r[5]
|
|
|
|
if done==1:
|
|
|
|
done="Completed"
|
|
|
|
elif done==0:
|
|
|
|
done="Queued"
|
2020-08-30 12:15:47 +01:00
|
|
|
if protein_name == None:
|
|
|
|
protein_name = r[6]
|
2020-09-10 08:09:26 +01:00
|
|
|
|
|
|
|
PDFReport = "./app/static/uploads/reports/" + str(jobID) + ".pdf"
|
2020-08-30 17:54:16 +01:00
|
|
|
AndroidModel = "/static/uploads/3DModels/" + str(jobID) + ".gltf"
|
|
|
|
iOSModel = "/static/uploads/3DModels/" + str(jobID) + ".usdz"
|
2020-08-30 12:15:47 +01:00
|
|
|
|
2020-08-30 17:54:16 +01:00
|
|
|
return render_template('job_status.html',ID=jobID,pn=protein_name,ln=ligand_name,subDate=date,desc=description,status=done,PDFReport=PDFReport,AndroidModel=AndroidModel,iOSModel=iOSModel)
|
2020-07-07 17:50:03 +01:00
|
|
|
flash_errors(taskStatusForm)
|
|
|
|
return render_template('job_status_form.html',form=taskStatusForm)
|
|
|
|
|
2020-06-24 19:09:05 +01:00
|
|
|
@app.route('/basic-form', methods=['GET', 'POST'])
|
|
|
|
def basic_form():
|
|
|
|
if request.method == 'POST':
|
|
|
|
firstname = request.form['firstname']
|
|
|
|
lastname = request.form['lastname']
|
|
|
|
email = request.form['email']
|
|
|
|
|
|
|
|
return render_template('result.html',
|
|
|
|
firstname=firstname,
|
|
|
|
lastname=lastname,
|
|
|
|
email=email)
|
|
|
|
|
|
|
|
return render_template('form.html')
|
|
|
|
|
|
|
|
@app.route('/wtform', methods=['GET', 'POST'])
|
|
|
|
def wtform():
|
|
|
|
myform = MyForm()
|
|
|
|
|
|
|
|
if request.method == 'POST':
|
|
|
|
if myform.validate_on_submit():
|
|
|
|
# Note the difference when retrieving form data using Flask-WTF
|
|
|
|
# Here we use myform.firstname.data instead of request.form['firstname']
|
|
|
|
firstname = myform.firstname.data
|
|
|
|
lastname = myform.lastname.data
|
|
|
|
email = myform.email.data
|
|
|
|
|
|
|
|
flash('You have successfully filled out the form', 'success')
|
|
|
|
return render_template('result.html', firstname=firstname, lastname=lastname, email=email)
|
|
|
|
|
|
|
|
flash_errors(myform)
|
|
|
|
return render_template('wtform.html', form=myform)
|
|
|
|
|
2020-09-09 20:19:32 +01:00
|
|
|
@app.route('/PDBQTs',methods=['GET','POST'])
|
|
|
|
def generate_pdbqts():
|
|
|
|
myform = generatePDBQTS()
|
|
|
|
|
|
|
|
if request.method == 'POST':
|
|
|
|
if myform.validate_on_submit():
|
|
|
|
pdbId = myform.pdb.data
|
|
|
|
smiles = myform.smiles.data
|
|
|
|
name = myform.name.data
|
|
|
|
if (len(pdbId)==0) and (len(smiles)==0):
|
2020-09-10 07:34:25 +01:00
|
|
|
log("Nothing Submitted!","WARNING")
|
2020-09-09 20:19:32 +01:00
|
|
|
flash("Invalid Submission!",'danger')
|
|
|
|
if len(smiles) != 0:
|
2020-09-10 07:34:25 +01:00
|
|
|
try:
|
|
|
|
import oddt
|
|
|
|
except ImportError:
|
|
|
|
return render_template('error.html',code="OD00",description=errors['OD00'])
|
2020-09-09 20:19:32 +01:00
|
|
|
try:
|
|
|
|
mol = oddt.toolkit.readstring('smi', smiles)
|
|
|
|
except:
|
2020-09-10 07:34:25 +01:00
|
|
|
return render_template('error.html',code="OD01",description=errors['OD01'])
|
2020-09-09 20:19:32 +01:00
|
|
|
try:
|
|
|
|
mol.make3D()
|
|
|
|
mol.calccharges()
|
|
|
|
except:
|
2020-09-10 07:34:25 +01:00
|
|
|
return render_template('error.html',code="OD02",description=errors['OD02'])
|
2020-09-09 20:19:32 +01:00
|
|
|
from oddt.docking.AutodockVina import write_vina_pdbqt
|
|
|
|
|
|
|
|
try:
|
|
|
|
write_vina_pdbqt(mol,'app',flexible=False)
|
|
|
|
except:
|
2020-09-10 07:34:25 +01:00
|
|
|
return render_template('error.html',code="OD03",description=errors['OD03'])
|
2020-09-09 20:19:32 +01:00
|
|
|
path = ".pdbqt"
|
|
|
|
if ".pdbqt" in name:
|
|
|
|
fname = name
|
|
|
|
else:
|
|
|
|
fname = name + ".pdbqt"
|
|
|
|
return send_file(path,attachment_filename=fname,as_attachment=True)
|
|
|
|
if len(pdbId) != 0:
|
2020-09-10 07:34:25 +01:00
|
|
|
try:
|
|
|
|
from plip.basic import config
|
|
|
|
except ImportError:
|
|
|
|
return render_template('error.html',code="PL00",description=errors['PL00'])
|
2020-09-09 20:19:32 +01:00
|
|
|
from plip.exchange.webservices import fetch_pdb
|
|
|
|
from plip.structure.preparation import create_folder_if_not_exists, extract_pdbid
|
|
|
|
from plip.structure.preparation import tilde_expansion, PDBComplex
|
|
|
|
|
|
|
|
try:
|
|
|
|
pdbfile, pdbid = fetch_pdb(pdbId.lower())
|
|
|
|
except:
|
2020-09-10 07:34:25 +01:00
|
|
|
return render_template('error.html',code="PL01",description=errors['PL01'])
|
2020-09-09 20:19:32 +01:00
|
|
|
pdbpath = tilde_expansion('%s/%s.pdb' % (config.BASEPATH.rstrip('/'), pdbid))
|
|
|
|
create_folder_if_not_exists(config.BASEPATH)
|
|
|
|
with open(pdbpath, 'w') as g:
|
|
|
|
g.write(pdbfile)
|
2020-09-10 07:34:25 +01:00
|
|
|
try:
|
|
|
|
import oddt
|
|
|
|
except:
|
|
|
|
return render_template('error.html',code="OD00",description=errors['OD00'])
|
2020-09-09 20:19:32 +01:00
|
|
|
from oddt.docking.AutodockVina import write_vina_pdbqt
|
|
|
|
try:
|
|
|
|
receptor = next(oddt.toolkit.readfile("pdb",pdbpath.split("./")[1]))
|
|
|
|
receptor.calccharges()
|
|
|
|
except Exception:
|
|
|
|
receptor = next(oddt.toolkits.rdk.readfile("pdb",pdbpath.split("./")[1]))
|
|
|
|
receptor.calccharges()
|
|
|
|
|
|
|
|
try:
|
|
|
|
path = write_vina_pdbqt(receptor,'app',flexible=False)
|
|
|
|
except:
|
2020-09-10 07:34:25 +01:00
|
|
|
return render_template('error.html',code="OD03",description=errors['OD03'])
|
2020-09-09 20:19:32 +01:00
|
|
|
os.rename(path,"app/.pdbqt")
|
|
|
|
path = ".pdbqt"
|
|
|
|
fname = pdbId.upper() + ".pdqbt"
|
|
|
|
return send_file(path,attachment_filename=fname,as_attachment=True)
|
|
|
|
flash_errors(myform)
|
|
|
|
return render_template('pdbqt_form.html',form=myform)
|
|
|
|
|
|
|
|
|
2020-09-10 08:09:26 +01:00
|
|
|
tfWorking = 0
|
2020-09-10 07:55:30 +01:00
|
|
|
if app.config['LSTM']:
|
2020-08-06 07:51:31 +01:00
|
|
|
try:
|
2020-09-10 07:55:30 +01:00
|
|
|
import tensorflow as tf
|
2020-08-06 07:51:31 +01:00
|
|
|
tfWorking = 1
|
2020-09-10 07:34:25 +01:00
|
|
|
except Exception as e:
|
|
|
|
log(e,"EXCEPTION")
|
2020-08-06 07:51:31 +01:00
|
|
|
tfWorking = 0
|
2020-08-04 17:09:26 +01:00
|
|
|
|
|
|
|
if tfWorking == 1:
|
2020-07-31 17:49:38 +01:00
|
|
|
from lstm_chem.utils.config import process_config
|
|
|
|
from lstm_chem.model import LSTMChem
|
|
|
|
from lstm_chem.generator import LSTMChemGenerator
|
|
|
|
config = process_config("app/prod/config.json")
|
|
|
|
modeler = LSTMChem(config, session="generate")
|
|
|
|
gen = LSTMChemGenerator(modeler)
|
2020-09-10 07:34:25 +01:00
|
|
|
log("Heating up model","INFO")
|
2020-07-31 17:49:38 +01:00
|
|
|
gen.sample(1)
|
|
|
|
|
|
|
|
@app.route('/Generate', methods=['GET','POST'])
|
|
|
|
def generate():
|
|
|
|
"""Generate novel drugs"""
|
|
|
|
form = generateSMILES()
|
|
|
|
|
|
|
|
with open("./app/prod/config.json") as config:
|
|
|
|
import json
|
|
|
|
j = json.loads(config.read())
|
2020-09-10 07:34:25 +01:00
|
|
|
log(("Model Name:", j["exp_name"]),"INFO")
|
2020-08-01 11:04:22 +01:00
|
|
|
|
2020-07-31 17:49:38 +01:00
|
|
|
|
|
|
|
if request.method == 'POST' and form.validate_on_submit():
|
2020-09-10 07:34:25 +01:00
|
|
|
log(tfWorking,"DEBUG")
|
2020-08-04 17:09:26 +01:00
|
|
|
if tfWorking == 0:
|
2020-09-10 07:34:25 +01:00
|
|
|
log("Failed to initialise model","DANGER")
|
2020-08-04 17:09:26 +01:00
|
|
|
flash("Failed to initialise the model!","danger")
|
|
|
|
else:
|
2020-08-06 07:51:31 +01:00
|
|
|
result = gen.sample(form.n.data)
|
2020-08-04 17:09:26 +01:00
|
|
|
return render_template('generate.html',expName=j["exp_name"],epochs=j["num_epochs"],optimizer=j["optimizer"].capitalize(), form=form,result=result)
|
2020-07-31 17:49:38 +01:00
|
|
|
|
|
|
|
return render_template('generate.html',expName=j["exp_name"],epochs=j["num_epochs"],optimizer=j["optimizer"].capitalize(), form=form)
|
2020-06-24 19:09:05 +01:00
|
|
|
|
2020-07-13 14:26:13 +01:00
|
|
|
@app.route('/Dock', methods=['GET', 'POST'])
|
2020-06-24 19:09:05 +01:00
|
|
|
def dock_upload():
|
|
|
|
form = curieForm()
|
|
|
|
|
|
|
|
if request.method == 'POST' and form.validate_on_submit():
|
2020-09-10 07:34:25 +01:00
|
|
|
log(("Recieved task: ",form.description.data),"DEBUG")
|
2020-06-24 19:09:05 +01:00
|
|
|
description = form.description.data
|
|
|
|
target = form.target.data
|
2020-07-03 12:39:05 +01:00
|
|
|
ligand = form.ligand.data
|
|
|
|
cx,cy,cz = str(form.center_x.data), str(form.center_y.data), str(form.center_z.data)
|
|
|
|
sx,sy,sz = str(form.size_x.data), str(form.size_y.data), str(form.size_z.data)
|
|
|
|
email = form.email.data
|
|
|
|
|
|
|
|
import mysql.connector as con
|
2020-07-06 14:26:16 +01:00
|
|
|
mycon = con.connect(host=app.config['DB_HOST'],user=app.config['DB_USER'],password=app.config['DB_PASSWORD'],port=app.config['DB_PORT'],database=app.config['DB_NAME'])
|
2020-07-03 12:39:05 +01:00
|
|
|
mycursor = mycon.cursor()
|
2020-07-06 14:26:16 +01:00
|
|
|
|
|
|
|
import tempfile
|
|
|
|
with tempfile.TemporaryDirectory() as directory:
|
|
|
|
os.chdir(directory)
|
|
|
|
target.save(secure_filename(target.filename))
|
|
|
|
ligand.save(secure_filename(ligand.filename))
|
|
|
|
buffer = "center_x="+cx+"\ncenter_y="+cy+"\ncenter_z="+cz+"\nsize_x="+sx+"\nsize_y="+sy+"\nsize_z="+sz
|
2020-07-07 08:10:28 +01:00
|
|
|
with open("config.txt","w") as f:
|
|
|
|
f.write(buffer)
|
2020-07-06 14:26:16 +01:00
|
|
|
ligandB = convertToBinaryData(secure_filename(ligand.filename))
|
|
|
|
receptor = convertToBinaryData(secure_filename(target.filename))
|
|
|
|
config = convertToBinaryData("config.txt")
|
|
|
|
ligandName = secure_filename(ligand.filename)
|
|
|
|
receptorName = secure_filename(target.filename)
|
|
|
|
sqlQuery = "insert into curieweb (id, email, protein, protein_name, ligand_pdbqt, ligand_name,date, description, config) values (%s,%s,%s,%s,%s,%s,CURDATE(),%s,%s) "
|
|
|
|
jobID = gen_word(16, 1, 1)
|
2020-09-10 07:34:25 +01:00
|
|
|
log(("Submitted JobID: ",jobID),"DEBUG")
|
2020-07-06 14:26:16 +01:00
|
|
|
insert_tuple = (jobID,email,receptor,receptorName,ligandB,ligandName,description,config)
|
|
|
|
mycursor.execute(sqlQuery,insert_tuple)
|
|
|
|
mycon.commit()
|
|
|
|
|
2020-09-10 07:34:25 +01:00
|
|
|
log(("Description",description),"DEBUG")
|
2020-09-02 13:45:21 +01:00
|
|
|
cwd = os.path.join(os.getcwd(),"app")
|
2020-09-10 07:34:25 +01:00
|
|
|
if app.config['INSTANT_EXEC']:
|
|
|
|
subprocess.Popen(['python3', 'dock-docker.py'],cwd=cwd)
|
2020-07-06 14:26:16 +01:00
|
|
|
return render_template('display_result.html', filename="OwO", description=description,job=jobID)
|
2020-06-24 19:09:05 +01:00
|
|
|
|
|
|
|
flash_errors(form)
|
|
|
|
return render_template('dock_upload.html', form=form)
|
|
|
|
|
2020-08-29 14:55:45 +01:00
|
|
|
@app.route('/Dock-Single', methods=['GET', 'POST'])
|
|
|
|
def dock_upload_single():
|
|
|
|
form = dockSingleForm()
|
|
|
|
|
|
|
|
if request.method == 'POST' and form.validate_on_submit():
|
2020-09-10 07:34:25 +01:00
|
|
|
log(("Recieved task: ",form.description.data),"DEBUG")
|
2020-08-29 14:55:45 +01:00
|
|
|
description = form.description.data
|
|
|
|
pdb = form.pdbID.data
|
|
|
|
smile = form.smiles.data
|
|
|
|
name = form.name.data
|
|
|
|
email = form.email.data
|
|
|
|
|
|
|
|
import mysql.connector as con
|
|
|
|
mycon = con.connect(host=app.config['DB_HOST'],user=app.config['DB_USER'],password=app.config['DB_PASSWORD'],port=app.config['DB_PORT'],database=app.config['DB_NAME'])
|
|
|
|
mycursor = mycon.cursor()
|
|
|
|
|
|
|
|
sqlQuery = "insert into curieweb (id, email, pdb, ligand_smile, ligand_name, date, description) values (%s,%s,%s,%s,%s,CURDATE(),%s) "
|
|
|
|
jobID = gen_word(16, 1, 1)
|
|
|
|
|
|
|
|
insert_tuple = (jobID,email,pdb,smile,name,description)
|
|
|
|
mycursor.execute(sqlQuery,insert_tuple)
|
|
|
|
mycon.commit()
|
|
|
|
|
2020-09-10 07:34:25 +01:00
|
|
|
log(("Description",description),"DEBUG")
|
2020-08-29 14:55:45 +01:00
|
|
|
|
|
|
|
cwd = os.path.join(os.getcwd(),"app")
|
2020-09-10 07:34:25 +01:00
|
|
|
if app.config['INSTANT_EXEC']:
|
|
|
|
subprocess.Popen(['python3', 'dock-single.py'],cwd=cwd)
|
2020-08-29 14:55:45 +01:00
|
|
|
|
|
|
|
return render_template('display_result.html', filename="OwO", description=description,job=jobID)
|
|
|
|
|
|
|
|
flash_errors(form)
|
|
|
|
return render_template('dock_upload_single.html', form=form)
|
|
|
|
|
2020-06-24 19:09:05 +01:00
|
|
|
###
|
|
|
|
# The functions below should be applicable to all Flask apps.
|
|
|
|
###
|
|
|
|
|
|
|
|
# Flash errors from the form if validation fails
|
|
|
|
def flash_errors(form):
|
|
|
|
for field, errors in form.errors.items():
|
|
|
|
for error in errors:
|
|
|
|
flash(u"Error in the %s field - %s" % (
|
|
|
|
getattr(form, field).label.text,
|
|
|
|
error
|
|
|
|
), 'danger')
|
|
|
|
|
|
|
|
@app.route('/<file_name>.txt')
|
|
|
|
def send_text_file(file_name):
|
|
|
|
"""Send your static text file."""
|
|
|
|
file_dot_text = file_name + '.txt'
|
|
|
|
return app.send_static_file(file_dot_text)
|
|
|
|
|
|
|
|
|
|
|
|
@app.after_request
|
|
|
|
def add_header(response):
|
|
|
|
"""
|
|
|
|
Add headers to both force latest IE rendering engine or Chrome Frame,
|
|
|
|
and also to cache the rendered page for 10 minutes.
|
|
|
|
"""
|
|
|
|
response.headers['X-UA-Compatible'] = 'IE=Edge,chrome=1'
|
|
|
|
response.headers['Cache-Control'] = 'public, max-age=0'
|
|
|
|
return response
|
|
|
|
|
|
|
|
|
|
|
|
@app.errorhandler(404)
|
|
|
|
def page_not_found(error):
|
|
|
|
"""Custom 404 page."""
|
|
|
|
return render_template('404.html'), 404
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
app.run(debug=True, host="0.0.0.0", port="8080")
|