forked from markormesher/noisy-tweets
-
Notifications
You must be signed in to change notification settings - Fork 1
/
flaskserver.py
70 lines (37 loc) · 1.21 KB
/
flaskserver.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
from flask import Flask, render_template
from flask.ext.socketio import SocketIO
# mate
class Mate:
def __init__(self):
pass
def set_keyword(self, k):
self.keyword = k
mate = Mate()
# app setup
app = Flask(__name__)
app.config['SECRET_KEY'] = ''
socketio = SocketIO(app)
@app.route('/noisytweets')
def index():
return render_template('index.html')
# socket setup
@socketio.on('connect', namespace='/noisytweets')
def test_connect():
socketio.emit('connect okay', {'data': 'Connected'}, namespace='/noisytweets')
@socketio.on('disconnect', namespace='/noisytweets')
def test_disconnect():
print('Client disconnected')
@socketio.on('change keyword', namespace='/noisytweets')
def test_disconnect(data):
print('Changing to: ' + data['new_keyword'])
# TODO: figure out how to change the filter
# communication methods
def send_log_message(msg):
socketio.emit('log message', {'msg': msg}, namespace='/noisytweets')
def send_emoji_event(which):
socketio.emit('emoji event', {'which': which}, namespace='/noisytweets')
def send_tweet_event(tweet):
socketio.emit('tweet event', tweet, namespace='/noisytweets')
# done
def start_server():
socketio.run(app)