-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask1a.py
More file actions
32 lines (22 loc) · 690 Bytes
/
task1a.py
File metadata and controls
32 lines (22 loc) · 690 Bytes
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
import tweepy
import csv
#insert keys
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
api = tweepy.API(auth)
#tweets = api.user_timeline('comprehensive')
status =[]
csvFile = open('result.csv', 'a')
csvWriter = csv.writer(csvFile)
def limit_handled(cursor):
while True:
try:
yield cursor.next()
except tweepy.RateLimitError:
time.sleep(15 * 60)
for tweet in limit_handled(tweepy.Cursor(api.search,q = "comprehensive",since="2017-02-28",until="2017-09-29",lang="en").items(600)):
print(tweet.text)
status.append([tweet.text.encode('utf-8')])
for st in status:
csvWriter.writerow(st)
csvFile.close()