Created
September 21, 2013 10:38
-
-
Save snipsnipsnip/6649328 to your computer and use it in GitHub Desktop.
Dump Jibberbook's comments.xml as Disqus importable WXR
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/bin/ruby-1.9 | |
require 'nokogiri' | |
# cf. http://help.disqus.com/customer/portal/articles/472150 | |
def tag(n,c='') "<#{n}>#{c}</#{n}>" end | |
def t(n,c='') print tag(n, c) end | |
doc = File.open("comments.xml", encoding:'utf-8'){|f| Nokogiri::XML f } | |
print <<EOS | |
<?xml version="1.0" encoding="UTF-8"?> | |
<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/" | |
><channel><item> | |
EOS | |
t :title, 'guestbook' | |
t :link, 'http://example.com' | |
t :'content:encoded' | |
t 'dsq:thread_identifier', 'foo' | |
t 'wp:ost_date_gmt' | |
(doc/:message).each_with_index do |m, i| | |
print '<wp:comment>' | |
t 'wp:comment_id', i | |
t 'wp:comment_author', m.%(:name).text | |
t 'wp:comment_author_email', '' # intentionally drop emails | |
t 'wp:comment_author_url', m.%(:website).text | |
t 'wp:comment_author_IP', m.%(:user_ip).text | |
t 'wp:comment_date_gmt', Time.at(m.%(:date).text.to_i).getgm.to_s[0..18] | |
t 'wp:comment_content', "<![CDATA[#{m.%(:comment).text}]]>" | |
t 'wp:comment_approved', 1 | |
t 'wp:comment_parent', '' | |
puts '</wp:comment>' | |
end | |
puts '</item></channel></rss>' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment