From edd60fa2d3c972932da7be1605fec2674069c31b Mon Sep 17 00:00:00 2001 From: lnu Date: Tue, 5 Apr 2005 14:40:15 +0000 Subject: git-svn-id: svn+ssh://svn.gna.org/svn/feed2imap/trunk/feed2imap@11 f70e237a-67f3-0310-a06c-d2b8a7116972 --- lib/feed2imap/config.rb | 1 + lib/feed2imap/feed2imap.rb | 25 ++++++++++++++++--------- 2 files changed, 17 insertions(+), 9 deletions(-) (limited to 'lib') diff --git a/lib/feed2imap/config.rb b/lib/feed2imap/config.rb index 002db3e..a784b91 100644 --- a/lib/feed2imap/config.rb +++ b/lib/feed2imap/config.rb @@ -70,6 +70,7 @@ end # A configured feed. simple data container. class ConfigFeed attr_reader :name, :url, :imapaccount, :folder + attr_accessor :body def initialize(name, url, imapaccount, folder) @name, @url, @imapaccount, @folder = name, url, imapaccount, folder diff --git a/lib/feed2imap/feed2imap.rb b/lib/feed2imap/feed2imap.rb index 92cab8f..3131587 100644 --- a/lib/feed2imap/feed2imap.rb +++ b/lib/feed2imap/feed2imap.rb @@ -69,22 +69,26 @@ class Feed2Imap exit(1) end end - # for each feed, fetch, upload to IMAP and cache + # check that IMAP folders exist + @logger.info("Checking IMAP folders") @config.feeds.each do |f| - @logger.info("Processing #{f.url}") begin - # check that folder exist f.imapaccount.create_folder(f.folder) if not f.imapaccount.folder_exist?(f.folder) rescue @logger.fatal("Error while creating IMAP folder #{f.folder}: #{$!}") exit(1) end + end + # for each feed, fetch, upload to IMAP and cache + @logger.info("Fetching feeds") + @config.feeds.each do |f| + @logger.info("Processing #{f.name}") begin - body = HTTPFetcher::fetch(f.url, @cache.get_last_check(f.name)) + f.body = HTTPFetcher::fetch(f.url, @cache.get_last_check(f.name)) # dump if requested if @config.dumpdir fname = @config.dumpdir + '/' + f.name + '-' + Time::now.xmlschema - File::open(fname, 'w') { |file| file.puts body } + File::open(fname, 'w') { |file| file.puts f.body } end rescue Timeout::Error @logger.fatal("Timeout::Error while fetching #{f.url}: #{$!}") @@ -93,17 +97,20 @@ class Feed2Imap @logger.fatal("Error while fetching #{f.url}: #{$!}") next end - next if body.nil? # means 304 + end + @logger.info("Parsing and uploading") + @config.feeds.each do |f| + next if f.body.nil? # means 304 begin - channel = Channel::new(body) + channel = Channel::new(f.body) rescue - @logger.fatal("Error while parsing #{f.url}: #{$!}") + @logger.fatal("Error while parsing #{f.name}: #{$!}") next end begin newitems, updateditems = @cache.get_new_items(f.name, channel.items) rescue - @logger.fatal("Exception caught when selecting new items for #{f.url}: #{$!}") + @logger.fatal("Exception caught when selecting new items for #{f.name}: #{$!}") puts $!.backtrace next end -- cgit v1.2.3-70-g09d2