Sumedh

How to import your existing database comments into Disqus using generic WXR XML format.




Published - Aug 17/2011
Last Updated - Aug 17/2011
Author - Sumedh






So you want to move your existing Wordpress, Drupal, Joomla or a custom website comments to Disqus, great choice, your comments will be imported into Disqus in few easy steps.


I am assuming you can extract your existing comments from your mysql, postgres or some other database using any programming or scripting language you are comfortable with. We have to extract the comments into a generic WXR (WordPress eXtended RSS) XML format. You just to need to extract the commenter's name, email, website, ip address, date and the actual comment. If any of the fields are missing like email or ip address then you can keep it blank.

e.g - <wp:comment_author_email></wp:comment_author_email>


Change the following according to your specific settings.

<title>This is a test page</title>

<link>http://sumedh.info/articles/test.php</link>

<dsq:thread_identifier>test_page</dsq:thread_identifier>



Sample WXR XML format.

<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
  xmlns:content="http://purl.org/rss/1.0/modules/content/"
  xmlns:dsq="http://www.disqus.com/"
  xmlns:dc="http://purl.org/dc/elements/1.1/"
  xmlns:wp="http://wordpress.org/export/1.0/">
<channel>
<item>
    
<title>This is a test page</title>
<link>http://sumedh.info/articles/test.php</link>
<dsq:thread_identifier>test_page</dsq:thread_identifier>
<wp:post_date_gmt>2011-06-06 00:49:12</wp:post_date_gmt>
<wp:comment_status>open</wp:comment_status>

<wp:comment>
    <wp:comment_id>932322</wp:comment_id>
	<wp:comment_author>Raul</wp:comment_author>
	<wp:comment_author_email>raul@raul.com</wp:comment_author_email>
	<wp:comment_author_url></wp:comment_author_url>
	<wp:comment_author_IP>127.0.0.1</wp:comment_author_IP>
	<wp:comment_date_gmt>2011-9-1 08:58:44</wp:comment_date_gmt>
	<wp:comment_content>Thanks it worked</wp:comment_content>
	<wp:comment_approved>1</wp:comment_approved>
	<wp:comment_parent>0</wp:comment_parent>
</wp:comment>

<wp:comment>
	<wp:comment_id>932323</wp:comment_id>
	<wp:comment_author>james</wp:comment_author>
	<wp:comment_author_email>james@james.com</wp:comment_author_email>
	<wp:comment_author_url>www.sumedh.info</wp:comment_author_url>
	<wp:comment_author_IP>122.53.95.203</wp:comment_author_IP>
	<wp:comment_date_gmt>2011-9-27 09:32:10</wp:comment_date_gmt>
	<wp:comment_content>comments have been imported</wp:comment_content>
	<wp:comment_approved>1</wp:comment_approved>
	<wp:comment_parent>0</wp:comment_parent>
</wp:comment>

</item>
</channel>
</rss>
    



Write a Perl or Php script which will extract the required values from the DB and create an XML file in the above format. After your XML file is created, double check the syntax. If there are any syntax errors we will get "Error Importing" Messages in disqus while importing the file.





Log into your disqus account, go to Tools, click on "Import / Export". Click on Generic WXR. Select your XML file and click on import. It can take from 5 minutes to 2 hours for the comments to be imported into Disqus depending on the load on their servers.

Usb_multiboot




P.S - Don't be lazy, stop searching google for the script to extract the comments from the DB, write your own.




Sumedh K
All Rights Reserved