forked from zeke/griffin
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added script and wrote a little readme
- Loading branch information
Showing
3 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
What tweets and growls? A Griffin. | ||
|
||
The griffin is a legendary creature with the body of a lion and the head and often wings of an eagle. This ruby script pulls down your twitter public timeline at an interval of your choosing and creates growl notifications for the new messages. | ||
|
||
It's a work in progress, mutated from someone else's hard work: http://pastie.org/44304 |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Requires the following gems: xml-simple and ruby-growl (http://segment7.net/projects/ruby/growl/) | ||
|
||
require 'net/http' | ||
require 'rubygems' | ||
require 'xmlsimple' | ||
require 'ruby-growl' | ||
require 'time' | ||
|
||
@@config = {:username => 'zeke', :password => 'secret', :frequency => 1} | ||
|
||
def call_twitter(method, arg_options={}) | ||
options = { :auth => true }.merge(arg_options) | ||
|
||
path = "/statuses/#{method.to_s}.xml" | ||
headers = { "User-Agent" => @@config[:username] } | ||
|
||
begin | ||
response = Net::HTTP.start('twitter.com', 80) do |http| | ||
req = Net::HTTP::Get.new(path, headers) | ||
req.basic_auth(@@config[:username], @@config[:password]) if options[:auth] | ||
http.request(req) | ||
end | ||
|
||
response.body | ||
rescue Exception | ||
return nil | ||
end | ||
end | ||
|
||
g = Growl.new "127.0.0.1", "squawk", ["squawk Notification"] | ||
last_fetch = Time.now | ||
|
||
while true do | ||
puts "checkin' it out" | ||
xml = call_twitter(:friends_timeline) | ||
unless xml.nil? | ||
doc = XmlSimple.xml_in(xml) | ||
raise doc.to_yaml | ||
doc['status'].reverse.each do |status| | ||
if status['user'] | ||
g.notify "squawk Notification", status['user'][0]['name'].to_s, status['text'].to_s if Time.parse(status['created_at'].to_s) > last_fetch | ||
end | ||
end | ||
|
||
last_fetch = Time.now | ||
end | ||
sleep @@config[:frequency] * 60 | ||
end |