Created
August 9, 2012 07:04
-
-
Save haruyama/3301828 to your computer and use it in GitHub Desktop.
convert livedoor clip xml to delicious html.
This file contains 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/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