From 11ced10b0ef14cf5b52ca7887cce5957a3e12e06 Mon Sep 17 00:00:00 2001 From: greg Date: Sun, 25 Dec 2005 18:24:23 +0000 Subject: [PATCH] get new and updated entries git-svn-id: file:///home/svn/ljdump/trunk@11 7994a137-d0a5-da11-ade6-0050bffea3d9 --- ljdump.py | 57 +++++++++++++++++++++++++++++++++---------------------- 1 file changed, 34 insertions(+), 23 deletions(-) diff --git a/ljdump.py b/ljdump.py index 96adc46..318b459 100755 --- a/ljdump.py +++ b/ljdump.py @@ -2,7 +2,7 @@ # # ljdump.py - livejournal archiver # Greg Hewgill http://hewgill.com -# Version 1.0.2 +# Version 1.0.3 # # $Id$ # @@ -24,7 +24,7 @@ # clear; the livejournal "challenge" password mechanism is used. # # This program may be run as often as needed to bring the backup copy up -# to date. Only new items are downloaded. +# to date. Both new and updated items are downloaded. # # LICENSE # @@ -88,11 +88,20 @@ except: server = xmlrpclib.ServerProxy(Server) -total = 0 -fetched = 0 +new = 0 errors = 0 last = "" +f = open("%s/.last" % Username, "r") +try: + last = f.readline() + if last[-1] == '\n': + last = last[:len(last)-1] + f.close() +except: + pass +origlast = last + while True: r = server.LJ.XMLRPC.syncitems(dochallenge({ 'username': Username, @@ -104,25 +113,27 @@ while True: break for item in r['syncitems']: if item['item'][0] == 'L': - fn = "%s/%s" % (Username, item['item']) - if not os.access(fn, os.F_OK): - print "Fetching journal entry %s" % item['item'] - try: - e = server.LJ.XMLRPC.getevents(dochallenge({ - 'username': Username, - 'ver': 1, - 'selecttype': "one", - 'itemid': item['item'][2:], - }, Password)) - writedump(fn, e['events'][0]) - fetched += 1 - except xmlrpclib.Fault, x: - print "Error getting item: %s" % item['item'] - pprint.pprint(x) - errors += 1 - total += 1 + print "Fetching journal entry %s (%s)" % (item['item'], item['action']) + try: + e = server.LJ.XMLRPC.getevents(dochallenge({ + 'username': Username, + 'ver': 1, + 'selecttype': "one", + 'itemid': item['item'][2:], + }, Password)) + writedump("%s/%s" % (Username, item['item']), e['events'][0]) + new += 1 + except xmlrpclib.Fault, x: + print "Error getting item: %s" % item['item'] + pprint.pprint(x) + errors += 1 last = item['time'] -print "%d total entries" % total -print "%d fetched entries" % fetched +f = open("%s/.last" % Username, "w") +f.write("%s\n" % last) +f.close() +if origlast: + print "%d new entries (since %s)" % (new, origlast) +else: + print "%d new entries" % new if errors > 0: print "%d errors" % errors -- 2.39.5