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. +
+