Created
July 15, 2015 00:00
-
-
Save claymcleod/5b583c76649371872e7e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Port of https://gist.github.com/yanofsky/5436496 | |
# He used tweepy, I used python-twitter | |
#!/usr/bin/env python | |
# encoding: utf-8 | |
import csv | |
import twitter | |
api = twitter.Api(consumer_key='', | |
consumer_secret='', | |
access_token_key='', | |
access_token_secret='') | |
def get_all_tweets(screen_name): | |
alltweets = [] | |
new_tweets = api.GetUserTimeline(screen_name=screen_name, count=200) | |
alltweets.extend(new_tweets) | |
oldest = alltweets[-1].id - 1 | |
while len(new_tweets) > 0: | |
new_tweets = api.GetUserTimeline(screen_name=screen_name,count=200,max_id=oldest) | |
alltweets.extend(new_tweets) | |
oldest = alltweets[-1].id - 1 | |
outtweets = [[tweet.id_str, tweet.created_at, tweet.text.encode("utf-8")] for tweet in alltweets] | |
with open('%s_tweets.csv' % screen_name, 'wb') as f: | |
writer = csv.writer(f) | |
writer.writerow(["id","created_at","text"]) | |
writer.writerows(outtweets) | |
pass | |
if __name__ == '__main__': | |
get_all_tweets("J_tsar") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
can i use this for get the timeline of more than 1 acount at a time???