- entry = xml.dom.minidom.getDOMImplementation().createDocument(None, "comments", None)
- found = False
- for d in entry.getElementsByTagName("comment"):
- if int(d.getElementsByTagName("id")[0].firstChild.nodeValue) == id:
- found = True
- break
- if found:
- print "Warning: downloaded duplicate comment id %d in jitemid %s" % (id, jitemid)
- else:
- entry.documentElement.appendChild(createxml(entry, "comment", comment))
- f = codecs.open("%s/C-%s" % (Username, jitemid), "w", "UTF-8")
- entry.writexml(f)
- f.close()
- newcomments += 1
- if id > maxid:
- maxid = id
- if maxid >= newmaxid:
- break
-
-lastmaxid = maxid
-
-writelast()
-
-if origlastsync:
- print "%d new entries, %d new comments (since %s)" % (newentries, newcomments, origlastsync)
-else:
- print "%d new entries, %d new comments" % (newentries, newcomments)
-if errors > 0:
- print "%d errors" % errors
+ # for installations where the above utf_8_decode doesn't work
+ picfn = "".join([ord(x) < 128 and x or "?" for x in picfn])
+ picf = open("%s/%s%s" % (Username, picfn, ext), "wb")
+ shutil.copyfileobj(pic, picf)
+ pic.close()
+ picf.close()
+ print >>f, "</userpics>"
+ f.close()
+
+ newmaxid = maxid
+ maxid = lastmaxid
+ while True:
+ r = urllib2.urlopen(urllib2.Request(Server+"/export_comments.bml?get=comment_body&startid=%d" % (maxid+1), headers = {'Cookie': "ljsession="+ljsession}))
+ meta = xml.dom.minidom.parse(r)
+ r.close()
+ for c in meta.getElementsByTagName("comment"):
+ id = int(c.getAttribute("id"))
+ jitemid = c.getAttribute("jitemid")
+ comment = {
+ 'id': str(id),
+ 'parentid': c.getAttribute("parentid"),
+ 'subject': gettext(c.getElementsByTagName("subject")),
+ 'date': gettext(c.getElementsByTagName("date")),
+ 'body': gettext(c.getElementsByTagName("body")),
+ 'state': metacache[id]['state'],
+ }
+ if usermap.has_key(c.getAttribute("posterid")):
+ comment["user"] = usermap[c.getAttribute("posterid")]
+ try:
+ entry = xml.dom.minidom.parse("%s/C-%s" % (Username, jitemid))
+ except:
+ entry = xml.dom.minidom.getDOMImplementation().createDocument(None, "comments", None)
+ found = False
+ for d in entry.getElementsByTagName("comment"):
+ if int(d.getElementsByTagName("id")[0].firstChild.nodeValue) == id:
+ found = True
+ break
+ if found:
+ print "Warning: downloaded duplicate comment id %d in jitemid %s" % (id, jitemid)
+ else:
+ entry.documentElement.appendChild(createxml(entry, "comment", comment))
+ f = codecs.open("%s/C-%s" % (Username, jitemid), "w", "UTF-8")
+ entry.writexml(f)
+ f.close()
+ newcomments += 1
+ if id > maxid:
+ maxid = id
+ if maxid >= newmaxid:
+ break
+
+ lastmaxid = maxid
+
+ writelast(Username, lastsync, lastmaxid)
+
+ if origlastsync:
+ print "%d new entries, %d new comments (since %s)" % (newentries, newcomments, origlastsync)
+ else:
+ print "%d new entries, %d new comments" % (newentries, newcomments)
+ if errors > 0:
+ print "%d errors" % errors
+
+if __name__ == "__main__":
+ config = xml.dom.minidom.parse("ljdump.config")
+ server = config.documentElement.getElementsByTagName("server")[0].childNodes[0].data
+ username = config.documentElement.getElementsByTagName("username")[0].childNodes[0].data
+ password = config.documentElement.getElementsByTagName("password")[0].childNodes[0].data
+ ljdump(server, username, password)