-
-
Save adamtomecek/3187216 to your computer and use it in GitHub Desktop.
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 'net/http' | |
require 'uri' | |
Earthquake.init do | |
output_filter do |item| | |
next unless item['text'] | |
text = item["text"] | |
text.scan( /http:\/\/t\.co\/[a-zA-Z0-9\-]+/ ).each do |url| | |
uri = URI.parse url | |
Net::HTTP::start( uri.host , uri.port ) do |connection| | |
connection.request_get uri.path do |response| | |
text.gsub! url , response['Location'] unless response['Location'].nil? | |
end | |
end | |
end | |
text | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment