Skip to content

Instantly share code, notes, and snippets.

@sonkm3
Last active December 10, 2015 19:38
Show Gist options
  • Save sonkm3/4482584 to your computer and use it in GitHub Desktop.
Save sonkm3/4482584 to your computer and use it in GitHub Desktop.
python: fetch tweets by tweepy's Cursor but this stops before it reaches the end..
# -*- coding: utf-8 -*-
import tweepy
consumer_token = ''
consumer_secret = ''
access_token = ''
access_secret = ''
def get_tweets(api, screen_name):
for tweet in tweepy.Cursor(api.user_timeline, screen_name = screen_name).items():
yield tweet
def main():
screen_name = sys.argv[1]
auth = tweepy.OAuthHandler(consumer_token, consumer_secret)
auth.set_access_token(access_token, access_secret)
api = tweepy.API(auth_handler=auth)
for tweet in get_tweets(api, screen_name):
print (tweet.id_str + u"\t" + tweet.text + u"\t" + str(tweet.created_at)).encode('utf-8') # print as utf-8 for redirection.
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment