-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
62 lines (51 loc) · 1.58 KB
/
Copy pathapp.py
File metadata and controls
62 lines (51 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import os
import uuid
from datetime import datetime as dt
from flask import Flask, render_template, request, redirect, url_for
from boyaki import Boyaki
app = Flask(__name__, static_folder='static')
@app.route('/', methods=['GET'])
def index():
key = dt.now().strftime('%Y-%m-%d')
result = Boyaki.view_index.query(key, scan_index_forward=False)
try:
items = list(result)
except Exception as ex:
items = []
return render_template('index.html', items=items)
@app.route('/create', methods=['POST'])
def create():
boyaki = request.form['boyaki']
if boyaki:
try:
create_data(boyaki)
except Exception as ex:
print('error:', ex)
return redirect(url_for('.index'))
@app.route('/delete/<string:id>')
def delete(id: str) -> None:
print(f'delete: id={id}')
try:
item = Boyaki.get(id)
item.delete()
except Boyaki.DoesNotExist:
print('Boyaki does not exist')
except Exception as ex:
print('error:', ex)
return redirect(url_for('.index'))
def create_data(boyaki: str) -> None:
now = dt.now()
id = str(uuid.uuid4())
date_str = now.strftime('%Y-%m-%d')
time_str = now.strftime('%H:%M:%S')
model = Boyaki(id, boyaki=boyaki, date=date_str, time=time_str)
model.save()
print(f'create: id={id}, boyaki={boyaki}')
if __name__ == '__main__':
try:
if not Boyaki.exists():
Boyaki.create_table(wait=True)
except Exception as ex:
print('error:', ex)
port = int(os.getenv('PORT', 8080))
app.run(host='0.0.0.0', port=port)