#!/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" else puts "No article found, skipping" end end summary << "" m = Melanie.new( {'From' => "admin@cybertigi.com", 'To' => "feeds@radio.org.ml", 'Subject' => "Nouvelles au #{date}" } ) m.add_custom_header( 'X-KamilleMessage-Type', 'NewsReaderContext' ) m.smtp['server'] = CONFIGURATION['smtp_server'] m.smtp['port'] = CONFIGURATION['smtp_port'] File.open( "/tmp/rbgan_news.html", "w+" ) { |f| f.write summary } m.add_message( "Ci-joint, la derniere edition des actualites.\nUtilisez le mode 'telecharger' (download) de Squirrelmail pour la visionner.\n\nGCM Server.", "ISO8859-1", false ) m.add_attachment( "/tmp/rbgan_news.html" ) # m.add_message( summary, "utf-8", true ) m.send begin ; File.delete( "/tmp/rbgan_news.html" ) ; rescue ; end # puts summary