def upload(): """ Imports a file and saves to DB :return: """ datafile = request.files['file'] c = MySQL.get_connection(DATABASE) if datafile: try: logfile = os.path.splitext(datafile.filename)[0] + str( int(time.time())) + '.log' # given name + current timestamp f = logging.FileHandler(os.path.join(LOG_DIR, logfile), 'w') Config.setup_logging(f) filepath = os.path.join(UPLOADS_DIR, datafile.filename) datafile.save(filepath) # to file system Importer.run(filepath, c, {"normalization": request.form['normalization']}) logger.removeHandler(f) f.close() return jsonify({"name": datafile.filename, 'log': logfile}) finally: c.close()
def main(): Config.setup_logging() c = MySQL.get_connection('astronomy_test') # run('./Assets/test_inp.txt', c, {"normalization": "Lodders et al. (2009)"}) run('./Assets/exo_test_inp.txt', c, {"normalization": "Lodders et al. (2009)"})