-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
39 lines (30 loc) · 988 Bytes
/
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
37
38
from gevent import monkey
monkey.patch_all()
import cgi
import redis
from flask import Flask, render_template
from flask_socketio import SocketIO
app = Flask(__name__)
app.config['DEBUG'] = True
db = redis.StrictRedis('localhost', 6379, 0)
socketio = SocketIO(app)
@app.route('/')
def main():
return render_template('main.html')
@app.route('/pymeetups/')
def pymeetups():
return render_template('pymeetups.html')
@socketio.on('connect', namespace='/fgwebsockets')
def ws_conn():
c = db.incr('user_count')
socketio.emit('msg', {'count': c}, namespace="/fgwebsockets")
@socketio.on('disconnect', namespace='/fgwebsockets')
def ws_conn():
c = db.decr('user_count')
socketio.emit('msg', {'count': c}, namespace="/fgwebsockets")
@socketio.on('city', namespace='/fgwebsockets')
def ws_city(message):
socketio.emit('city', {'city': cgi.escape(message['city'])},
namespace='/fgwebsockets')
if __name__ == '__main__':
socketio.run(app)