Created
July 30, 2012 21:07
-
-
Save tlehman/3210241 to your computer and use it in GitHub Desktop.
Disqus comment xml output
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
| require 'sequel' | |
| require 'builder' | |
| def export_comments_to_wxr(dbinfo) | |
| db = Sequel.connect("mysql2://#{dbinfo[:user]}:#{dbinfo[:pass]}@localhost/#{dbinfo[:dbname]}") | |
| comments = db[:posts].graph(:comments, :post_id=>:id).filter(:spam=>0).to_a | |
| posts = db[:posts].to_a | |
| xml = Builder::XmlMarkup.new(:target => STDOUT, :indent => 2) | |
| xml.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/" do |r| | |
| r.channel do |c| | |
| posts.each do |p| | |
| builder = Builder::XmlMarkup.new | |
| comments.each do |comment| | |
| c.item do |i| | |
| i.title comment[:posts][:title] | |
| i.link "http://#{dbinfo[:url]}/posts/#{comment[:comments][:post_id]}" | |
| i.tag!("content:encoded") { |j| j.cdata! comment[:posts][:body] } | |
| i.tag!("dsq:thread_identifier", "sw#{comment[:posts][:id]}") | |
| i.tag!("wp:post_date_gmt", comment[:posts][:created_at]) | |
| i.tag!("wp:comment_status", "open") | |
| i.tag!("wp:comment") do |wc| | |
| wc.tag!("wp:comment_id", comment[:comments][:id]) | |
| wc.tag!("wp:comment_author_name", comment[:comments][:name]) | |
| wc.tag!("wp:comment_author_email", comment[:comments][:email]) | |
| wc.tag!("wp:comment_author_url", comment[:comments][:website]) | |
| wc.tag!("wp:comment_author_IP", "") | |
| wc.tag!("wp:comment_date_gmt", comment[:comments][:created_at]) | |
| wc.tag!("wp:comment_content") { |j| j.cdata! comment[:comments][:body] } | |
| wc.tag!("wp:comment_approved", "1") | |
| wc.tag!("wp:comment_parent", comment[:comments][:id]) | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment