From: greg Date: Fri, 25 Nov 2005 18:34:46 +0000 (+0000) Subject: save archive in dir named by username, misc cleanup X-Git-Tag: ljdump-1.3.2~29 X-Git-Url: http://wagner.pp.ru/gitweb/?a=commitdiff_plain;h=32309e5c929b049cee525d3c0f092177eb9b9f3c;p=oss%2Fljdump.git save archive in dir named by username, misc cleanup git-svn-id: file:///home/svn/ljdump/trunk@3 7994a137-d0a5-da11-ade6-0050bffea3d9 --- diff --git a/ljdump.py b/ljdump.py index 65903fd..45466d9 100755 --- a/ljdump.py +++ b/ljdump.py @@ -20,8 +20,8 @@ def dumpelement(f, name, e): f.write("<%s>%s\n" % (k, saxutils.escape(s), k)) f.write("\n" % name) -def writedump(itemid, event): - f = codecs.open("archive/"+itemid, "w", "UTF-8") +def writedump(fn, event): + f = codecs.open(fn, "w", "UTF-8") f.write("""\n""") dumpelement(f, "event", event) f.close() @@ -30,7 +30,14 @@ config = xml.dom.minidom.parse("ljdump.config") Username = config.documentElement.getElementsByTagName("username")[0].childNodes[0].data Password = config.documentElement.getElementsByTagName("password")[0].childNodes[0].data +print "Fetching journal entries for: %s" % Username + server = xmlrpclib.ServerProxy("http://livejournal.com/interface/xmlrpc") + +total = 0 +fetched = 0 +errors = 0 + last = "" while True: r = server.LJ.XMLRPC.syncitems(dochallenge({ @@ -42,9 +49,10 @@ while True: if len(r['syncitems']) == 0: break for item in r['syncitems']: - #print item['item'] if item['item'][0] == 'L': - if not os.access("archive/"+item['item'], os.F_OK): + 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, @@ -52,8 +60,15 @@ while True: 'selecttype': "one", 'itemid': item['item'][2:], }, Password)) - writedump(item['item'], e['events'][0]) + writedump(fn, e['events'][0]) + fetched += 1 except xmlrpclib.Fault, x: print "Error getting item: %s" % item['item'] pprint.pprint(x) + errors += 1 last = item['time'] + total += 1 +print "%d total entries" % total +print "%d fetched entries" % fetched +if errors > 0: + print "%d errors" % errors