+ max_id = tweet['id']
+ n_tweets += 1
+ return n_tweets, max_id
+
+def main(args=sys.argv[1:]):
+ oauth_filename = OPTIONS['oauth_filename']
+ oauth_token, oauth_token_secret = read_token_file(oauth_filename)
+
+ twitter = Twitter(
+ auth=OAuth(
+ oauth_token, oauth_token_secret, CONSUMER_KEY, CONSUMER_SECRET),
+ api_version='1',
+ domain='api.twitter.com')
+
+ if args:
+ max_id = args[0]
+ else:
+ max_id = None
+
+ n_tweets = 0
+ while True:
+ try:
+ tweets_processed, max_id = get_tweets(twitter, max_id)
+ n_tweets += tweets_processed
+ log_debug("Processed %i tweets (max_id %s)" %(n_tweets, max_id))
+ if tweets_processed == 0:
+ log_debug("That's it, we got all the tweets. Done.")
+ break
+ except TwitterError, e:
+ log_debug("Twitter bailed out. I'm going to sleep a bit then try again")
+ sleep(3)