X-Git-Url: https://jfr.im/git/z_archive/twitter.git/blobdiff_plain/780044e6336befd1861d5d4ac194e864c4f53257..17b9ff10207340026b876eb623660f2c79bfe85d:/twitter/archiver.py diff --git a/twitter/archiver.py b/twitter/archiver.py index 4075409..ef2dc1f 100644 --- a/twitter/archiver.py +++ b/twitter/archiver.py @@ -97,8 +97,11 @@ def load_tweets(filename): tweets = {} for line in archive.readlines(): - tid, text = line.strip().split(" ", 1) - tweets[int(tid)] = text.decode("utf-8") + try: + tid, text = line.strip().split(" ", 1) + tweets[int(tid)] = text.decode("utf-8") + except Exception as e: + err("loading tweet %s failed due to %s" % (line, unicode(e))) archive.close() return tweets @@ -125,7 +128,10 @@ def save_tweets(filename, tweets): return for k in sorted(tweets.keys()): - archive.write("%i %s\n" % (k, tweets[k].encode('utf-8'))) + try: + archive.write("%i %s\n" % (k, tweets[k].encode('utf-8'))) + except Exception as ex: + err("archiving tweet %s failed due to %s" % (k, unicode(ex))) archive.close() @@ -322,8 +328,11 @@ def main(args=sys.argv[1:]): # authenticate using OAuth, asking for token if necessary if options['oauth']: - oauth_filename = (os.getenv("HOME", "") + os.sep - + ".twitter-archiver_oauth") + oauth_filename = (os.environ.get('HOME', + os.environ.get('USERPROFILE', '')) + + os.sep + + '.twitter-archiver_oauth') + if not os.path.exists(oauth_filename): oauth_dance("Twitter-Archiver", CONSUMER_KEY, CONSUMER_SECRET, oauth_filename)