X-Git-Url: https://jfr.im/git/z_archive/twitter.git/blobdiff_plain/c115f12f63079f7a826cdfa6ca5e5dbed62eee9f..6990ead71ac6484c64013bf731338a757ab3230f:/twitter/logger.py diff --git a/twitter/logger.py b/twitter/logger.py index c3c2cc2..b96dc1a 100644 --- a/twitter/logger.py +++ b/twitter/logger.py @@ -10,25 +10,32 @@ DESCRIPTION: Produce a complete archive in text form of a user's tweets. The archive format is: - screen_name tweet_id tweet_time + screen_name + Date: + [In-Reply-To: a_tweet_id] Tweet text possibly spanning multiple lines with each line indented by four spaces. - Each tweet is separated by a blank line. + + Each tweet is separated by two blank lines. """ +from __future__ import print_function + import sys import os from time import sleep -from api import Twitter, TwitterError -from cmdline import CONSUMER_KEY, CONSUMER_SECRET -from auth import NoAuth +from .api import Twitter, TwitterError +from .cmdline import CONSUMER_KEY, CONSUMER_SECRET +from .auth import NoAuth +from .util import printNicely + def log_debug(msg): - print >> sys.stderr, msg + print(msg, file=sys.stderr) def get_tweets(twitter, screen_name, max_id=None): kwargs = dict(count=3200, screen_name=screen_name) @@ -40,13 +47,16 @@ def get_tweets(twitter, screen_name, max_id=None): for tweet in tweets: if tweet['id'] == max_id: continue - print "%s %s %s" % (tweet['user']['screen_name'], - tweet['id'], - tweet['created_at']) - print + print("%s %s\nDate: %s" % (tweet['user']['screen_name'], + tweet['id'], + tweet['created_at'])) + if tweet.get('in_reply_to_status_id'): + print("In-Reply-To: %s" % tweet['in_reply_to_status_id']) + print() for line in tweet['text'].splitlines(): - print ' ' + line.encode('utf-8') - print + printNicely(' ' + line + '\n') + print() + print() max_id = tweet['id'] n_tweets += 1 return n_tweets, max_id @@ -58,7 +68,7 @@ def main(args=sys.argv[1:]): domain='api.twitter.com') if not args: - print __doc__ + print(__doc__) return 1 screen_name = args[0] @@ -77,7 +87,7 @@ def main(args=sys.argv[1:]): if tweets_processed == 0: log_debug("That's it, we got all the tweets. Done.") break - except TwitterError, e: + except TwitterError as e: log_debug("Twitter bailed out. I'm going to sleep a bit then try again") sleep(3)