[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: file name and content not corresponding

Jano Svitok

6/18/2007 9:58:00 AM

On 6/17/07, Tom Bombadil <bombadil.tom@gmail.com> wrote:
> 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|
> file << ( doc/'#vulnerability' ).inner_text
> end
> end
> end