-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTwitterTimeline.py
More file actions
72 lines (54 loc) · 1.57 KB
/
TwitterTimeline.py
File metadata and controls
72 lines (54 loc) · 1.57 KB
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
71
# coding: utf-8
# In[1]:
import tweepy
from tweepy import OAuthHandler
import codecs
from time import time, sleep
# In[2]:
consumer_key = 'jmCRzWWRZjuhNo5Q2gHUXpOGd'
consumer_secret = '1wxvlRAjjRcP9TIuE2wnI7LlJ32pkxEc21wMkghMULNLCtKUyD'
access_token = '794344198312849408-vknnh03URiVLo4ijoNGYxYN7ZAmjYxB'
access_secret = 'PxWES0uBWpw7EcEv7IhG18kWn9yB8Kqsmwn6GbfwMRhrH'
# In[3]:
auth = OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_secret)
api = tweepy.API(auth)
buf = set()
listword = []
listusername = []
listuserad = []
# In[4]:
def writefile():
global buf
global listword
global listusername
global listuserad
with codecs.open('Text.txt', 'a+', "utf-8") as f:
for i in range(0,len(listword)):
f.write(listusername[i]+ ",;," +listuserad[i]+ ",;," +listword[i]+ u";,;");
buf = set()
if(len(listword)>0):
buf.add(listword[len(listword)-1])
listword = []
listusername = []
listuserad = []
def trusty_sleep(n):
start = time()
while (time() - start <= n):
sleep(3)
# In[6]:
while True:
try:
for status in tweepy.Cursor(api.home_timeline).items(400):
if(status.text not in buf):
buf.add(status.text)
listword.append(status.text)
listusername.append(status.user.name)
listuserad.append(status.user.screen_name)
else:
break
writefile()
trusty_sleep(15 * 60)
except:
writefile()
trusty_sleep(15 * 60)