Add app.py
This commit is contained in:
parent
17c8861c45
commit
f6cd2cb415
29
app.py
Normal file
29
app.py
Normal file
@ -0,0 +1,29 @@
|
||||
from flask import Flask, render_template, request, redirect
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
from discord_lnbits_bot import Base, engine, Config, Plan
|
||||
|
||||
app = Flask(__name__)
|
||||
app.secret_key = os.getenv("FLASK_SECRET")
|
||||
|
||||
Session = sessionmaker(bind=engine)
|
||||
|
||||
@app.route("/", methods=["GET","POST"])
|
||||
def settings():
|
||||
db = Session()
|
||||
if request.method=="POST":
|
||||
# update Config
|
||||
for key in ("discord_token","guild_id","lnbits_url","lnbits_api_key"):
|
||||
cfg = db.get(Config, key)
|
||||
cfg.value = request.form.get(key, "")
|
||||
db.commit()
|
||||
return redirect("/")
|
||||
|
||||
config_rows = db.query(Config).all()
|
||||
plan_rows = db.query(Plan).all()
|
||||
db.close()
|
||||
return render_template("settings.html", config=config_rows, plans=plan_rows)
|
||||
|
||||
# you can add routes for adding/editing/deleting plans...
|
||||
|
||||
if __name__=="__main__":
|
||||
app.run(host="0.0.0.0", port=3000)
|
Loading…
x
Reference in New Issue
Block a user