From ec36839aa869bdb4ce716ba9eb538125d3e3e314 Mon Sep 17 00:00:00 2001 From: greg Date: Fri, 25 Nov 2005 06:35:01 +0000 Subject: [PATCH] initial commit git-svn-id: file:///home/svn/ljdump/trunk@2 7994a137-d0a5-da11-ade6-0050bffea3d9 --- ljdump.config.sample | 5 ++++ ljdump.py | 59 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 ljdump.config.sample create mode 100755 ljdump.py diff --git a/ljdump.config.sample b/ljdump.config.sample new file mode 100644 index 0000000..3d98ddc --- /dev/null +++ b/ljdump.config.sample @@ -0,0 +1,5 @@ + + + myaccount + mypassword + diff --git a/ljdump.py b/ljdump.py new file mode 100755 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\n" % (k, saxutils.escape(s), k)) + f.write("\n" % name) + +def writedump(itemid, event): + f = codecs.open("archive/"+itemid, "w", "UTF-8") + f.write("""\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'] -- 2.39.5