def output_data_calculation(): processing_data(request.args['input_full_path'], request.args['output_full_path'], output_fields_name) os.remove(relative_path(request.args['input_full_path'])) return redirect( url_for('display_charts', output_filename=request.args['output_filename']))
def archive(): push_to_online_mongo_db(relative_path(request.args['data_source']), output_fields_name) time.sleep(5) # To let X seconds for the user to read the triggered modal. # Should go for AJAX to avoid rendering the page again. return redirect( url_for('display_charts', output_filename=request.args['data_source'].split("/")[-1]))
def delete_files(): os.remove(relative_path(request.args['data_source'])) session.clear() time.sleep(5) # To let X seconds for the user to read the triggered modal. return redirect("/")
def send_input_example_csv(): return send_file( relative_path(request.args['data_source']), mimetype='text/csv', attachment_filename=request.args['data_source'].split("/")[-1], as_attachment=True)
import os import time from flask import Flask, flash, request, redirect, url_for, render_template, send_file, after_this_request, session from data_input import file_uploading, file_check, get_timestamp from data_output import processing_data from data_tools import relative_path from archive import push_to_online_mongo_db # SETTINGS --------------------------------------------------------------------- # INPUT DATA upload_folder = relative_path('static/data/data_input') input_example_folder = 'static/data/data_input_example' input_example_filename = 'data_input_example.csv' output_folder = 'static/data/data_output' output_example_folder = 'static/data/data_output_example' dlload_folder = relative_path(output_folder) allowed_extensions = set(['csv']) max_file_size = 2 * 1024 * 1024 #2 megabytes # OUTPUT DATA # input_fields_name = ['row','date','q','rain','temp','ETP_dint','peff'] output_fields_name = [ 'row', 'date', 'q', 'rain', 'temp', 'ETP_dint', 'peff', 'baseflow_1', 'baseflow_2', 'baseflow_3' ] # MAIN APP --------------------------------------------------------------------- app = Flask(__name__) app.config['MAX_CONTENT_LENGTH'] = max_file_size app.config['UPLOAD_FOLDER'] = upload_folder app.secret_key = os.environ.get("SECRET_KEY")