2021-03-11 14:55:58 +01:00
|
|
|
import os
|
2021-03-11 13:32:50 +01:00
|
|
|
|
2021-03-11 14:55:58 +01:00
|
|
|
from flask import Flask, abort, redirect, render_template, request, url_for
|
|
|
|
from werkzeug.utils import secure_filename
|
2021-03-11 13:32:50 +01:00
|
|
|
|
|
|
|
app = Flask(__name__)
|
2021-03-11 14:55:58 +01:00
|
|
|
app.config["MAX_CONTENT_LENGTH"] = 1024 * 1024
|
|
|
|
app.config["UPLOAD_EXTENSIONS"] = [".csv"]
|
2021-03-11 15:06:33 +01:00
|
|
|
app.config["UPLOAD_PATH"] = "/tmp"
|
2021-03-11 13:32:50 +01:00
|
|
|
|
|
|
|
|
|
|
|
@app.route("/")
|
|
|
|
def index():
|
2021-03-11 14:55:58 +01:00
|
|
|
return render_template("index.html")
|
|
|
|
|
|
|
|
|
|
|
|
@app.route("/", methods=["POST"])
|
|
|
|
def upload_file():
|
|
|
|
uploaded_file = request.files["file"]
|
|
|
|
filename = secure_filename(uploaded_file.filename)
|
|
|
|
|
|
|
|
if filename != "":
|
|
|
|
file_ext = os.path.splitext(filename)[1]
|
|
|
|
if file_ext not in app.config["UPLOAD_EXTENSIONS"]:
|
|
|
|
abort(400)
|
|
|
|
|
|
|
|
uploaded_file.save(os.path.join(app.config["UPLOAD_PATH"], filename))
|
|
|
|
|
|
|
|
return redirect(url_for("index"))
|
2021-03-11 13:32:50 +01:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
app.run(host="127.0.0.1", port=8080, debug=True)
|