-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path02_user_timeline_twitter.py
More file actions
36 lines (27 loc) · 1.17 KB
/
Copy path02_user_timeline_twitter.py
File metadata and controls
36 lines (27 loc) · 1.17 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
import tweepy
import csv
def search_and_save():
#Fill in your keys, secrets, and tokens from your app created on https://apps.twitter.com/
consumer_key = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
consumer_secret = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
access_token = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
access_token_secret = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
#You can play with different operators using this reference:
# https://dev.twitter.com/docs/using-search
new_tweets = api.user_timeline(
screen_name="buzzfeed",
count=10,
exclude_replies=True,
include_rts=False)
#Create a csv file that stores your time_line search results.
#Change "new_file.csv" if you want to save with differenting file name.
csvFile = open('new_file.csv', 'w')
csvWriter = csv.writer(csvFile)
for tweet in new_tweets:
csvWriter.writerow([tweet.text.encode('utf-8')])
print tweet.created_at, ' ',tweet.text.encode('utf-8')
csvFile.close()
search_and_save()