File name and content not corresponding

Hi folks,

The code below almost works perfect. Thus it creates the text files with the
right content. However, the name of the text file should correspond to the
Bugtraq ID. As of now it's Bugtraq ID 1 and 3.txt, 2-2, and Bugtraq ID 3 -
1.txt. What do I have to correct? Is it index - 1?

Thanks,
Tom

# Initialize Logger
require 'logger'
root_logger = Logger.new 'root.log'
root_logger.level = Logger::INFO

# Setup at_exit hook
at_exit { root_logger.info 'done.' }

%w{ rubygems hpricot open-uri }.each { |lib| require lib }
URL_MASK = ‘http://www.securityfocus.com/bid/%i’.freeze<http://www.securityfocus.com/bid/%i’.freeze>

tgroup = ThreadGroup.new

root_logger.info 'Parsing SecurityFocus...'
( 1 .. 3 ).each do |id|
  root_logger.info " open #{ URL_MASK % id }"
  thread = Thread.new do
    begin
      Hpricot open( URL_MASK % id )
    rescue => error
      root_logger.error error.inspect
    end
  end
  tgroup.add thread
end

tgroup.list.each_with_index do |thread, index|
  if doc = thread.value
    File.open( "#{ index + 1 }.txt", 'w+' ) do |file|
      file << ( doc/'#vulnerability' ).inner_text
    end
  end
end

Hi folks,

The code below almost works perfect. Thus it creates the text files with the
right content. However, the name of the text file should correspond to the
Bugtraq ID. As of now it's Bugtraq ID 1 and 3.txt, 2-2, and Bugtraq ID 3 -
1.txt. What do I have to correct? Is it index - 1?

Thanks,
Tom

What about more explicit id using thread-local storage:
...

tgroup = ThreadGroup.new

root_logger.info 'Parsing SecurityFocus...'
( 1 .. 3 ).each do |id|
  root_logger.info " open #{ URL_MASK % id }"
  thread = Thread.new do
    begin
      Hpricot open( URL_MASK % id )
    rescue => error
      root_logger.error error.inspect
    end
  end

+ thread[:bug_id] = id

  tgroup.add thread
end

- tgroup.list.each_with_index do |thread, index|
+ tgroup.list.each do |thread|

  if doc = thread.value

- File.open( "#{ index + 1 }.txt", 'w+' ) do |file|
+ File.open( "#{thread[:bug_id]}.txt", 'w+' ) do |file|

···

On 6/17/07, Tom Bombadil <bombadil.tom@gmail.com> wrote:

      file << ( doc/'#vulnerability' ).inner_text
    end
  end
end