Skip to content

Instantly share code, notes, and snippets.

@tribela
Forked from adamtomecek/expand_tco.rb
Created March 20, 2014 04:14
Show Gist options
  • Select an option

  • Save tribela/9657129 to your computer and use it in GitHub Desktop.

Select an option

Save tribela/9657129 to your computer and use it in GitHub Desktop.
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
item["text"] = text
end
end
@tribela
Copy link
Copy Markdown
Author

tribela commented Mar 20, 2014

apply changed text

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment