Python to Ruby: How do I open a file, parse the data and multithread with it?
Question: I need to translate this into Ruby:

    
    
    ids = [i.strip() for i in open('ids.txt','r')]
    proxies = [i.strip() for i in open('socks.txt','r')]
    for (i,j) in izip(ids,proxies):
        i = parseID(i)
        j = j.split(':')
        threading.Thread(target=raider,args=(i,j)).start()
    

This is just showing you what's happening with it:

    
    
    def parseID(auser3):
    auser3 = auser3.split('&')
    userid = auser3[1].split('=')[1]
    k1 = auser3[2].split('=')[1]
    k2 = auser3[3].split('=')[1]
    return [userid,k1,k2]
    return l5
    
    def raider(a3,p):
    global ip
    global port
    try:
        socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS4, p[0], int(p[1]))
        socket.test = socks.socksocket
        xat = socket.test(socket.AF_INET, socket.SOCK_STREAM, socket.SOL_TCP)
        xat.connect((ip,int(port)))
        xat.send('<y r="'+str(info[2])+'" />\0')
        bypass = xat.recv(1024)
        print "\nRecv --> "+bypass+"\n"
        rcv = tree.fromstring(bypass.strip("\0"))
        if 'i' not in rcv.attrib:
            raise Exception("YUP")
        import pprint
        pprint.pprint(a3)
        print p[0]+":"+p[1]+"\n\n"
        uid = a3[0]
        k = a3[1]
        Y = getY(rcv.attrib["au"], rcv.attrib["p"].split("_")[0],rcv.attrib["p"].split("_")[1],rcv.attrib["p"].split("_")[2],rcv.attrib["p"].split("_")[3], rcv.attrib["i"])
        j2 = str('<j2 cb="'+rcv.attrib["c"]+'" Y="'+str(Y[0])+'" l5="'+str(Y[1]).strip()+'" l4="583" l3="463" l2="0" q="1" y="'+rcv.attrib['i']+'" k="'+k+'" k3="0" p="0" c="'+str(info[2])+'" f="0" u="'+str(uid)+'" d0="0" n=" " a="0" h="" v="0" />\0')
        xat.send(j2)
        print "\nSend --> "+j2+"\n"
        while 1:
            text = xat.recv(4069)
            if 'logout' in text or 'idle' in text or 'dup' in text:
                raider(a3, p)
            else:
                time.sleep(1)
                xat.send('<m t=" " u="'+uid+'" />\0')
    except:
        raider(a3, p)
    

I made an attempt but it failed:

    
    
    def raid()
        $proxies = []
        $ids = []
        IO.foreach('ids.txt') do |line| # Foreach id as a line 
            $ids << line #ine.scan(/&Userid=(.*?)&k1=(.*?)&k2=([0-9]+)/i) # parse id
        end
        IO.foreach('socks.txt') do |line|
            $proxies << line
        end
        $test = $ids.zip($proxies)
    end
    

It reads the data from the two files, matches each ID with a Proxy, and sends
it to a function.


Answer: I'd write it like:

    
    
    def raid()
      ids = File.readlines('ids.txt')
      proxies = File.readlines('socks.txt')
      ids.zip(proxies).map{ |a| a.map(&:chomp) }
    end
    

Starting with two files:

  * socks.txt:
    
        127.0.0.1
    127.0.0.2
    

  * ids.txt:
    
        foo
    bar
    

Calling the above method returns:

    
    
    raid() # => [["foo", "127.0.0.1"], ["bar", "127.0.0.2"]]
    

> "...sends it to a function"

I'm not sure where in your code you tried to call a function, so I can't
replicate that.

