diff options
author | lnu <lnu@f70e237a-67f3-0310-a06c-d2b8a7116972> | 2005-04-05 14:40:15 +0000 |
---|---|---|
committer | lnu <lnu@f70e237a-67f3-0310-a06c-d2b8a7116972> | 2005-04-05 14:40:15 +0000 |
commit | edd60fa2d3c972932da7be1605fec2674069c31b (patch) | |
tree | a29b21e1022d5d36c065bf558bbe44eee36f611d | |
parent | 3417edeaabcb2e23bb0d13d984e353385d183f82 (diff) | |
download | feed2imap-edd60fa2d3c972932da7be1605fec2674069c31b.tar.gz feed2imap-edd60fa2d3c972932da7be1605fec2674069c31b.tar.bz2 feed2imap-edd60fa2d3c972932da7be1605fec2674069c31b.zip |
git-svn-id: svn+ssh://svn.gna.org/svn/feed2imap/trunk/feed2imap@11 f70e237a-67f3-0310-a06c-d2b8a7116972
Diffstat (limited to '')
-rw-r--r-- | lib/feed2imap/config.rb | 1 | ||||
-rw-r--r-- | lib/feed2imap/feed2imap.rb | 25 |
2 files changed, 17 insertions, 9 deletions
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 |