visitor counter

This commit is contained in:
Nyx 2025-02-23 23:10:49 -06:00
parent 2613f185f3
commit 43a6d7d22b
3 changed files with 25 additions and 2 deletions

1
.gitignore vendored
View file

@ -1 +1,2 @@
.venv/ .venv/
visitorCount.txt

View file

@ -4,9 +4,26 @@ from flask import Flask, render_template, make_response
app = Flask(__name__) 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('/') @app.route('/')
def index(): def index():
return render_template('index.j2') increment_visitor_count()
return render_template('index.j2', visitor=get_visitor_count())
@app.route('/assets/index.css') @app.route('/assets/index.css')
def indexStyle(): def indexStyle():

View file

@ -9,6 +9,11 @@
</head> </head>
<body> <body>
<center>
<p>
hello, visitor number <b>{{ visitor }}</b>! this one is glad to see you.
</p>
</center>
<h1> <h1>
Nyx Tutt Nyx Tutt
</h1> </h1>
@ -32,7 +37,7 @@
<a href="matrix:u/n:everypizza.im">matrix</a><br> <a href="matrix:u/n:everypizza.im">matrix</a><br>
</li> </li>
<li> <li>
<a href="mailto:me@everypizza.im">email</a> (it has a pgp key in one of the key servers.)<br> <a href="mailto:me@everypizza.im">email</a> (it has a pgp key over in <a href="https://keys.openpgp.org/search?q=me%40everypizza.im">keys.openpgp.org</a>.)<br>
</li> </li>
<li> <li>
<a href="https://sharkey.everypizza.im">fedi</a><br> <a href="https://sharkey.everypizza.im">fedi</a><br>