Skip to content

Instantly share code, notes, and snippets.

@haruyama
Created August 9, 2012 07:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save haruyama/3301828 to your computer and use it in GitHub Desktop.
Save haruyama/3301828 to your computer and use it in GitHub Desktop.
convert livedoor clip xml to delicious html.
#!/usr/bin/env ruby
# -*- encoding: utf-8 -*-
require 'rexml/document'
require 'cgi'
require 'time'
DT_TEMPLATE=<<EOS
<DT><A HREF="%s" ADD_DATE="%d" PRIVATE="0" TAGS="%s">%s</A>
EOS
DD_TEMPLATE=<<EOS
<DD>%s
EOS
print <<EOS
<!DOCTYPE NETSCAPE-Bookmark-file-1>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
<TITLE>Bookmarks</TITLE>
<H1>Bookmarks</H1>
<DL><p>
EOS
open(ARGV[0]) { |xml|
doc = REXML::Document.new xml
doc.elements.each('//channel/item') { |e|
title = e.elements['title'].text || ''
desc = e.elements['description'].text
url = e.elements['link'].text
date = Time.parse(e.elements['pubDate'].text).to_i
tags = e.elements.to_a('dc:subject').map{|s| s.text.gsub(',', ' ')}.join(',')
printf DT_TEMPLATE, CGI.escapeHTML(url), date, CGI.escapeHTML(tags), CGI.escapeHTML(title)
printf DD_TEMPLATE, CGI.escapeHTML(desc) if desc && !desc.empty?
}
}
print <<EOS
</DL><p>
EOS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment