forked from markormesher/noisy-tweets
-
Notifications
You must be signed in to change notification settings - Fork 1
/
noisytweets.py
49 lines (39 loc) · 1.22 KB
/
noisytweets.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
import json
import thread
import sys
from tweepy.streaming import StreamListener
from tweepy import OAuthHandler
from tweepy import Stream
from config import *
from flaskserver import start_server
from flaskserver import mate
from tweetanalyser import TweetAnalyser
import twilioclient
class StreamHandler(StreamListener):
def __init__(self, analyser):
self._analyser = analyser
def on_data(self, data):
datadict = json.loads(data)
try:
self._analyser.incoming_tweet(datadict['text'])
except KeyError:
# no text - skip
pass
return True
def on_error(self, status):
print status
class NoisyTweets:
def __init__(self, auth, keyword):
mate.set_keyword(keyword)
stream = Stream(auth, StreamHandler(TweetAnalyser()))
stream.filter(track=[keyword])
try:
if __name__ == '__main__':
auth = OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
thread.start_new_thread(start_server, ())
if len(sys.argv) > 2:
twilioclient.make_call(sys.argv[2])
NoisyTweets(auth, sys.argv[1])
except KeyboardInterrupt:
print 'Bye bye!'