-
Notifications
You must be signed in to change notification settings - Fork 0
/
TwitterGetter.py
50 lines (38 loc) · 1.35 KB
/
TwitterGetter.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
from Classifier import Classifier
cl = Classifier('lists/lovelist.txt', 'lists/hatelist.txt')
def callb(item):
str = item['text']
print str
print cl.classify(str)
print '\n'
class TwitterGetter(object):
def __init__(self):
self.stop = False
self.registerApi()
@property
def headers(self):
return self.api
def registerApi(self):
from TwitterAPI import TwitterAPI
self.api = TwitterAPI("BGMUpePgUoFU13l3NOd26DVUD",
"pmiwqlftwhj6tPEDBzRrxvObSw3E8Kt29PIUo0XjGW60jtpOZO",
"2719912512-l6a59JAHMpbs8s5t72BHLJqL19sCvUluBw9Ewhh",
"1QNsRQKJ6eRTxY9x8HQ3RcdwNd48IF4ywk0MWFI0ILqG7")
def registerCallback(self, callback):
self.callback = callback
def startFlow(self):
r = self.api.request('statuses/filter', {'locations':'-179.1506, 18.9117, -66.9406, 71.4410'})
for item in r.get_iterator():
# if item['coordinates'] != None:
# print item['coordinates']['coordinates']
self.callback(item)
if self.stop : break
def stopFlow(self):
self.stop = True
# Basic usage here:::
if __name__ == "__main__":
tgetter = TwitterGetter()
tgetter.registerApi()
tgetter.registerCallback(callb)
tgetter.startFlow()
# then tgetter.stopFlow()