Created
September 19, 2011 00:16
-
-
Save bltavares/1225749 to your computer and use it in GitHub Desktop.
A small bot to show the messages on my party
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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