Skip to content

Instantly share code, notes, and snippets.

@siyo siyo/growl-all.rb forked from uu59/growl-all.rb
Created Oct 19, 2011

Embed
What would you like to do?
# -- coding: utf-8
require "fileutils"
require "digest/md5"
Earthquake.init do
dir = File.join(File.dirname(__FILE__), "userimage")
output do |item|
next if item.nil? || item["user"].nil?
begin
image_url = item["user"]["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))
arg = {
"-n" => "growl-all.rb",
"-t" => "#{item["user"]["screen_name"]}",
"-m" => item["text"],
"--image" => path,
}
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.