Migrating content from MovableType or TypePad to Drupal with Python

Migrating content out of one blogging or content management system into another is one of those tasks that doesn't usually merit writing a feature-complete, polished migration tool; no two systems are alike, and no two migration scenarios are alike either. Since it's an infrequent process, there's not really incentive for anyone to write or maintain a dedicated Drupal module for doing such migrations (unless perhaps they find themselves doing a whole lot of migrations for clients.)

So, when I went looking for a way to move a bunch of blog posts out of a TypePad blog and into a Drupal site, I was disappointed but not really surprised not to find a ready-made solution.

Rather than rolling my own Drupal module to deal with the problem, I turned to Python and its excellent xmlrpclib library.

Because both TypePad and Drupal implement the MetaWeblog API, I was able to move more than 300 blog entries from one to the other with about 10 lines of Python code. Now, in my case I did not need to worry about preserving comments, multiple authors, or attachments, so I was able to get away with very few headaches... but it would be a good starting place for more complex migrations.

I broke the code up and commented it to make it a bit easier to follow, so it wound up being 37 lines instead of the original 9 or 10... but that's still a lot less code than you'd wind up with if you attacked the problem with a custom Drupal module.

#!/usr/bin/python

import xmlrpclib

# Python script for migrating blog posts out of TypePad and into a Drupal site.
#
# Andy Chase
# The Proof Group LLC
# 2009-07-25
#
# This is a brute force tool, and does not account for mapping TypePad Users
# to Drupal users or preserving categories and attachments. You'll need to enable
# the Blog and BlogAPI modules on your Drupal site, and you may want to temporarily
# set your Drupal site's default input format to 'Full HTML' before doing the import.

#TypePad blog settings
typepadHost = 'http://www.typepad.com/t/api'
typepadBlogId = '1234567890' #Your TypePad blog ID
typepadUser = 'username'
typepadPass = 'password'

#Drupal blog settings
drupalHost = 'http://example.com/xmlrpc.php'
drupalBlogId = 'blog' #Tells BlogAPI to create new nodes with the 'blog' content type
drupalUser = 'username'
drupalPass = 'password'

#Instantiate XML-RPC clients
typepad = xmlrpclib.ServerProxy(typepadHost)
drupal = xmlrpclib.ServerProxy(drupalHost)

#Get posts from TypePad (The last argument is the number of posts you want to retrieve)
posts = typepad.metaWeblog.getRecentPosts(typepadBlogId, typepadUser, typepadPass, 500)

#Push posts to Drupal
for post in posts:
    drupal.metaWeblog.newPost(drupalBlogId, drupalUser, drupalPass, post, True)

It's worth noting that this technique should work for moving content out of and into any CMS that implements the MetaWeblog API.

AttachmentSize
migrate.py_.txt1.26 KB

thanks

Thanks I love drupal. I also hated using type pad and was ready for something better like Frupal. This makes my business run more efficient and better Esmaltes and Camisetas

Amazing

I have had a pretty easy time migrating my Wordpress blog. I used use Drupal rather regularly, but have since changed for aesthetic purposes. Wordpress' abilities to change and adapt on the fly without taking a ton of time in the process. Travel Medical Insurance

I broke the code up and

I broke the code up and commented it to make it a bit easier to follow, so it wound up being 37 lines instead of the original 9 or 10... but that's still a lot less code than you'd wind up with if you attacked the problem with a custom Drupal module.

Well thansk for explaining

Well thansk for explaining the transfer method in such an easy way i used to think that its a hard process.. logo design

Drupal rocks

I love drupal. I also hated using type pad and was ready for something better like Frupal. This makes my business run more efficient and better.

Typepad is a new thing for

Typepad is a new thing for me. I guess it is not worth trying if everyone is moving away from it. This looks like a real easy task to do if you know how to simple python commands.

i hate to use typepad now. I

i hate to use typepad now. I am glad that i am able to transfer over to drupal. This will definitely make things easier. thanks for the great info.
church sound systems

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd><p><div> <br><img>
  • Lines and paragraphs break automatically.

More information about formatting options

Verification
This question is for testing whether you are a human visitor and to prevent automated spam submissions.