Beispiel #1
0
def upload_file():
	if request.method == 'POST':
		file = request.files['file']
		if file and allowed_file(file.filename):
			filename = secure_filename(file.filename)
			file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
			validate.validation(filename)
			parse.parse_file(filename)
			flash('Successfully uploaded %s' % filename)
			return redirect(url_for('upload_file'))
		else:
			flash('Invalid file format: %s' % file.filename)
			return redirect(url_for('upload_file'))			
	else:
		files = notify.get_files(UPLOAD_FOLDER)
		return render_template('upload.html', files=files)
		return redirect(url_for('upload_file'))
Beispiel #2
0
def upload_file():
    if request.method == 'POST':
        file = request.files['file']
        if file and allowed_file(file.filename):
            filename = secure_filename(file.filename)
            file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
            validate.validation(filename)
            parse.parse_file(filename)
            flash('Successfully uploaded %s' % filename)
            return redirect(url_for('upload_file'))
        else:
            flash('Invalid file format: %s' % file.filename)
            return redirect(url_for('upload_file'))
    else:
        files = notify.get_files(UPLOAD_FOLDER)
        return render_template('upload.html', files=files)
        return redirect(url_for('upload_file'))
Beispiel #3
0
def upload_file():
    if request.method == "POST":
        file = request.files["file"]
        # logging.basicConfig(format='%(asctime)s %(message)s')
        # logging.warning('is when the check file has to start.')
        if file and allowed_file(file.filename):

            logging.basicConfig(format="%(asctime)s %(message)s")
            logging.warning("is when the check file is done.")

            filename = secure_filename(file.filename)

            file.save(os.path.join(app.config["UPLOAD_FOLDER"], filename))

            logging.basicConfig(format="%(asctime)s %(message)s")
            logging.warning("is the cleaning of data has to start.")
            validate.validation(filename)
            logging.basicConfig(format="%(asctime)s %(message)s")
            logging.warning("is when the cleaning of data is done.")

            logging.basicConfig(format="%(asctime)s %(message)s")
            logging.warning("is when the parsing process has to start (transform to JSON).")
            json_filename = parse.parse_file(filename)
            logging.basicConfig(format="%(asctime)s %(message)s")
            logging.warning("is when the parsing process (transform to JSON) is done.")

            print(session["userId"])

            logging.basicConfig(format="%(asctime)s %(message)s")
            logging.warning("is when the data storage process has to start.")

            collectionName = "Customer_" + session["userId"]
            customerDB = connection.get_collection(collectionName)
            transactionsDB = customerDB["Transactions"]
            print(transactionsDB)
            input_file = open(json_filename)
            for line in input_file:
                transactionsDB.insert(json.loads(line))
            flash("Successfully uploaded %s" % filename)

            logging.basicConfig(format="%(asctime)s %(message)s")
            logging.warning("is when the data storage process is done.")
            return redirect(url_for("upload_file"))
        else:
            flash("Invalid file %s" % file.filename)
            return redirect(url_for("upload_file"))
    else:
        files = notify.get_files(app.config["UPLOAD_FOLDER"])
        return render_template("upload.html", files=files)
        return redirect(url_for("upload_file"))