Skip to content

Instantly share code, notes, and snippets.

@no6v
Created April 13, 2011 16:06
Show Gist options
  • Save no6v/917830 to your computer and use it in GitHub Desktop.
Save no6v/917830 to your computer and use it in GitHub Desktop.
Earthquake.init do
icon_dir = File.join(config[:plugin_dir], "icons")
icon_path = ->(item){
icon_file = File.join(icon_dir, item["user"]["screen_name"])
mtime = File.exist?(icon_file) ? File.mtime(icon_file) : Time.at(0)
begin
image = open(item["user"]["profile_image_url"], "If-Modified-Since" => mtime.rfc2822, &:read)
File.open(icon_file, "wb"){|f| f.write(image)}
rescue OpenURI::HTTPError
end
icon_file
}
once do
FileUtils.mkdir_p(icon_dir)
end
command /^:notify( .*)?$/, :as => :notify do |m|
config[:notify] = (/^on$/i === m[1].strip) if m[1]
puts "notify is " + (config[:notify] ? "on" : "off")
end
output :notify do |item|
if config[:notify] && item["_stream"] && item["text"]
icon = icon_path[item]
# notify(item["text"], :title => item["user"]["screen_name"], :icon => icon)
system "notify-send", "-i", icon, item["user"]["screen_name"], item["text"].e
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment