Created
February 26, 2011 14:08
-
-
Save julik/845226 to your computer and use it in GitHub Desktop.
Migrating a RYO comment system (in this case Inkpot) to Disqus
This file contains hidden or 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
#!/usr/local/bin/ruby | |
$KCODE = 'u' | |
require 'rubygems' | |
gem "camping", "1.5.180" | |
require File.dirname(__FILE__) + '/app/inkpot' | |
# 2010-09-20 13:19:10 | |
RFCT = "%Y-%m-%d %H:%M:%S" | |
Camping::Models::Base.establish_connection(SIKRIT_HASJ) | |
def permalink(e) | |
fmt = "http://live.julik.nl/%s/%s/%s" | |
fmt % e.permalink_elements # returns [year, month, slug] | |
end | |
def utc(date_time) | |
date_time.utc.strftime(RFCT) | |
end | |
# c in this case is my model object, we will use the following methods | |
# to_param, author (nickname), email, url (author URL), originating_ip | |
# created_at, text | |
def export_comment(c) | |
@xml.wp(:comment) do | |
@xml.wp(:comment_id, c.to_param) | |
@xml.wp(:comment_author, c.author) | |
@xml.wp(:comment_author_email, c.email) | |
@xml.wp(:comment_author_url, c.url) | |
@xml.wp(:comment_author_IP, c.originating_ip || "127.0.0.1" ) | |
@xml.wp(:comment_date_gmt, utc(c.created_at)) | |
@xml.wp(:comment_content, c.text) | |
@xml.wp(:comment_approved, "1") | |
@xml.wp(:comment_parent, "0") | |
end | |
end | |
# and same here for entry | |
def export_entry(e) | |
@xml.item do | |
@xml.title(e.title) | |
@xml.link(permalink(e)) | |
@xml.content(:encoded, e.body) | |
@xml.wp(:post_date_gmt, utc(e.created_at)) | |
@xml.wp(:comment_status, e.allow_comments? ? "open" : "closed") | |
e.comments.each(&method(:export_comment)) | |
end | |
end | |
@entries = Inkpot::Models::Entry.find(:all) | |
@xml = Builder::XmlMarkup.new(:target => STDOUT, :indent=>2, :encoding => "utf-8") | |
@xml.instruct! | |
@xml.rss( | |
:version => "2.0", | |
"xmlns:dsq".to_sym => "http://www.disqus.com/", | |
"xmlns:dc".to_sym => "http://purl.org/dc/elements/1.1/", | |
"xmlns:wp".to_sym => "http://wordpress.org/export/1.0/" | |
) do | |
@xml.channel { @entries.each(&method(:export_entry)) } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment