Created
October 10, 2011 02:18
-
-
Save siyo/1274497 to your computer and use it in GitHub Desktop.
earthquake.gem plugin: fav and follow events growl notifer
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
# -*- coding: utf-8 -*- | |
# event_notifer+ plugin | |
# | |
require "fileutils" | |
require "digest/md5" | |
Earthquake.init do | |
dir = File.join(File.dirname(__FILE__), "userimage") | |
output do |item| | |
if item["event"] && item["source"]["screen_name"] != twitter.info["screen_name"] | |
begin | |
image_url = item["source"]["profile_image_url"] | |
next unless image_url | |
name = Digest::MD5.hexdigest image_url | |
path = File.join(dir, name.chars.first, name) | |
FileUtils.mkdir_p(File.dirname(path)) | |
text = item["target_object"] ? item["target_object"]["text"] : item["event"] | |
arg = { | |
"-t" => "#{item["event"].capitalize}: #{item["source"]["screen_name"]}", | |
"-m" => "#{item["target"]["screen_name"]}: #{text}", | |
"--image" => path, | |
"--sticky" => "" # comment out this line if you want off "Growl sticky" | |
} | |
EM.defer( | |
lambda { | |
return path if File.exists?(path) | |
open(path, "w"){|f| | |
f.print open(image_url).read | |
} | |
path | |
}, | |
lambda {|path| | |
system('growlnotify', *arg.to_a.flatten) | |
} | |
) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment