Skip to content

Instantly share code, notes, and snippets.

@mcroydon
Created May 27, 2009 14:33
Show Gist options
  • Save mcroydon/118666 to your computer and use it in GitHub Desktop.
Save mcroydon/118666 to your computer and use it in GitHub Desktop.
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