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/pythonimport 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 settingstypepadHost = 'http://www.typepad.com/t/api'typepadBlogId = '1234567890' #Your TypePad blog IDtypepadUser = 'username'typepadPass = 'password'#Drupal blog settingsdrupalHost = 'http://example.com/xmlrpc.php'drupalBlogId = 'blog' #Tells BlogAPI to create new nodes with the 'blog' content typedrupalUser = 'username'drupalPass = 'password'#Instantiate XML-RPC clientstypepad = 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 Drupalfor 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.
Tags: DrupalXML-RPCPythonxmlrpclibTypePadMovableTypeblogcontent migrationMetaWeblog API
-
var switchTo5x=true;stLight.options({publisher:'dr-8d4fe24c-a8ab-ba90-8086-3791b02244be'});