36 lines
830 B
Python
36 lines
830 B
Python
#!/usr/bin/env python
|
|
|
|
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():
|
|
increment_visitor_count()
|
|
return render_template('index.j2', visitor=get_visitor_count())
|
|
|
|
@app.route('/assets/index.css')
|
|
def indexStyle():
|
|
css = render_template('assets/index.css')
|
|
response = make_response(css)
|
|
response.mimetype = "text/css"
|
|
return response
|
|
|
|
if __name__ == '__main__':
|
|
app.run(host="0.0.0.0", port=8080)
|