import xml.dom.minidom
import os
import codecs
+import sys
+
from time import strptime, strftime
def getNodeText(doc, nodename):
parent.appendChild(element)
-def addEntryForId(outDoc, username, id):
+def addEntryForId(outDoc, element, 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)
+ element.appendChild(entry)
# Create an itemid element
appendTextNode(outDoc, entry, "itemid", getNodeText(inDoc,"itemid"))
# Create an allowmask element (doesn't exist in pydump output if public)
maskText = getNodeText(inDoc, "allowmask")
+ # XXXSMG: consult L-1411 and L-976 for examples of security and
+ # allowmask use
if(maskText != ""):
appendTextNode(outDoc, entry, "allowmask", maskText)
else:
if(parentId != ""):
appendTextNode(outDoc, outComment, "parent_itemid", parentId)
+def main(argv):
+ username = ""
+ entryLimit = 250
+
+ if( len(argv) != 2 ):
+ print( "Usage: convertdump.py <username> <entrylimit>" )
+ return
+ else:
+ username = argv[0]
+ entryLimit = int(argv[1])
+ userDir = os.listdir(username)
-userDir = os.listdir("grahams")
+ highNum = -1
+ entryArray = []
-highNum = -1
-entryArray = []
+ # get the list of entries
+ for file in userDir:
+ if file.startswith("L-"):
+ entryNum = int(file.replace("L-",""))
-# get the list of entries
-for file in userDir:
- if file.startswith("L-"):
- entryNum = int(file.replace("L-",""))
+ entryArray.append(entryNum)
- entryArray.append(entryNum)
+ if( highNum < entryNum ):
+ highNum = entryNum
- if( highNum < entryNum ):
- highNum = entryNum
+ entryArray.sort()
-entryArray.sort()
+ # Create the minidom document
+ outDoc = xml.dom.minidom.Document()
-# Create the minidom document
-outDoc = xml.dom.minidom.Document()
+ # Create the <livejournal> base element
+ ljElement = outDoc.createElement("livejournal")
+ outDoc.appendChild(ljElement)
-# Create the <livejournal> base element
-ljElement = outDoc.createElement("livejournal")
-outDoc.appendChild(ljElement)
+ entryLimit = 250
+ currentFileEntry = 0
-breakup = 250
-currentFileEntry = 0
+ # start processing entries
+ for entry in entryArray:
+ addEntryForId(outDoc, ljElement, username, entry)
-# start processing entries
-for entry in entryArray:
- addEntryForId(outDoc, "grahams", entry)
+ currentFileEntry += 1
- currentFileEntry += 1
+ if( currentFileEntry == entryLimit ):
- if( currentFileEntry == breakup ):
+ f = open("%s - %s.xml" % (username, entry), "w")
+ tempXML = outDoc.toxml("UTF-8")
+ f.write(tempXML)
+
+ currentFileEntry = 0
- 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()
+
+ # Create the <livejournal> base element
+ ljElement = outDoc.createElement("livejournal")
+ outDoc.appendChild(ljElement)
- # Create the minidom document
- outDoc = xml.dom.minidom.Document()
+if __name__ == "__main__":
+ main(sys.argv[1:])
- # Create the <livejournal> base element
- ljElement = outDoc.createElement("livejournal")
- outDoc.appendChild(ljElement)