Skip to content

Instantly share code, notes, and snippets.

@siyo
Created October 10, 2011 04:17
Show Gist options
  • Save siyo/1274624 to your computer and use it in GitHub Desktop.
Save siyo/1274624 to your computer and use it in GitHub Desktop.
@eew_jp 氏をgrowlするearthquake.gem plugin
# -*- coding: utf-8 -*-
# kinkyuu jisin sokuhou (@eew_jp) earthguake.gem plugin
#
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["user"]["screen_name"] == 'eew_jp')
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))
place,sindo = item["text"].scan(/\d+:\d+頃、(.+)の深さ.+(震度\d.*)です/).flatten
arg = {
"-t" => "%s : %s" % [place, sindo],
"-m" => item["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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment