Skip to content

Instantly share code, notes, and snippets.

@bltavares
Created September 19, 2011 00: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 bltavares/1225749 to your computer and use it in GitHub Desktop.
Save bltavares/1225749 to your computer and use it in GitHub Desktop.
A small bot to show the messages on my party
require "net/http"
require "uri"
require "json"
def send_notify(cur_json)
cur_json["results"].each do |tweet|
puts tweet['text']
`notify-send -t 7000 '#{tweet['text']}'`
sleep 7
end
end
def log_sleep
d = Time.new
puts "Sleeping 10m - next #{d.hour}:#{ d.min + 10}"
sleep 600
end
HOST = "http://search.twitter.com/search.json?q=%40bltavares%20%23festa&result_type=recent&count=5&show_user=true"
#HOST = "http://search.twitter.com/search.json?q=to%3Abltavares%20viado&result_type=recent&count=5&show_user=true"
request = Net::HTTP.get_response(URI.parse(HOST))
ol_json = JSON.parse(request.body)
send_notify(ol_json)
log_sleep
while true
puts "Getting more"
request = Net::HTTP.get_response(URI.parse(HOST))
cur_json = JSON.parse(request.body)
send_notify(cur_json) if cur_json["max_id"] != ol_json["max_id"]
log_sleep
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment