ca42/main.py
2024-09-29 01:09:34 +02:00

35 lines
962 B
Python

from flask import Flask, render_template, redirect
import datetime
from textwrap import wrap
app = Flask(__name__);
values = ""
try:
with open("bozo", 'r') as f:
values = f.read()
except:
values = str(datetime.date.today())
with open("bozo", 'w+') as f:
f.write(values)
@app.route("/api/update", methods = ['POST'])
def update():
global values
new_value = str(datetime.date.today())
if new_value not in values:
values += " " + new_value
with open("bozo", 'w+') as f:
f.write(values)
return redirect('/')
@app.route("/", methods = ['GET'])
def normal():
print(values.split(" "))
return render_template('home.html', dates = wrap(values, 10), total = len(values.split(' ')), days = (datetime.datetime.today().date() - datetime.datetime.strptime(values.split(' ')[-1], "%Y-%m-%d").date()).days)
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000, debug=1)