-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgetTweets.py
44 lines (36 loc) · 1010 Bytes
/
getTweets.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
from subprocess import call
from threading import Thread
def getTweets(movieName, rating):
outFileName = "{}.txt".format(rating+movieName)
query = "\\\"{}\\\" movie".format(movieName)
print query
try:
call(["java", "-jar", "GetTweets-1.0-SNAPSHOT-jar-with-dependencies.jar", "querysearch={}".format(query), "maxtweets=2000", outFileName])
except:
print 'jar problem'
def readList():
# threadList = []
with open('list.txt','r') as f:
threadList = []
for line in f:
words = line.split()
if len(words) == 0:
break;
movieName = " ".join(words[0:len(words)-1])
rating = words[len(words)-1]
print rating
t = Thread(target=getTweets, args=(movieName, rating))
threadList.append(t)
t.start()
if len(threadList) >= 15:
print "waiting for workers"
for t in threadList:
t.join()
threadList = []
print "start {}".format(movieName)
if len(threadList) > 0:
for t in threadList:
t.join()
print "finish"
if __name__ == '__main__':
readList()