summaryrefslogtreecommitdiff
path: root/lib/feed2imap
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--lib/feed2imap/config.rb30
-rw-r--r--lib/feed2imap/feed2imap.rb8
2 files changed, 26 insertions, 12 deletions
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