Pastebin is 300% more awesome when you are logged in. Sign Up, it's FREE!
Guest

Untitled

By: a guest on Sep 23rd, 2013  |  syntax: Ruby  |  size: 0.63 KB  |  hits: 153  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
This paste has a previous version, view the difference. Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. require 'sinatra'
  2. require 'hpricot'
  3. require 'open-uri'
  4.  
  5. set :server, 'webrick'
  6.  
  7. class Page
  8.   def initialize(link)
  9.     @link = "https://facebook.com/" + link
  10.     doc = Hpricot(open(@link))
  11.     @title = (doc/"title").inner_text
  12.   end
  13.  
  14.   def link
  15.     @link
  16.   end
  17.  
  18.   def title
  19.     @title
  20.   end
  21.  
  22. end
  23.  
  24.  
  25. get '/' do
  26.   str = File.read('source.html')
  27.   id = /\d{5,20}/
  28.  
  29.   @matches = str.scan id
  30.   @pages = []
  31.   @matches.each do |id|
  32.     @pages << Page.new(id)
  33.   end
  34.  
  35.   erb :index
  36.  
  37. end
  38.  
  39. #index.erb
  40. <% @pages.each do |page| %>
  41.  
  42.   <p> <a href=<%= page.link %>><%= page.link %></a> | <%= page.title %> </p>
  43. <% end %>