-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
33 lines (26 loc) · 880 Bytes
/
app.py
File metadata and controls
33 lines (26 loc) · 880 Bytes
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
from flask import Flask, render_template, request, redirect, url_for, jsonify
from flask_socketio import SocketIO, emit
import logging
app = Flask(__name__)
socketio = SocketIO(app)
people = []
@app.route('/')
def index():
return render_template('index.html')
@app.route('/getPeople', methods=['GET'])
def get_people():
return jsonify(people)
@app.route('/addPerson', methods=['POST'])
def add_person():
person_data = request.json
people.append(person_data)
logging.info(f'Emitting update_people event with data: {people}')
socketio.emit('update_people', people)
return jsonify({'status': 'success', 'person': person_data})
@socketio.on('connect')
def handle_connect():
logging.info('Client connected')
emit('update_people', people)
if __name__ == '__main__':
logging.basicConfig(level=logging.INFO)
socketio.run(app, debug=True)