Skip to content

Instantly share code, notes, and snippets.

@ELLIOTTCABLE
Created April 22, 2009 13:09
Show Gist options
  • Select an option

  • Save ELLIOTTCABLE/99784 to your computer and use it in GitHub Desktop.

Select an option

Save ELLIOTTCABLE/99784 to your computer and use it in GitHub Desktop.
This script watches the status of your API request limit on Twitter.
require 'open-uri'
require 'json'
User = 'somebody'
Pass = 's3kr3tl0l'
cache = {}
while true
[[User, Pass], nil].each do |auth|
status = JSON.parse(open('http://twitter.com/account/rate_limit_status.json', :http_basic_authentication => auth).read)
unless cache[auth] && cache[auth] == status['remaining_hits']
eta = status['reset_time_in_seconds'] - Time.now.to_i
puts "#{auth ? 'User' : 'IP'}:\t#{status['remaining_hits']} (reset: #{eta / 60}m #{eta % 60}s)"
cache[auth] = status['remaining_hits']
end
end
sleep 1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment