init with copied files from markdown-tagebuch

This commit is contained in:
Marcel Dechert
2022-04-18 22:50:19 +01:00
parent f13e1c88ed
commit 22013a7b3e
11 changed files with 328 additions and 0 deletions

56
rest_server.py Normal file
View File

@@ -0,0 +1,56 @@
import os
import flask
from flask import render_template
from flask import request
from flask import url_for
from flask_cors import CORS
from flask_httpauth import HTTPBasicAuth
from werkzeug.security import check_password_hash
# import main
# from werkzeug.utils import redirect
import config_parser
app = flask.Flask(__name__)
auth = HTTPBasicAuth()
app.config["DEBUG"] = True
CORS(app)
URL_BASE_PATH = "/"
# URL_BASE_PATH = "/tagebuch"
@auth.verify_password
def verify_password(username, password):
if username == config_parser.credentials['username'] and \
check_password_hash(config_parser.credentials['hashedPassword'], password):
return username
@app.route(URL_BASE_PATH + 'home', methods=['GET'])
# @auth.login_required
def api_show_form():
return render_template("index.html")
@app.route(URL_BASE_PATH, methods=['POST', 'GET'])
@auth.login_required
def handle_yt_url():
if request.method == "POST":
user_input = request.form['ytlink']
# return redirect(url_for("return_result", ytlink=user_input))
print(user_input)
return render_template("yt.html")
else:
return render_template("yt.html")
if __name__ == '__main__':
flask_options = dict(
host='0.0.0.0',
debug=True,
port=4001,
threaded=True,
)
app.run(**flask_options)