Skip to content

Instantly share code, notes, and snippets.

@chubas
Created August 26, 2010 17:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chubas/551799 to your computer and use it in GitHub Desktop.
Save chubas/551799 to your computer and use it in GitHub Desktop.
Twitter status sanity
require 'json'
require 'net/http'
require 'uri'
status = JSON.parse Net::HTTP.get(URI.parse("http://api.twitter.com/1/account/rate_limit_status.json"))
red, green, reset = "\e[31m", "\e[32m", "\e[0m"
wait = (Time.at(status["reset_time_in_seconds"].to_i) - Time.now).to_i
if (hits = status["remaining_hits"]).zero?
puts "#{red}Oops#{reset}, seems you have to wait another #{red}#{wait / 60} mins, #{wait % 60} secs#{reset}."
else
puts "#{green}Good!#{reset}, you still have #{green}#{hits}#{reset} left for the next #{green}#{wait / 60} mins, #{wait % 60} secs#{reset}."
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment