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()
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({
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,
'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