Created
March 28, 2010 23:26
-
-
Save sbusso/347114 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice one, I'd been wondering how you might do this!