X-Git-Url: https://jfr.im/git/z_archive/twitter.git/blobdiff_plain/694aaadfb9092a3eaa83a974f58de2cbd2cccdd8..30af6c0f49cd4a11409f0ff1d78dab696e9c7749:/twitter/archiver.py diff --git a/twitter/archiver.py b/twitter/archiver.py index 91a8aa7..6f2468a 100644 --- a/twitter/archiver.py +++ b/twitter/archiver.py @@ -129,14 +129,18 @@ def save_tweets(filename, tweets): archive.close() -def format_date(utc, to_localtime=True, isoformat=False): +def format_date(utc, isoformat=False): """Parse Twitter's UTC date into UTC or local time.""" u = datetime.strptime(utc.replace('+0000','UTC'), '%a %b %d %H:%M:%S %Z %Y') + # This is the least painful way I could find to create a non-naive + # datetime including a UTC timezone. Alternative suggestions + # welcome. unew = datetime.combine(u.date(), time(u.time().hour, u.time().minute, u.time().second, tzinfo=UTC)) - if to_localtime and _time.timezone != 0: - unew = unew.astimezone(Local) + # Convert to localtime + unew = unew.astimezone(Local) + if isoformat: return unew.isoformat() else: @@ -186,9 +190,9 @@ def statuses_portion(twitter, screen_name, max_id=None, mentions=False, favorite tweets = {} if mentions: - tl = twitter.statuses.mentions(**kwargs) + tl = twitter.statuses.mentions_timeline(**kwargs) elif favorites: - tl = twitter.favorites(**kwargs) # API v1, favorites.list() in v1.1 + tl = twitter.favorites.list(**kwargs) elif received_dms != None: if received_dms: tl = twitter.direct_messages(**kwargs) @@ -329,7 +333,7 @@ def main(args=sys.argv[1:]): else: auth = NoAuth() - twitter = Twitter(auth=auth, api_version='1', domain='api.twitter.com') + twitter = Twitter(auth=auth, api_version='1.1', domain='api.twitter.com') if options['api-rate']: rate_limit_status(twitter) @@ -389,7 +393,7 @@ def main(args=sys.argv[1:]): dms = {} try: dms = load_tweets(filename) - except Exception, e: + except Exception as e: err("Error when loading saved DMs: %s - continuing without" % str(e))