Created
September 23, 2009 12:22
-
-
Save closer/191944 to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/ruby | |
require 'fileutils' | |
require 'open-uri' | |
require 'uri' | |
require 'digest/md5' | |
require 'rubygems' | |
require 'RMagick' | |
require 'simple-rss' | |
CACHE_DIR = '/tmp/eyefi-notify' | |
FEED = "https://api.eye.fi/api/rest/manager/1.0/?method=feeds.get&key=9648bd534b6fe48f7541e8ce428416a4&Locale=ja_JP" | |
FEED_LAST = ENV['HOME'] + "/.eyefi-notify" | |
FileUtils.mkdir_p(CACHE_DIR) unless File.exist?(CACHE_DIR) | |
def get_thumbnail(url) | |
cache_file = "%s/%s" % [ CACHE_DIR, Digest::MD5.hexdigest(url) ] | |
if !File.exist?(cache_file) || (File.atime(cache_file) + 24*60*60) < Time.now | |
File.open(cache_file, "wb") do |f| | |
begin | |
image = open(url.gsub(/amp;/, '')) | |
rimage = Magick::Image.from_blob(image.read).first | |
rimage = rimage.resize_to_fill(48, 48) | |
f << rimage.to_blob | |
rescue Net::ProtocolError | |
return nil | |
end | |
end | |
end | |
cache_file | |
end | |
feed_last = File.exist?(FEED_LAST) ? File.open(FEED_LAST).first.chomp : '' | |
page = open(FEED) | |
rss = SimpleRSS.parse(page) | |
not_sended = true | |
results = rss.items.select do |item| | |
if Digest::MD5.hexdigest(item.guid) == feed_last | |
not_sended = false | |
end | |
not_sended | |
end | |
File.open(FEED_LAST, 'w+').puts Digest::MD5.hexdigest(results.first.guid) if results.size > 0 | |
#puts results.map{|item| item.title }.join("\n") | |
results.reverse_each do |item| | |
system "DISPLAY=:0 notify-send -i '#{get_thumbnail(item.guid)}' -- '#{item.title}' '#{item.description}'" | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment