From 146beb0d171a4158abd4e8f7f39c69013aeea99e Mon Sep 17 00:00:00 2001 From: lnu Date: Fri, 22 Jul 2005 08:59:13 +0000 Subject: git-svn-id: svn+ssh://svn.gna.org/svn/feed2imap/trunk/feed2imap@39 f70e237a-67f3-0310-a06c-d2b8a7116972 --- ChangeLog | 1 + feed2imaprc-example | 8 +++++++- lib/feed2imap/config.rb | 30 ++++++++++++++++++++---------- lib/feed2imap/feed2imap.rb | 8 ++++++-- 4 files changed, 34 insertions(+), 13 deletions(-) diff --git a/ChangeLog b/ChangeLog index be85722..aab56b2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,6 @@ Feed2Imap 0.4 (date unknown) ============================ +* added min-frequency and disable config options. Added doc in example config. * You can now use WordPress's feed:http://something urls in feed2imaprc. * Switched to a real SGML parser for the text version. * Much better output for the text version of emails. diff --git a/feed2imaprc-example b/feed2imaprc-example index d539e77..f27e671 100644 --- a/feed2imaprc-example +++ b/feed2imaprc-example @@ -1,6 +1,12 @@ +# name is the name of the feed (must be unique) +# url is the HTTP[S] address where the feed has to be fetched +# target is the IMAP URI where to put emails +# min-frequency (in HOURS) is the minimum frequency with which this particular +# feed will be fetched +# disable: if set to something, the feed will be ignored feeds: - name: feed2imap - url: http://home.gna.org/feed2imap/feed2imap.rss + url: http://home.gna.org/feed2imap/feed2imap.rss target: imap://lucaswebmail:password@imap.apinc.org/INBOX.Feeds.Feed2Imap - name: lucas url: http://www.lucas-nussbaum.net/dotclear/rss.php diff --git a/lib/feed2imap/config.rb b/lib/feed2imap/config.rb index d61d415..8899ef5 100644 --- a/lib/feed2imap/config.rb +++ b/lib/feed2imap/config.rb @@ -37,13 +37,14 @@ class F2IConfig @conf['feeds'] ||= [] @feeds = [] @imap_accounts = ImapAccounts::new - @conf['feeds'].each { |f| - uri = URI::parse(f['target']) - path = uri.path - path = path[1..-1] if path[0,1] == '/' - @feeds.push(ConfigFeed::new(f['name'], f['url'], - @imap_accounts.add_account(uri), path)) - } + @conf['feeds'].each do |f| + if f['disable'].nil? + uri = URI::parse(f['target']) + path = uri.path + path = path[1..-1] if path[0,1] == '/' + @feeds.push(ConfigFeed::new(f, @imap_accounts.add_account(uri), path)) + end + end end def to_s @@ -72,8 +73,17 @@ 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 - url.sub!(/^feed:/, '') + def initialize(f, imapaccount, folder) + @name = f['name'] + @url = f['url'] + @url.sub!(/^feed:/, '') if @url =~ /^feed:/ + @imapaccount, @folder = imapaccount, folder + @freq = f['min-frequency'] + @freq = @freq.to_i if @freq + end + + def needfetch(lastcheck) + return true if @freq.nil? + return (lastcheck + @freq * 3600) < Time::now end end diff --git a/lib/feed2imap/feed2imap.rb b/lib/feed2imap/feed2imap.rb index 59997e8..1ae946c 100644 --- a/lib/feed2imap/feed2imap.rb +++ b/lib/feed2imap/feed2imap.rb @@ -87,9 +87,13 @@ class Feed2Imap @config.feeds.each do |f| ths << Thread::new do begin - f.body = HTTPFetcher::fetch(f.url, @cache.get_last_check(f.name)) + lastcheck = @cache.get_last_check(f.name) + if f.needfetch(lastcheck) + f.body = HTTPFetcher::fetch(f.url, @cache.get_last_check(f.name)) + @cache.set_last_check(f.name, Time::now) + end # dump if requested - if @config.dumpdir + if @config.dumpdir and f.body fname = @config.dumpdir + '/' + f.name + '-' + Time::now.xmlschema File::open(fname, 'w') { |file| file.puts f.body } end -- cgit v1.2.3-70-g09d2 4&id=d041a06226aec18308b846bd90ef99a744367f3e&follow=1'>Add package and category objectsRené 'Necoro' Neumann1-3/+29