-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtweet_specific_3.py
67 lines (58 loc) · 2.08 KB
/
tweet_specific_3.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
from __future__ import print_function
import sys,io
from tweepy.streaming import StreamListener
from tweepy import OAuthHandler
from tweepy import Stream
import json
import os,signal
import sys
import time
import gzip
specific=sys.argv[1]
# use my key
#Variables that contains the user credentials to access Twitter API
# access_token = "900801909417791488-ayuvoHwGozmSLypO4c43Y0BJYjEWjga"
# access_token_secret = "K21taY7vVl2cJWsIdooARfVP1FfSHWIHrKs13w655UTiP"
# consumer_key = "XEtyr3gSbLyApjkBUigqtP28w"
# consumer_secret = "bwhi37FkOHSUCbGNeiTdh1oETXDFplwRhy5znMrqG5RWNmFGt0"
access_token="4491264149-V3rYWdTTZdmk02Jc788b4EK2x44LaiS9f5y88dd"
access_token_secret="jgxAMAHrxlzSN8Y28K7hJ7ZbgxKaQ8mkbzsdnFYFZEBIG"
consumer_key="sjBM9K7qOv5r19TvO5AXHk9gy"
consumer_secret="D5r6GZHh2N8mpHuzyZjVCED24ZRYHsQIAD14M31DxYI73CaD7p"
#This is a basic listener that just prints received tweets to stdout.
class StdOutListener(StreamListener):
def __init__(self):
self.count=0
StreamListener.__init__(self)
def on_data(self, data):
self.count=self.count+1
print ("Tweet: "+str(self.count))
day=int((time.time()-start_time)/86400)
#print(day)
filename = "All_Stream_tweets_"+specific+"_"+str(day)+"_"+".txt"
f= open(filename,"a+")
f.write(data)
f.write("\n")
f.close()
def on_error(self, status):
if status==420:
print ("Error")
return False
if __name__ == '__main__':
#This handles Twitter authetification and the connection to Twitter Streaming API
l = StdOutListener()
auth = OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
global start_time
start_time=time.time()
while True:
try:
stream = Stream(auth, l)
stream.filter(track=[str(specific)])
except KeyboardInterrupt:
break
except Exception as e:
pass
'''
[[[68.4228514144,7.841615498],[97.6904295394,7.841615498],[97.6904295394,35.5679807149],[68.4228514144,35.5679807149]]]
'''