class LinkList def initialize with_file_named @links = [] @file_name = with_file_named end def outbound_links self.import_links @links.sort.uniq end def import_links File.open @file_name do |file| (file.gets nil).scan /()/i do |a, b, c| @links << b end end end end class Neighborhood def initialize with_file_named @neighbors = Hash.new 0 @linkList = LinkList.new with_file_named end def neighboring_links neighboring_links = Hash.new 0 @linkList.outbound_links.each do |link| neighboring_links.update ((BlogdexScanner.new).scan link) #neighboring_links.update ((DaypopScanner.new).scan link) end neighboring_links.keys.sort do |a, b| neighboring_links[b] <=> neighboring_links[a] end neighboring_links.keys.sort.uniq end end class Scanner def scan with_url result = Hash.new 0 require "net/http" connection = self.make_connection begin url = self.make_url with_url ignored, data = connection.get url, nil data.scan self.regexp do |a, b, c| result[self.format_url b] += 1 end rescue EOFError end result end def format_url url url end end class BlogdexScanner < Scanner def make_connection Net::HTTP.new "blogdex.media.mit.edu", 80 end def make_url with_url "/browseSource.asp?url=#{with_url.gsub /:/, '%3A'}" end def regexp /()([^<]*)(<\/span>)/ end def format_url url "http://#{url}" end end class DaypopScanner < Scanner def make_connection Net::HTTP.new "www.daypop.com", 80 end def make_url with_url "/search?q=link%3A#{with_url.gsub /http:\/\//, ''}&t=w" end def regexp /( ]*)(>)/ end end neighborhood = Neighborhood.new ARGV[0] links = neighborhood.neighboring_links exit if links.size == 0 print "
Network:\n" i = 0 links.each do |link| (print "\n| ") if i > 0 print "#{link.gsub /http:\/\//, ''}" i += 1 end print "\n
\n"