50 lines
1.7 KiB
Python
50 lines
1.7 KiB
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('/')
|
|
|
|
def record():
|
|
global values
|
|
tmp = values.split(' ')
|
|
today = datetime.datetime.today()
|
|
longer = 0
|
|
if len(tmp) == 0:
|
|
return 0
|
|
if len(tmp) < 2:
|
|
return abs(datetime.datetime.strptime(tmp[0], "%Y-%m-%d") - today).days
|
|
for i in range(0, len(tmp) - 1):
|
|
if abs((datetime.datetime.strptime(tmp[i], "%Y-%m-%d").date() - datetime.datetime.strptime(tmp[i + 1], "%Y-%m-%d").date()).days) > longer:
|
|
longer = abs((datetime.datetime.strptime(tmp[i], "%Y-%m-%d").date() - datetime.datetime.strptime(tmp[i + 1], "%Y-%m-%d").date()).days)
|
|
if abs((today - datetime.datetime.strptime(tmp[-1], "%Y-%m-%d")).days) > longer:
|
|
longer = abs((today - datetime.datetime.strptime(tmp[-1], "%Y-%m-%d")).days)
|
|
return longer
|
|
|
|
@app.route("/", methods = ['GET'])
|
|
def normal():
|
|
return render_template('home.html', longer = record(), 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)
|