support newsgroup cache for subjects and ids
This commit is contained in:
parent
7ef2a9c568
commit
6d7e67a90b
1 changed files with 38 additions and 2 deletions
|
|
@ -29,10 +29,12 @@ def add(messid, id, subject)
|
||||||
@grouped = false
|
@grouped = false
|
||||||
end
|
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)
|
resp, count, first, last,name = @nntp.group(group)
|
||||||
range = Set::IntSpan.new("#{first}-#{last}")
|
range = Set::IntSpan.new("#{first}-#{last}")
|
||||||
# for i in (first.to_i..last.to_i)
|
|
||||||
for i in (range.diff(@skip_ids).elements)
|
for i in (range.diff(@skip_ids).elements)
|
||||||
begin
|
begin
|
||||||
@nntp.stat(i)
|
@nntp.stat(i)
|
||||||
|
|
@ -50,6 +52,9 @@ def get_articles(group)
|
||||||
print "whoopsie couldn't stat #{i}\n" if Debuglevel > 1
|
print "whoopsie couldn't stat #{i}\n" if Debuglevel > 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
if cachedir
|
||||||
|
save_cache(group, cachedir)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_groups
|
def get_groups
|
||||||
|
|
@ -158,6 +163,37 @@ def set_skip_ids(ids)
|
||||||
return true
|
return true
|
||||||
end
|
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)
|
def uudecode(data, outfile=nil)
|
||||||
case data.type.to_s
|
case data.type.to_s
|
||||||
when "Array"
|
when "Array"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue