Skip to content

Instantly share code, notes, and snippets.

@sbusso
Created March 28, 2010 23:26
Show Gist options
  • Save sbusso/347114 to your computer and use it in GitHub Desktop.
Save sbusso/347114 to your computer and use it in GitHub Desktop.
# rake task to export comments from typo to disqus
require 'disqus'
require 'disqus/api'
require 'disqus/author'
require 'disqus/forum'
require 'disqus/post'
require 'disqus/thread'
namespace :export do
desc "Load Blog comments to Disqus"
task :comments => :environment do
Disqus::defaults[:account] = 'xxxx' # your user account
Disqus::defaults[:api_key] = 'xxxx' # your api key http://disqus.com/api/get_my_key/
site_url = "http://yourwebsite.com/articles/"
forum = Disqus::Forum.list.first
Content.find(:all, :conditions => "type = 'Article'").each do |post|
if post.comments && post.comments.size > 0
# create thread
permalink = site_url + post[:published_at].strftime('%Y/%m/%d/') + post.permalink
thread = Disqus::Api.thread_by_identifier(
:forum_api_key => forum.key,
:identifier => post.title,
:title => post.title)
begin
Disqus::Api.update_thread(
:forum_api_key => forum.key,
:thread_id => thread["message"]["thread"]['id'],
:url => permalink,
:slug => post.permalink,
:title => post.title,
:allow_comments => 1) # if you want to close comments on old posts
rescue => e
puts permalink
puts e
end
post.comments.each do |comment|
# insert comments
next if comment[:state] =~ /Spam/
# FIXME: better way to manage author ?
Disqus::Api.create_post(
:forum_api_key => forum.key,
:thread_id => thread["message"]["thread"]['id'],
:message => comment.body,
:author_name => comment.author,
:author_email => comment.email,
:created_at => comment.created_at.strftime("%Y-%m-%dT%H:%M")
)
end
end
end
end # export:comments
end
@johngrimes
Copy link

Nice one, I'd been wondering how you might do this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment