-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
36 lines (28 loc) · 1.08 KB
/
app.py
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
from textwrap import dedent
from flask import Flask, render_template, request, jsonify
from flask_socketio import SocketIO
from todotxt import Todo
app = Flask(__name__)
socketio = SocketIO(app)
@app.route('/', methods=['GET'])
def index():
task = Todo.from_lines(open('todo.txt', encoding='utf8').read())
return render_template('index.html', task=task)
@app.route('/api/v1/todos', methods=['GET', 'POST'])
def todos():
task = Todo.from_lines(open('todo.txt', encoding='utf8').read())
if 'POST' == request.method:
task.json = request.json
with open('todo.txt', encoding='utf8', mode='w') as f:
f.write(str(task))
return jsonify(dict(json=task.json, txt=str(task)))
"""
https://flask-socketio.readthedocs.io/en/latest/
Login: need to be authenticated against the webapp, protect via decorator
Later: Multi-User: each user talks to a 'pad' url that represents one taskboard, use rooms to organize this
"""
@socketio.on('update_todo')
def update_todo(json):
print('received json: ' + str(json))
if __name__ == '__main__':
socketio.run(app)