#!/usr/bin/env ruby
#
# Created by Steve Ivy on 2007-02-01.
# Copyright (c) 2007. All rights reserved.
require 'rubygems'
require 'open-uri'
require 'hpricot'
require 'mofo'
require 'pp'
require 'active_support'
class Feed
def initialize(title, url, type)
@title = title
@url = url
@type = type
end
attr_accessor :title
attr_accessor :url
attr_accessor :type
end
def get_doc(uri)
begin
doc = Hpricot open(uri)
return doc
rescue StandardError => poof
puts "Error: #{poof}"
end
nil
end
def check_site(uri)
doc= get_doc uri
pfeeds=[]
if doc
links = doc/"link [@rel='alternate'][@type]" #returns Hpricot::Elements
#pp links
links.each do |link|
if kind = link[:type][/(rss|atom)\+xml/i,1]
kind.downcase!
pfeeds << Feed.new(link[:title], link[:href], kind)
end
end
end
pfeeds
end
URL = ARGV[0] || 'http://redmonk.net/about-this-site'
hcard = HCard.find(URL)[0]
if (hcard)
puts "Welcome #{hcard.fn}..."
end
puts "checking #{URL} for your other sites..."
######
# defunkt:
#
# I'd rather use mofo to do this:
#
# mes = XFN.find(URL).me
#
startdoc = get_doc URL
rels = startdoc/"a [@rel]"
urlstocheck=[]
possiblefeeds=[]
rels.each do |a|
urlstocheck << a[:href] if a[:rel]=~/ ?me ?/ and a[:href]=~/http\:\/\//
end
urlstocheck.each do |u|
puts "Checking #{u} for subscribable content"
possiblefeeds.concat check_site(u)
end
if (hcard.nickname)
puts "
Good, I found nicknames: #{hcard.nickname.to_sentence }."
puts "I'm going to each one as a username, and see if I can find anything interesting "+
"on some popular sites."
SERVICES = { # use with sprintf
"Del.icio.us" => "http://del.icio.us/%s",
"Ma.gnolia" => "http://ma.gnolia.com/People/%s",
"Flickr" => "http://flickr.com/photos/%s",
"Last.fm" => "http://last.fm/user/%s/",
#"Cork'd" => "http://corkd.com/people/%s/feeds"
}
hcard.nickname.each do |nick|
SERVICES.each do |name, url|
puts "Checking #{name}: #{url % nick} for subscribable content"
possiblefeeds.concat check_site(url % nick)
end
end
end
puts "
This what I found:
"
possiblefeeds.each_with_index do |feed, i|
puts "[#{i+1}] #{URI(feed.url).host}: #{feed.title} (#{feed.url}, #{feed.type})"
end