Skip to content

Instantly share code, notes, and snippets.

@mikiobraun
Created February 14, 2014 14:24
Show Gist options
  • Save mikiobraun/9001815 to your computer and use it in GitHub Desktop.
Save mikiobraun/9001815 to your computer and use it in GitHub Desktop.
If you know how to Ruby you can torture Twitter's servers, too, now.
require 'rubygems'
require 'net/http'
require 'uri'
require 'hpricot'
def get(url)
uri = URI.parse(url)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Get.new(uri.request_uri)
response = http.request(request)
if response.code != "200"
puts "Ouch, got response status #{response.code}, aborting"
exit
end
return response
end
def drill(start)
s = get(start)
d = Hpricot(s.body)
links = d.search("//p[@class='js-tweet-text tweet-text']/a")
links = links.map {|l| l.attributes['data-expanded-url']}
links = links.reject {|l| l.empty?}.uniq
links = links.select {|l| l =~ /https:\/\/twitter.com\/[^\/]+\/status\/[0-9]+/}
if links.empty?
return nil
else
return links[0]
end
end
counter = 0
start = ARGV[0]
until start.empty?
counter += 1
puts "##{counter} #{start}"
start = drill(start)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment