more minor stuff

main
Matt C 2 years ago
parent 776266e8c4
commit 21b8deb5a0

@ -1,5 +1,4 @@
import time, os import os, sys
from datetime import datetime
from flask import ( from flask import (
Flask, Flask,
@ -15,7 +14,16 @@ from werkzeug.exceptions import HTTPException
from discord_webhook import DiscordWebhook from discord_webhook import DiscordWebhook
APP_DIST = "Crystal Linux" import yaml
if os.path.exists("settings.yaml"):
settings_obj = yaml.safe_load(open("settings.yaml").read().strip())
APP_DIST = settings_obj["app_dist"]
CAMP_EXTRA = settings_obj["camp_extra"]
else:
print("No 'settings.yaml', exiting")
sys.exit(1)
app = Flask(__name__) app = Flask(__name__)
app.secret_key = "SuperStrongAndComplicated" app.secret_key = "SuperStrongAndComplicated"
@ -37,25 +45,54 @@ def oopsie(e):
def do_stuff(): def do_stuff():
if request.method == "GET": if request.method == "GET":
return render_template( return render_template(
"page.html", dist=APP_DIST, extra=render_template("form.html") "page.html",
dist=APP_DIST,
extra=render_template("form.html", dist=APP_DIST, camp_extra=CAMP_EXTRA),
) )
elif request.method == "POST": elif request.method == "POST":
dtag = request.form["discord-tag"] dtag = request.form["discord-tag"]
feedback = request.form["feedback"] feedback = request.form["feedback"]
if not os.path.exists("data"):
os.makedirs("data") fail = False
if os.path.exists("data/" + dtag):
return "Already submitted" if not "#" in dtag:
fail = True
elif len(dtag.split("#")[1]) != 4:
fail = True
if not fail:
if not os.path.exists("data"):
os.makedirs("data")
if os.path.exists("data/" + dtag):
return render_template(
"page.html",
dist=APP_DIST,
extra="<p style='color:red;'>This user has submitted before.</p>",
)
else:
with open("data/" + dtag, "w") as f:
f.write(feedback)
content = f"User: `{dtag}` submitted the following:\n```{feedback}\n```"
webhook = DiscordWebhook(
url=open(".webhook").read().strip(), content=content
)
response = webhook.execute()
return render_template(
"page.html", dist=APP_DIST, extra="<p>Thanks for your feedback!</p>"
)
else: else:
with open("data/" + dtag, "w") as f: return render_template(
f.write(feedback) "page.html",
content = f"User: `{dtag}` submitted the following:\n```{feedback}\n```" dist=APP_DIST,
webhook = DiscordWebhook(url=open(".webhook").read().strip(), content=content) extra=f"<p style='color:red;'>Funky discord tag you got there: '{dtag}'</p>",
response = webhook.execute() )
return "Thanks!"
else: else:
return "How did we get here?" return "How did we get here?"
if __name__ == "__main__": if __name__ == "__main__":
app.run(host="0.0.0.0", port=9090, debug=True) app.run(
host=settings_obj["host"],
port=settings_obj["port"],
debug=settings_obj["debug"],
)

@ -1,4 +1,5 @@
Flask[async] Flask[async]
gunicorn gunicorn
Flask-Limiter Flask-Limiter
discord-webhook discord-webhook
pyyaml

@ -0,0 +1,5 @@
app_dist: "Crystal Linux"
camp_extra: "Please note that this particular event is only able to ship to the US and Canada."
host: "0.0.0.0"
port: 9090
debug: true

@ -3,9 +3,10 @@
<input type='text' name='discord-tag'/> <input type='text' name='discord-tag'/>
<br/> <br/>
<h3>Feedback: </h3> <h3>Feedback: </h3>
<textarea name='feedback'> <textarea name='feedback' rows="5">
What do you like, or dislike, about Crystal Linux, and how can we make it better? :) What do you like, or dislike, about {{dist}}, and how can we make it better? :)
</textarea> </textarea>
<br/> <br/><br/>
<p>{{camp_extra}}</p>
<button type='submit' class="btn btn-primary">Register</button> <button type='submit' class="btn btn-primary">Register</button>
</form> </form>

@ -23,6 +23,7 @@
</head> </head>
<body> <body>
<h1>{{dist}} - SimpleFeedback</h1> <h1>{{dist}} - SimpleFeedback</h1>
<p>Worried about our usage of your data? Don't be, this program is <a href="https://github.com/crystal-linux/simplefeedback">open source</a>. :)</p>
{{extra|safe}} {{extra|safe}}

Loading…
Cancel
Save