From ba9898a44a0b4cad84ba6ce15e6251910c43a0c2 Mon Sep 17 00:00:00 2001 From: csd4ni3l Date: Sun, 10 Aug 2025 16:57:55 +0200 Subject: [PATCH] add new fields to user so we can track grass touching activity later, add part of the application part which currently includes a homepage and a leaderboard --- main.py | 37 ++++++++++++++++++++++++------ templates/app.jinja2 | 44 ++++++++++++++++++++++++++++++++++++ templates/leaderboard.jinja2 | 36 +++++++++++++++++++++++++++++ 3 files changed, 110 insertions(+), 7 deletions(-) create mode 100644 templates/app.jinja2 create mode 100644 templates/leaderboard.jinja2 diff --git a/main.py b/main.py index e41e042..fca1249 100644 --- a/main.py +++ b/main.py @@ -24,6 +24,9 @@ def get_db(): db.execute(""" CREATE TABLE IF NOT EXISTS Users ( username TEXT PRIMARY KEY, + last_grass_touch_time TEXT NOT NULL, + grass_touching_count INT NOT NULL, + banned BOOL, password TEXT NOT NULL, password_salt TEXT NOT NULL ) @@ -53,10 +56,30 @@ def user_loader(user_id): user.id = user_id return user -@app.route("/iamarealpersonwhotouchedgrass") +@app.route("/app") @flask_login.login_required -def iamarealpersonwhotouchedgrass(): - return "You are a real person who touched grass! I can't believe this. You probably just tricked the AI or smth..." +def application(): + username = flask_login.current_user.id + + return render_template("app.jinja2", username=username) + +@app.route("/leaderboard") +@flask_login.login_required +def leaderboard(): + username = flask_login.current_user.id + + cur = get_db().cursor() + + cur.execute("SELECT grass_touching_count, username FROM USERS ORDER BY grass_touching_count DESC, username ASC LIMIT 25") + + users = cur.fetchall() + if not users: + cur.close() + return Response("DB is not healthy.", 401) + + cur.close() + + return render_template("leaderboard.jinja2", users=users, current_username=username) @app.route("/login", methods=["GET", "POST"]) def login(): @@ -83,7 +106,7 @@ def login(): user.id = username flask_login.login_user(user, remember=True) - return redirect(url_for("iamarealpersonwhotouchedgrass")) + return redirect(url_for("application")) else: cur.close() return Response("Unathorized access. Just go outside, touch grass and make your own account...", 401) @@ -112,7 +135,7 @@ def register(): user.id = username flask_login.login_user(user, remember=True) - return redirect(url_for("iamarealpersonwhotouchedgrass")) + return redirect(url_for("application")) def resize_image_file(path, max_side=256, fmt="JPEG"): img = Image.open(path) @@ -175,7 +198,7 @@ def info(): @app.route("/") def main(): if flask_login.current_user.is_authenticated: - return redirect(url_for("iamarealpersonwhotouchedgrass")) + return redirect(url_for("application")) else: return redirect(url_for("login")) @@ -188,4 +211,4 @@ def logout(): def unauthorized_handler(): return redirect("/login") -app.run(port=os.environ.get("PORT"), host=os.environ.get("HOST", "0.0.0.0")) \ No newline at end of file +app.run(debug=True, port=os.environ.get("PORT"), host=os.environ.get("HOST", "0.0.0.0")) \ No newline at end of file diff --git a/templates/app.jinja2 b/templates/app.jinja2 new file mode 100644 index 0000000..899cd82 --- /dev/null +++ b/templates/app.jinja2 @@ -0,0 +1,44 @@ +{% extends "base.jinja2" %} +{% block title %}Grass Touching Dashboard{% endblock %} + +{% block body %} + + +
+
+

Welcome back, {{ username }}

+
Why are you here?
+
Why did you cheat?
+
I know you did!!!
+
No one touches grass!
+
I know you don't go outside you liar!
+
You are a discord moderator who plays League of Legends 24 hours a day!
+
But, if you really want to learn how to go outside and touch grass, check our unofficial guide
+
To prove you belong here, you have to touch grass each day or your account will be permanently banned with no exceptions.
+
To see how you fare against others, check the leaderboard
+
+
+ +{% endblock %} \ No newline at end of file diff --git a/templates/leaderboard.jinja2 b/templates/leaderboard.jinja2 new file mode 100644 index 0000000..bd4b0e3 --- /dev/null +++ b/templates/leaderboard.jinja2 @@ -0,0 +1,36 @@ +{% extends "base.jinja2" %} +{% block title %}Grass Touching Leaderboard{% endblock %} + +{% block body %} + +
+

Leaderboard

+ +
+{% endblock%} \ No newline at end of file