#!/usr/bin/python # -*- coding: utf-8 -*- # Read all comments from a CAIF file, the XML haloscan exports from disqus import DisqusService from xml.etree import ElementTree from datetime import datetime import time # Obviously these should be YOUR comment threads ;-) threads={ 'P1': ('http://lateral.netmanagers.com.ar/weblog/posts/P1.html','My first post'), 'P2': ('http://lateral.netmanagers.com.ar/weblog/posts/P2.html','My second post'), } key='USE YOUR API KEY HERE' ds=DisqusService() ds.login(key) forum=ds.get_forum_list()[0] def importThread(node): t_id=node.attrib['id'] # Your haloscan thread data thr_data=threads[t_id] # A Disqus thread: it will be created if needed thread=ds.thread_by_identifier(forum,t_id,t_id)['thread'] # Set the disqus thread data to match your blog ds.update_thread(forum, thread, url=thr_data[0], title=thr_data[1]) # Now post all the comments in this thread for node in node.findall('comment'): dt=datetime.strptime(node.find('datetime').text[:19],'%Y-%m-%dT%H:%M:%S') name=node.find('name').text or 'Anonymous' email=node.find('email').text or '' uri=node.find('uri').text or '' text=node.find('text').text or 'No text' print '-'*80 print 'Name:', name print 'Email:', email print 'Date:', dt print 'URL:', uri print print 'Text:' print text print ds.create_post(forum, thread, text, name, email, created_at=dt, author_url=uri) time.sleep(1) def importComments(fname): tree=ElementTree.parse(fname) for node in tree.findall('thread'): importThread(node) # Replace comments.xml with the file you downloaded from Haloscan importComments('comments.xml')