support multiple date

This commit is contained in:
starnakin 2024-09-13 00:58:49 +02:00
parent 0f02669f5c
commit dfec19b341
2 changed files with 17 additions and 12 deletions

23
main.py
View File

@ -1,30 +1,33 @@
from flask import Flask, render_template, redirect
import datetime
from textwrap import wrap
app = Flask(__name__);
last_value: str
values = ""
try:
with open("bozo", 'r') as f:
last_value: str = f.read()
values = f.read()
except:
values = str(datetime.date.today())
with open("bozo", 'w+') as f:
last_value = str(datetime.date.today())
f.write(last_value)
f.write(values)
@app.route("/api/update", methods = ['POST'])
def update():
last_value = str(datetime.date.today())
print(last_value)
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(last_value)
return render_template('home.html', date = last_value)
f.write(values)
return redirect('/')
@app.route("/", methods = ['GET'])
def normal():
print(last_value)
return render_template('home.html', date = last_value)
print(values.split(" "))
return render_template('home.html', dates = wrap(values, 10))
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000, debug=1)

View File

@ -6,7 +6,9 @@
</head>
<body>
<h1>Ca42</h1>
{% for date in dates %}
<h1>{{date}}</h1>
{% endfor %}
<form action="/api/update" method="post">
<button name="foo" value="upvote">Upvote</button>
</form>