]> wagner.pp.ru Git - oss/ljdump.git/commitdiff
initial commit
authorgreg <greg@7994a137-d0a5-da11-ade6-0050bffea3d9>
Fri, 25 Nov 2005 06:35:01 +0000 (06:35 +0000)
committergreg <greg@7994a137-d0a5-da11-ade6-0050bffea3d9>
Fri, 25 Nov 2005 06:35:01 +0000 (06:35 +0000)
git-svn-id: file:///home/svn/ljdump/trunk@2 7994a137-d0a5-da11-ade6-0050bffea3d9

ljdump.config.sample [new file with mode: 0644]
ljdump.py [new file with mode: 0755]

diff --git a/ljdump.config.sample b/ljdump.config.sample
new file mode 100644 (file)
index 0000000..3d98ddc
--- /dev/null
@@ -0,0 +1,5 @@
+<?xml version="1.0"?>
+<ljdump>
+    <username>myaccount</username>
+    <password>mypassword</password>
+</ljdump>
diff --git a/ljdump.py b/ljdump.py
new file mode 100755 (executable)
index 0000000..65903fd
--- /dev/null
+++ b/ljdump.py
@@ -0,0 +1,59 @@
+import codecs, md5, os, pprint, sys, xml.dom.minidom, xmlrpclib
+from xml.sax import saxutils
+
+def dochallenge(params, password):
+    challenge = server.LJ.XMLRPC.getchallenge()
+    params.update({
+        'auth_method': "challenge",
+        'auth_challenge': challenge['challenge'],
+        'auth_response': md5.new(challenge['challenge']+md5.new(password).hexdigest()).hexdigest()
+    })
+    return params
+
+def dumpelement(f, name, e):
+    f.write("<%s>\n" % name)
+    for k in e.keys():
+        if isinstance(e[k], {}.__class__):
+            dumpelement(f, k, e[k])
+        else:
+            s = unicode(str(e[k]), "UTF-8")
+            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")
+    f.write("""<?xml version="1.0"?>\n""")
+    dumpelement(f, "event", event)
+    f.close()
+
+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
+
+server = xmlrpclib.ServerProxy("http://livejournal.com/interface/xmlrpc")
+last = ""
+while True:
+    r = server.LJ.XMLRPC.syncitems(dochallenge({
+        'username': Username,
+        'ver': 1,
+        'lastsync': last,
+    }, Password))
+    #pprint.pprint(r)
+    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):
+                try:
+                    e = server.LJ.XMLRPC.getevents(dochallenge({
+                        'username': Username,
+                        'ver': 1,
+                        'selecttype': "one",
+                        'itemid': item['item'][2:],
+                    }, Password))
+                    writedump(item['item'], e['events'][0])
+                except xmlrpclib.Fault, x:
+                    print "Error getting item: %s" % item['item']
+                    pprint.pprint(x)
+        last = item['time']