Created
February 14, 2014 14:24
-
-
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.
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
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