From f18d217d036f861073374788434be94779c87f90 Mon Sep 17 00:00:00 2001 From: "Sean M. Graham" Date: Sat, 24 Jan 2009 18:58:53 -0500 Subject: [PATCH] Created new convertdump script --- convertdump.py | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100755 convertdump.py diff --git a/convertdump.py b/convertdump.py new file mode 100755 index 0000000..6f394ce --- /dev/null +++ b/convertdump.py @@ -0,0 +1,70 @@ +#!/usr/bin/python + +import xml.dom.minidom + +def getNodeText(doc, nodename): + rc = "" + + nodelist = doc.getElementsByTagName(nodename)[0].childNodes + + for node in nodelist: + if node.nodeType == node.TEXT_NODE: + rc = rc + node.data + + return rc + +def appendTextNode(doc, parent, nodename, value): + element = doc.createElement(nodename) + textNode = doc.createTextNode(value) + element.appendChild(textNode) + parent.appendChild(element) + + +def addEntryForID(doc, username, id): + entryFile = open("%s/L-%s" % (username,id), "r") + inDoc = xml.dom.minidom.parse(entryFile) + + # Create an entry element + entry = outDoc.createElement("entry") + ljElement.appendChild(entry) + + # Create an itemid element + appendTextNode(outDoc, entry, "itemid", getNodeText(inDoc,"itemid")) + + # Create an eventtime element + appendTextNode(outDoc, entry, "eventtime", getNodeText(inDoc, "eventtime")) + + # Create an subject element + appendTextNode(outDoc, entry, "subject", getNodeText(inDoc, "subject")) + + # Create an event node (special case because for some reason there are two + # 'event' elements in the pydump output, which is probably LJ's fault) + event = inDoc.getElementsByTagName("event")[0] + appendTextNode(outDoc, entry, "event", getNodeText(event, "event")) + + # Create an allowmask element (doesn't exist in pydump output if public) + try: + appendTextNode(outDoc, entry, "allowmask", + getNodeText(inDoc, "allowmask")) + except: + appendTextNode(outDoc, entry, "allowmask", "0") + + # Create a taglist element + appendTextNode(outDoc, entry, "taglist", getNodeText(inDoc, "taglist")) + + # XXXSMG: make sure there is a comment file before trying to do anything + # with it + commentFile = open("%s/C-%s" % (username,id), "r") + + +# Create the minidom document +outDoc = xml.dom.minidom.Document() + +# Create the base element +ljElement = outDoc.createElement("livejournal") +outDoc.appendChild(ljElement) + +addEntryForID(outDoc, "grahams", "2583") + +# Print our newly created XML +print outDoc.toprettyxml(indent=" ") -- 2.39.5