From 43a6d7d22b93c1432807b3473fb65efeb7deeae0c63c398a7275e6c150d1456d Mon Sep 17 00:00:00 2001 From: Nyx Tutt Date: Sun, 23 Feb 2025 23:10:49 -0600 Subject: [PATCH] visitor counter --- .gitignore | 1 + site/app.py | 19 ++++++++++++++++++- site/templates/index.j2 | 7 ++++++- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 25a1f68..1ba65ad 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ .venv/ +visitorCount.txt diff --git a/site/app.py b/site/app.py index 102b9de..519de07 100644 --- a/site/app.py +++ b/site/app.py @@ -4,9 +4,26 @@ from flask import Flask, render_template, make_response app = Flask(__name__) +countFile = "visitorCount.txt" + +def get_visitor_count(): + try: + with open(countFile, "r") as f: + return int(f.read()) + except FileNotFoundError: + return 0 + +def increment_visitor_count(): + count = get_visitor_count() + count += 1 + with open(countFile, "w") as f: + f.write(str(count)) + return count + @app.route('/') def index(): - return render_template('index.j2') + increment_visitor_count() + return render_template('index.j2', visitor=get_visitor_count()) @app.route('/assets/index.css') def indexStyle(): diff --git a/site/templates/index.j2 b/site/templates/index.j2 index 3970179..a19eab5 100644 --- a/site/templates/index.j2 +++ b/site/templates/index.j2 @@ -9,6 +9,11 @@ +
+

+ hello, visitor number {{ visitor }}! this one is glad to see you. +

+

Nyx Tutt

@@ -32,7 +37,7 @@ matrix
  • - email (it has a pgp key in one of the key servers.)
    + email (it has a pgp key over in keys.openpgp.org.)
  • fedi