Importing your old comments to Disqus site

In one of my latest blogpost on disqus I covered topics on integrating Disqus to the website and disqus SSO. In this post, I will let you know how to migrate the older comments to Disqus.

If you sneak peek in to the alluring features of disqus you may make your mind to migrate your custom commenting system on your blog to use disqus commenting system. The threaded comments and replies, powerful moderation and admin tools, RSS options and many more features come in as battaries included with Disqus which makes the commenting more interactive and easy to deal with.

Let us kick start the process. Till date importing the old comments directly from the blogger and wordpress to disqus is feasible. This can be achieved by using tools and plugins that are already existing in them and its pretty straight forward. In this post our prime concern will be laid on custom XML import format. If you are using neither blogger, nor wordpress the custom XML import format which is based on the WXR (WordPress eXtended RSS) schema comes to the rescue. Disqus also supports MovableType, and IntenseDebate but preferably WXR is of more concern.

I consider a case in a Django project, which does adopt a custom commenting system in which the comments are stored in a postgresql database. This process of migrating the comments to disqus comprises of two steps in this case.

  1. Creating a WXR schema of the existing comments
  2. Importing the WXR file to Disqus site.

  3. Creating a WXR schema of the existing comments

    WXR format is based on the Rss specification. This format is normally used for importing or exporting data from wordpress servers. Now the aim is to create a WXR file from the existing comments in our storage. For that we are going to write a python script. Disqus has prescribed a format of the file that we are planning to import to Disqus. The format looks in the following way.

    <?xml version=”1.0” encoding=”UTF-8”?>

    Foo bar</link> <![CDATA[Hello world]]> disqus_identifier 2010-09-20 09:13:44 open user id 65 Foo Bar [email protected] 2010-09-20 13:19:10 <![CDATA[Hello world]]> 1 0
  • Things to keep in mind:

As recommended by the Disqus we need some points to keep in mind while creating a WXR file of the existing comments.

  1. Only use the “dsq:remote” tag (and its children) if you’re using Single Sign-On; otherwise remove it.
  2. If you’re manually filling in make sure it's unique to each user or else all comments will display the same author name.
  3. Each “item” tag can parent an infinite number of “wp:comment” tags.
  4. There is a minimum character requirement for each comment message, which is 3 characters.

Every item is supposed to be a comment on the site. As I am not using the SSO in the site, we can remove the . The link specifies the site url to the specific post. In my case I happened to find some encoding issues with the which does take the whole body of the post so I preferred removing it from the WXR file and it worked fine.

The script appears to be in the below manner. I accessed my comment model to get the comment data. And then I created the xml file in the format prescribed by Disqus. I skipped some tags which ought to mess up encryption issues. But beware, try to create as the disqus prescribes for the easy flow. The script looks like the following way.

from mysite.models import Comment
from django.contrib.sites.models import Site

site = Site.objects.all()[0]

comments = Comment.objects.all()
xml_data_header = """<?xml version="1.0" encoding="UTF-8"?>
                <rss version="2.0"
xml_data_footer = """
file_dis = open('disqus.xml','wb')
for comment in comments:
    xml_data_all = ''
    xml_data = """

                """.format(comment.comment_for.title.encode('utf-8'), site.domain+comment.comment_for.get_absolute_url().encode('utf-8'), comment.comment_for.text.raw.encode('utf-8'),, comment.comment_for.created_on,, \
                    comment.user_name.encode('utf-8'), comment.email_id.encode('utf-8'), comment.user_ip, comment.created_on, comment.text.encode('utf-8'), \
    # xml_data_all += xml_data


Once you run the above script the resultant will be a “disqus.xml” file. An example output of the file looks like this:

<?xml version="1.0" encoding="UTF-8"?>
            <rss version="2.0"
                      <title>Google Appengine - First Impressions</title>
                      <wp:post_date_gmt>2008-04-09 04:02:57</wp:post_date_gmt>
                        <wp:comment_author_email>[email protected]</wp:comment_author_email>
                        <wp:comment_date_gmt>2008-04-09 08:48:53</wp:comment_date_gmt>
                        <wp:comment_content><![CDATA[<p>On dev server data is stored in /tmp folder</p>]]></wp:comment_content>

            </rss> Once we are done with creating the WXR schema we should import it to the disqus site.

2.Importing the WXR file to Disqus site.

To attain the second part you need to have a disqus account and a disqus site available for you. You can get to know more about creating a disqus site in the linked blogpost

Once you are done with the creation of disqus site go to the settings which can be accessible on admin panel. There appears the settings page, click on the discussion on the right top panel. Click “import” tab and there appears the different types of import formats that disqus supports. Select generic(WXR) and click on browse. Upload the disqus.xml file and once the process get completed it shows up if there are any errors in the uploaded file. If there are any errors, the process of importing comments will be kept on hold. If the comments are successfully imported it takes some time to get those comments reflected in your site.

TIP: The best practice would be to try importing in to test disqus site and once it works perfectly, move towards importing them to the main site.

Thank you for reading the Agiliq blog. This article was written by Rakesh on Jan 16, 2015 in Disqus .

You can subscribe ⚛ to our blog.

We love building amazing apps for web and mobile for our clients. If you are looking for development help, contact us today ✉.

Would you like to download 10+ free Django and Python books? Get them here