Created
August 3, 2008 12:48
-
-
Save motemen/3822 to your computer and use it in GitHub Desktop.
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 | |
require 'open-uri' | |
require 'rss/1.0' | |
require 'rss/2.0' | |
require 'rss/dublincore' | |
require 'rubygems' | |
require 'hatenabm' | |
HATENA_USER = '' | |
HATENA_PASS = '' | |
DELICIOUS_USER = '' | |
def get_content(url) | |
open(url) { |f| content = f.read } | |
end | |
def parse_rss(content) | |
begin | |
RSS::Parser.parse(content) | |
rescue RSS::InvalidRSSError | |
RSS::Parser.parse(content, false) | |
end | |
end | |
begin | |
url = "http://b.hatena.ne.jp/#{HATENA_USER}/rss" | |
content = get_content(url) | |
last_update = parse_rss(content).items[0].dc_date.getlocal | |
url = "http://feeds.delicious.com/v2/rss/#{DELICIOUS_USER}" | |
content = get_content(url) | |
rss = parse_rss(content) | |
i = 0 | |
rss.items.each do |item| | |
break if item.pubDate.getlocal < last_update | |
i += 1 | |
end | |
if i.zero? | |
exit | |
else | |
i -= 1 | |
end | |
hbm = HatenaBM.new( | |
:user => HATENA_USER, | |
:pass => HATENA_PASS | |
) | |
i.downto(0) do |j| | |
begin | |
item = rss.items[j] | |
p item | |
hbm.post( | |
:title => item.title ? item.title : "", | |
:link => item.link ? item.link : "", | |
:summary => item.description ? item.description : "", | |
:tags => item.categories ? item.categories.map { |c| c.content } .join(' ') : "" | |
) | |
rescue => e | |
$stderr.puts $! | |
$stderr.puts e | |
next | |
end | |
sleep(1) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment