From 6d7e67a90b7e738f17e3601f2129a9430381ae30 Mon Sep 17 00:00:00 2001 From: Ward Wouts Date: Mon, 29 Apr 2002 21:44:36 +0000 Subject: [PATCH] support newsgroup cache for subjects and ids --- trunk/ripnews/news/article.rb | 40 +++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/trunk/ripnews/news/article.rb b/trunk/ripnews/news/article.rb index 3154a50..12b1073 100644 --- a/trunk/ripnews/news/article.rb +++ b/trunk/ripnews/news/article.rb @@ -29,10 +29,12 @@ def add(messid, id, subject) @grouped = false end -def get_articles(group) +def get_articles(group, cachedir=false) + if cachedir + read_cache(group, cachedir) + end resp, count, first, last,name = @nntp.group(group) range = Set::IntSpan.new("#{first}-#{last}") -# for i in (first.to_i..last.to_i) for i in (range.diff(@skip_ids).elements) begin @nntp.stat(i) @@ -50,6 +52,9 @@ def get_articles(group) print "whoopsie couldn't stat #{i}\n" if Debuglevel > 1 end end + if cachedir + save_cache(group, cachedir) + end end def get_groups @@ -158,6 +163,37 @@ def set_skip_ids(ids) return true end +def read_cache(group, cachedir) + filename = "#{cachedir}/#{group}.ripnewscache" + if FileTest.directory?( cachedir) and FileTest.file?( filename ) and FileTest.readable?( filename ) + file = File.new( filename ) + lines = file.readlines + for line in lines + #print "line: #{line}\n" + if line =~ /^(.*?)\|(\d+)\|(.*)$/ + #print "messid: #{$1}\n" + #print "id: #{$2}\n" + #print "subject: #{$3}\n" + add($1, $2, $3) + @skip_ids.insert($2.to_i) + end + end + end +end + +def save_cache(group, cachedir) + filename = "#{cachedir}/#{group}.ripnewscache" + if FileTest.directory?( cachedir) + file = File.new( filename, "w" ) or print "couldn't open cachefile for writing\n" + for i in (0...@subjects.length) + file.print("#{@messids[i]}|#{@ids[i]}|#{@subjects[i]}\n") + #print "writing: #{@messids[i]}|#{@ids[i]}|#{@subjects[i]}\n" + end + end +end + +####################################################################### + def uudecode(data, outfile=nil) case data.type.to_s when "Array"