Created
February 23, 2009 15:38
-
-
Save koduki/69004 to your computer and use it in GitHub Desktop.
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 -*- | |
require 'open-uri' | |
require 'uri' | |
require 'tmpdir' | |
require 'fileutils' | |
require 'digest/md5' | |
id = "koduki" | |
sound = '/usr/share/sounds/purple/receive.wav' | |
configatron.plugins.k_notify.set_default(:icon_cache_dir, "#{Dir.tmpdir}/termtter-icon-cache-dir") | |
FileUtils.mkdir_p(configatron.plugins.k_notify.icon_cache_dir) unless File.exist?(configatron.plugins.k_notify.icon_cache_dir) | |
def get_icon_path s | |
cache_file = "%s/%s%s" % [ configatron.plugins.k_notify.icon_cache_dir, | |
Digest::MD5.hexdigest(s.user_profile_image_url), | |
File.extname(s.user_profile_image_url) ] | |
if File.exist?(cache_file) | |
cache_file | |
else | |
tmp = open(URI.escape(s.user_profile_image_url)).read | |
File.open(cache_file , "wb") do |f| | |
f << tmp | |
end.path | |
end | |
end | |
Termtter::Client.add_hook do |statuses, event| | |
if !statuses.empty? && event == :update_friends_timeline | |
system 'aplay', sound if statuses.any?{|s| !s.text.scan(id).empty? } | |
statuses.find_all{|s| !s.text.scan(id).empty? }.each do |s| | |
Thread.new do | |
status_text = CGI.escapeHTML(s.text) | |
status_text.gsub!(%r{https?://[-_.!~*\'()a-zA-Z0-9;\/?:\@&=+\$,%#]+},'<a href="\0">\0</a>') | |
system 'notify-send', s.user_screen_name, status_text, '-t', '20000', '-i', get_icon_path(s) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment