nyxsite/site/app.py

37 lines
830 B
Python
Raw Normal View History

2025-02-23 22:42:00 -06:00
#!/usr/bin/env python
2025-02-23 22:55:49 -06:00
from flask import Flask, render_template, make_response
2025-02-23 22:42:00 -06:00
app = Flask(__name__)
2025-02-23 23:10:49 -06:00
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
2025-02-23 22:42:00 -06:00
@app.route('/')
2025-02-23 22:55:49 -06:00
def index():
2025-02-23 23:10:49 -06:00
increment_visitor_count()
return render_template('index.j2', visitor=get_visitor_count())
2025-02-23 22:55:49 -06:00
@app.route('/assets/index.css')
def indexStyle():
css = render_template('assets/index.css')
response = make_response(css)
response.mimetype = "text/css"
return response
2025-02-23 22:42:00 -06:00
if __name__ == '__main__':
app.run(host="0.0.0.0", port=8080)