Created
May 27, 2009 14:33
-
-
Save mcroydon/118666 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from postneo.category.models import Category | |
from postneo.blog.models import Entry | |
from lxml import etree | |
tree = etree.parse(open('../../../wordpress-20090526.xml', 'r')) | |
def field_data(tree, name): | |
"""Return the text for a field element with a particular name""" | |
return tree.find("field[@name='%s']" % name).text | |
for row in tree.find("//table_data[@name='wp_categories']").getchildren(): | |
"""Handle category import""" | |
c, created = Category.objects.get_or_create( | |
pk = field_data(row, 'cat_ID'), | |
name = field_data(row, 'cat_name'), | |
slug = field_data(row, 'category_nicename'), | |
description = field_data(row, 'category_description') or '', | |
parent__pk=field_data(row, 'category_parent') or None) | |
print c |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment