public
Created

Export typo comments to disqus using Nokogiri

  • Download Gist
export_wp.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
# RAILS_ENV=production bundle exec rails runner ./script/wp_export.rb >! blog.wxr
# Require nokogiri in Gemfile here
 
site_link = "http://tersesystems.com/"
site_name = "Terse Systems"
 
builder = Nokogiri::XML::Builder.new do |xml|
xml.rss('version' => "2.0",
'xmlns:content' => "http://purl.org/rss/1.0/modules/content/",
'xmlns:wfw' => "http://wellformedweb.org/CommentAPI/",
'xmlns:dsq' => "http://www.disqus.com/",
'xmlns:dc' => "http://purl.org/dc/elements/1.1/",
'xmlns:wp' => "http://wordpress.org/export/1.0/") do |xml|
xml.channel do |xml|
xml.title site_name
xml.link site_link
xml.language "en-us"
xml.ttl "40"
xml.description ""
 
articles = Article.find(:all)
articles.each do |a|
xml.item do |xml|
xml.title a.title
xml.content("Hello world")
xml.pubDate a.published_at.rfc2822
xml['dsq'].thread_identifier "#{site_link}#{a.published_at.strftime("%Y/%m/%d")}/#{a.permalink}"
xml.guid "urn:uuid:#{a.guid}", "isPermaLink" => "false"
author = a.user.name rescue a.author
xml.author author
xml['dc'].creator author
for category in a.categories
xml.category category.name
end
for tag in a.tags
xml.category tag.display_name
end
xml['wp'].post_id a.id
xml['wp'].post_date a.published_at.strftime("%Y-%m-%d %H:%M:%S")
xml['wp'].comment_status 'closed'
xml['wp'].ping_status 'closed'
xml['wp'].post_name a.permalink
xml['wp'].status 'publish'
xml['wp'].post_parent '0'
xml['wp'].post_type 'post'
for comment in a.comments
xml['wp'].comment do |xml|
xml['wp'].comment_id comment.id
xml['wp'].comment_author comment.author
xml['wp'].comment_author_email comment.email
xml['wp'].comment_author_url comment.url
xml['wp'].comment_author_IP comment.ip
xml['wp'].comment_date comment.published_at.strftime("%Y-%m-%d %H:%M:%S")
xml['wp'].comment_content comment.body
xml['wp'].comment_approved '1'
xml['wp'].comment_parent '0'
end
end
end
end
end
end
end
 
puts builder.to_xml

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.