]> projects.mako.cc - twitter-api-cdsw/blob - twitter4.py
918b565b37fa8af34b11efd8339c5f6dcf25c0a5
[twitter-api-cdsw] / twitter4.py
1 import encoding_fix
2 import tweepy
3 from twitter_authentication import CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET
4
5 auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
6 auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
7
8 api = tweepy.API(auth)
9
10 # code to write the file
11 import codecs
12 output_file = codecs.open("MY_DATA.tsv", "w", "utf-8")
13
14 public_tweets = api.search("data science", count=10)
15
16 for tweet in public_tweets:
17     print(tweet.user.screen_name + "\t" + str(tweet.created_at) + "\t" + tweet.text, file=output_file)
18

Benjamin Mako Hill || Want to submit a patch?