#!/usr/bin/ruby1.8 -wC/usr/lib/kamille
# katapulte-rss-sender.rb
# This script aims to build mails from rss_cach file
# and then sent it to subscribers
require 'yaml'
require 'homoplate'
require 'time'
require 'cancan'
include Cancan
require 'melanie'
CONFIGURATION = YAML::load( File.open( '/etc/kamille/katapulte.conf' ) )
DB_FILE = CONFIGURATION['feeds_db']
CACHE_DIR = CONFIGURATION['dir_cache']
rss_db = YAML::load( File.new( DB_FILE ) )
date = Time.new.strftime_french( '%d %B %Y' )
summary = "
Nouvelles au #{date}"
rss_db.each do |l|
begin
cache = YAML::load( File.new( CACHE_DIR + "/" +l['name'] + ".yaml" ) )
rescue
puts "No cache file for #{l['name']}, skipping"
next
end
# sorting the articles by date
if cache.respond_to? :sort!
cache.sort! { |a, b|
a[:date] <=> b[:date]
}
end
if cache.respond_to? :length and cache.length >= 1
summary << "#{l['name']}
\n"
summary << "\n"
cache.each { |i|
summary << "- #{i[:title]}
\n"
}
summary << "
\n"
else
puts "No article found, skipping"
end
end
summary << "