import xml.dom.minidom
import os
+import codecs
from time import strptime, strftime
def getNodeText(doc, nodename):
return rc
def appendTextNode(doc, parent, nodename, value):
+ nodeValue = value
+
+ # make sure value is properly encoded
+ try:
+ bytes = nodeValue.encode("UTF-8")
+ except:
+ bytes = nodeValue.encode("cp1252")
+ nodeValue = unicode(bytes, "UTF-8")
+
element = doc.createElement(nodename)
- if( value != "" ):
- textNode = doc.createTextNode(value)
+ if( nodeValue != "" ):
+ textNode = doc.createTextNode(nodeValue)
element.appendChild(textNode)
parent.appendChild(element)
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:
+ maskText = getNodeText(inDoc, "allowmask")
+
+ if(maskText != ""):
+ appendTextNode(outDoc, entry, "allowmask", maskText)
+ else:
appendTextNode(outDoc, entry, "allowmask", "0")
# Create a taglist element
def addCommentsForId(outDoc, entry, username, id):
try:
commentFile = open("%s/C-%s" % (username,id), "r")
- except:
- # there are no comments for this entry
+ except IOError: # there are no comments for this entry
return
inDoc = xml.dom.minidom.parse(commentFile)
-# Create the minidom document
-outDoc = xml.dom.minidom.Document()
-
-# Create the <livejournal> base element
-ljElement = outDoc.createElement("livejournal")
-outDoc.appendChild(ljElement)
-
userDir = os.listdir("grahams")
highNum = -1
entryArray.sort()
+
+# Create the minidom document
+outDoc = xml.dom.minidom.Document()
+
+# Create the <livejournal> base element
+ljElement = outDoc.createElement("livejournal")
+outDoc.appendChild(ljElement)
+
+breakup = 250
+currentFileEntry = 0
+
# start processing entries
for entry in entryArray:
- print entry
addEntryForId(outDoc, "grahams", entry)
+ currentFileEntry += 1
+
+ if( currentFileEntry == breakup ):
+
+ f = open("grahams - %s.xml" % entry, "w")
+ tempXML = outDoc.toxml("UTF-8")
+ f.write(tempXML)
+
+ currentFileEntry = 0
+
+ # Create the minidom document
+ outDoc = xml.dom.minidom.Document()
-# Print our newly created XML
-print outDoc.toprettyxml(indent=" ")
+ # Create the <livejournal> base element
+ ljElement = outDoc.createElement("livejournal")
+ outDoc.appendChild(ljElement)