csv-metadata-quality-web/main.py
Alan Orth 4f1d6fad38
main.py: Import csv_metadata_quality
Now I understand how I can use this, for example to print the vers-
ion of the CLI tool in the HTML template.
2021-03-11 20:29:43 +02:00

35 lines
947 B
Python

import os
from csv_metadata_quality.version import VERSION as cli_version
from flask import Flask, abort, redirect, render_template, request, url_for
from werkzeug.utils import secure_filename
app = Flask(__name__)
app.config["MAX_CONTENT_LENGTH"] = 1024 * 1024
app.config["UPLOAD_EXTENSIONS"] = [".csv"]
app.config["UPLOAD_PATH"] = "/tmp"
@app.route("/")
def index():
return render_template("index.html", cli_version=cli_version)
@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"))
if __name__ == "__main__":
app.run(host="127.0.0.1", port=8080, debug=True)