Feb 14
Import wordpress into django-mingus
\\//!
Ok I fixed a small script that added all my wordpress posts to django-mingus.
How did I do it?
1. Export the wordpress posts (tools/export)
2. write import_posts.py like below
import sys
import os
from django.core.management import setup_environ
import settings
from django.template.defaultfilters import slugify
from django_proxy.models import Proxy
import elementtree.ElementTree as ET
from basic.blog.models import Post, Category
tree = ET.parse('/tmp/wordpress.2010-02-13.xml')
for item in tree.findall("channel/item"):
post = Post()
post.title = item.find("title").text
post.slug = item.find("{http://wordpress.org/export/1.0/}post_name").text
post.body = item.find("{http://purl.org/rss/1.0/modules/content/}encoded").text
post.created = item.find("{http://wordpress.org/export/1.0/}post_date").text
post.status = 2
post.publish = post.created
post.save()
categories = item.findall("category")
for c in categories:
try:
cat = Category.objects.get(slug=slugify(c.text))
except:
cat = Category()
cat.title = c.text
cat.slug = slugify(c.text)
cat.save()
post.categories.add(cat)
post.save()
p = Proxy()
p.title = post.title
p.description = post.body_markup
p.pub_date = post.publish
p.active = {'status':2}
p.content_type_id=15
p.object_id = post.id
p.save()
3. put the file in your django-mingus/mingus folder 4. run it with python import_posts.py
llap!
blog comments powered by Disqus