]> wagner.pp.ru Git - oss/ljdump.git/commitdiff
save archive in dir named by username, misc cleanup
authorgreg <greg@7994a137-d0a5-da11-ade6-0050bffea3d9>
Fri, 25 Nov 2005 18:34:46 +0000 (18:34 +0000)
committergreg <greg@7994a137-d0a5-da11-ade6-0050bffea3d9>
Fri, 25 Nov 2005 18:34:46 +0000 (18:34 +0000)
git-svn-id: file:///home/svn/ljdump/trunk@3 7994a137-d0a5-da11-ade6-0050bffea3d9

ljdump.py

index 65903fda98df8427d0bafee6941339407edf4e7e..45466d906da9127eb75db12d57f2fec48475486e 100755 (executable)
--- a/ljdump.py
+++ b/ljdump.py
@@ -20,8 +20,8 @@ def dumpelement(f, name, e):
             f.write("<%s>%s</%s>\n" % (k, saxutils.escape(s), k))
     f.write("</%s>\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("""<?xml version="1.0"?>\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