-
-
Save jaspertandy/1385833 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'] | |
end | |
end | |
end | |
text | |
end | |
end |
Ah, I actually came across a similar issue using this previously. The problem actually stems from the core code of earthquake, in that the tweet body of a retweet is stored in a different variable to a regular tweet, which is quite annoying! I ended up (probably foolishly) making a modification to the core of earthquake to fix the issue for myself, but the modification I've made to the existing gist should skirt the issue (though you may still see t.co in retweets).
Hi,
Thx for this plugin, it's working great. However I encounter the same erroneous behavior with the latest version of your script.
You said you modified the core, that would be interesting to know what you modified.
Here's the stacktrace that appear in the console for reference:
earthquake: [ERROR] can't convert nil into String
/Users/brice/.earthquake/plugin/expand_tco.rb:11:in `gsub!'
/Users/brice/.earthquake/plugin/expand_tco.rb:11:in `block (5 levels) in <top (required)>'
/usr/local/Cellar/ruby/1.9.3-p0/lib/ruby/1.9.1/net/http.rb:1322:in `block (2 levels) in transport_request'
/usr/local/Cellar/ruby/1.9.3-p0/lib/ruby/1.9.1/net/http.rb:2671:in `reading_body'
/usr/local/Cellar/ruby/1.9.3-p0/lib/ruby/1.9.1/net/http.rb:1321:in `block in transport_request'
/usr/local/Cellar/ruby/1.9.3-p0/lib/ruby/1.9.1/net/http.rb:1316:in `catch'
/usr/local/Cellar/ruby/1.9.3-p0/lib/ruby/1.9.1/net/http.rb:1316:in `transport_request'
/usr/local/Cellar/ruby/1.9.3-p0/lib/ruby/1.9.1/net/http.rb:1293:in `request'
/usr/local/Cellar/ruby/1.9.3-p0/lib/ruby/1.9.1/net/http.rb:1195:in `request_get'
/Users/brice/.earthquake/plugin/expand_tco.rb:10:in `block (4 levels) in <top (required)>'
/usr/local/Cellar/ruby/1.9.3-p0/lib/ruby/1.9.1/net/http.rb:745:in `start'
/usr/local/Cellar/ruby/1.9.3-p0/lib/ruby/1.9.1/net/http.rb:557:in `start'
/Users/brice/.earthquake/plugin/expand_tco.rb:9:in `block (3 levels) in <top (required)>'
/Users/brice/.earthquake/plugin/expand_tco.rb:7:in `each'
/Users/brice/.earthquake/plugin/expand_tco.rb:7:in `block (2 levels) in <top (required)>'
/usr/local/Cellar/ruby/1.9.3-p0/lib/ruby/gems/1.9.1/gems/earthquake-0.8.4/lib/earthquake/output.rb:36:in `call'
/usr/local/Cellar/ruby/1.9.3-p0/lib/ruby/gems/1.9.1/gems/earthquake-0.8.4/lib/earthquake/output.rb:36:in `block (2 levels) in puts_items'
/usr/local/Cellar/ruby/1.9.3-p0/lib/ruby/gems/1.9.1/gems/earthquake-0.8.4/lib/earthquake/output.rb:36:in `each'
/usr/local/Cellar/ruby/1.9.3-p0/lib/ruby/gems/1.9.1/gems/earthquake-0.8.4/lib/earthquake/output.rb:36:in `any?'
https://gist.github.com/3187216
Fixed problem I was getting with empty String with some links.
@adamtomecek Thank's a lot for this!
This solved the issue :)
https://gist.github.com/Kjwon15/9657129
I fixed it doesn't applied for item object.
Thanks for writing this, it's helps a lot since the t.co URLs are opaque. Unfortunately, I've encountered a bug with it. Occasionally this plugin throws `gsub!': can't convert nil into String (TypeError) It's related to retweets, since I can reproduce the crash by retweeting certain tweets. (one, two)
If the error happens during a :recent command, it stops printing the recent tweets and puts the error message into a notification (libnotify in my ruby install). If it errors during streaming API mode, then the error is dumped to the shell and earthquake exits.
Examples:
The above tweet. The tweet that followed, was a retweet of this, by @exiledonline.
The above tweet was a retweet of this by @exiledonline. The tweet that followed, was a retweet of this, by @exiledonline. (The url wasn't expanded on the non-crashing @dylanratigan tweet, but that's not an issue)
If I knew my way around ruby I'd try to fix it myself, but I can't even see a pattern in the source tweets that would cause it. It works without a hitch 99% of the time, so I'll use it regardless.