Last active
August 29, 2015 14:02
-
-
Save kachina/0ecfb23d410c9494eb2e to your computer and use it in GitHub Desktop.
earthquake-notify-send.rb
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 "fileutils" | |
require "digest/md5" | |
Earthquake.init do | |
dir = File.join(File.dirname(__FILE__), "userimage") | |
output do |item| | |
next if item.nil? || item['user'].nil? || item['_stream'].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 = [ | |
"--urgency=low", | |
"--icon=#{path}", | |
"--expire-time=30", | |
item['user']['screen_name'], | |
"\"#{item['text']}\"" | |
] | |
EM.defer( | |
lambda { | |
return path if File.exists?(path) | |
open(path, "w"){|f| | |
f.print open(image_url).read | |
} | |
path | |
}, | |
lambda {|path| | |
system('notify-send', *arg) | |
} | |
) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment