forked from starnakin/ca42
support multiple date
This commit is contained in:
parent
0f02669f5c
commit
dfec19b341
23
main.py
23
main.py
@ -1,30 +1,33 @@
|
|||||||
from flask import Flask, render_template, redirect
|
from flask import Flask, render_template, redirect
|
||||||
import datetime
|
import datetime
|
||||||
|
from textwrap import wrap
|
||||||
|
|
||||||
app = Flask(__name__);
|
app = Flask(__name__);
|
||||||
|
|
||||||
last_value: str
|
values = ""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open("bozo", 'r') as f:
|
with open("bozo", 'r') as f:
|
||||||
last_value: str = f.read()
|
values = f.read()
|
||||||
except:
|
except:
|
||||||
|
values = str(datetime.date.today())
|
||||||
with open("bozo", 'w+') as f:
|
with open("bozo", 'w+') as f:
|
||||||
last_value = str(datetime.date.today())
|
f.write(values)
|
||||||
f.write(last_value)
|
|
||||||
|
|
||||||
@app.route("/api/update", methods = ['POST'])
|
@app.route("/api/update", methods = ['POST'])
|
||||||
def update():
|
def update():
|
||||||
last_value = str(datetime.date.today())
|
global values
|
||||||
print(last_value)
|
new_value = str(datetime.date.today())
|
||||||
|
if new_value not in values:
|
||||||
|
values += " " + new_value
|
||||||
with open("bozo", 'w+') as f:
|
with open("bozo", 'w+') as f:
|
||||||
f.write(last_value)
|
f.write(values)
|
||||||
return render_template('home.html', date = last_value)
|
return redirect('/')
|
||||||
|
|
||||||
@app.route("/", methods = ['GET'])
|
@app.route("/", methods = ['GET'])
|
||||||
def normal():
|
def normal():
|
||||||
print(last_value)
|
print(values.split(" "))
|
||||||
return render_template('home.html', date = last_value)
|
return render_template('home.html', dates = wrap(values, 10))
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app.run(host='0.0.0.0', port=5000, debug=1)
|
app.run(host='0.0.0.0', port=5000, debug=1)
|
||||||
|
@ -6,7 +6,9 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>Ca42</h1>
|
<h1>Ca42</h1>
|
||||||
|
{% for date in dates %}
|
||||||
<h1>{{date}}</h1>
|
<h1>{{date}}</h1>
|
||||||
|
{% endfor %}
|
||||||
<form action="/api/update" method="post">
|
<form action="/api/update" method="post">
|
||||||
<button name="foo" value="upvote">Upvote</button>
|
<button name="foo" value="upvote">Upvote</button>
|
||||||
</form>
|
</form>
|
||||||
|
Loading…
Reference in New Issue
Block a user