Adventure aus DB
This commit is contained in:
parent
8d18c2f8c4
commit
633017b64c
1 changed files with 24 additions and 23 deletions
47
app/app.py
47
app/app.py
|
|
@ -1,36 +1,37 @@
|
||||||
|
from flask import Flask
|
||||||
import os
|
import os
|
||||||
from flask import Flask, redirect, request
|
import sqlite3
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
def get_db():
|
||||||
|
db = sqlite3.connect("adventure.db")
|
||||||
|
db.row_factory = sqlite3.Row
|
||||||
|
return db
|
||||||
|
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
@app.route("/app")
|
@app.route("/app")
|
||||||
@app.route("/app/")
|
@app.route("/app/")
|
||||||
def hello():
|
def start():
|
||||||
return "Willkommen in unserem Escape Room!"
|
return '<h1>Verlies</h1><a href="/app/raum/1">Abenteuer starten</a>'
|
||||||
|
|
||||||
@app.route("/frage", methods=["GET", "POST"])
|
@app.route("/app/raum/<int:id>")
|
||||||
def frage():
|
def raum(id):
|
||||||
if request.method == "POST":
|
db = get_db()
|
||||||
if request.form["antwort"] == "8":
|
r = db.execute("SELECT name, beschreibung FROM raeume WHERE id = ?", (id,)).fetchone()
|
||||||
return "Richtig!"
|
ausgaenge = db.execute(
|
||||||
return "Leider falsch."
|
"SELECT richtung, nach_raum FROM ausgaenge WHERE von_raum = ?", (id,)
|
||||||
return '<form method="post">Was ist 3 + 5? ' \
|
).fetchall()
|
||||||
'<input name="antwort"><button>OK</button></form>'
|
db.close()
|
||||||
|
|
||||||
eintraege = []
|
if r is None:
|
||||||
|
return '<h1>Raum nicht gefunden</h1>'
|
||||||
|
|
||||||
@app.route("/pinnwand", methods=["GET", "POST"])
|
html = "<h1>" + r["name"] + "</h1>"
|
||||||
def pinnwand():
|
html += "<p>" + r["beschreibung"] + "</p>"
|
||||||
if request.method == "POST":
|
for a in ausgaenge:
|
||||||
eintraege.append(request.form["nachricht"])
|
html += '<a href="/app/raum/' + str(a["nach_raum"]) + '">' + a["richtung"] + '</a> '
|
||||||
return redirect("/app/pinnwand")
|
return html
|
||||||
liste = ""
|
|
||||||
for e in eintraege:
|
|
||||||
liste = liste + "<li>" + e + "</li>"
|
|
||||||
return '<h1>Pinnwand</h1>' \
|
|
||||||
'<form method="post"><input name="nachricht">' \
|
|
||||||
'<button>Senden</button></form><ul>' + liste + '</ul>'
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
port = int(os.environ.get("PORT", "9003"))
|
port = int(os.environ.get("PORT", "9003"))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue