Jump to content
UBot Underground

Split List By Number Of Threads


Recommended Posts

I have a master list, lets say it has 1000 entries in it.

 

I want to allow user to run up to 10 threads

 

So - how would I go about splitting the master list into multiple small lists based on the number of threads selected by the user?

Link to post
Share on other sites

why do you need to split it? just let each thread to take next list item from the list (by using global index parameter).

if you still want to split where are several options:

1. perform 1000/10=10 to find number of entries per thread and create 10 lists with indexes (for each thread)

2. perform 1000/10=10 to find number of entries per thread and do math calculation to find starting position for each thread (thread one will start at position 0, thread 2 will start at position 10, thread 3 will start at position 20 and so on) - just make start positions parameters or list global

Edited by bestmacros
Link to post
Share on other sites

Thanks BestMacros - Going to work through what you've provided. - couldnt just let each thread take next list item becasue i kept getting the exceeded range of list error on nextlistitem

Link to post
Share on other sites

I attached the file here so that you can take a look.

 

basically, its fine on its own, but when i try to thread it, I break it.

 

fyi - i am pulling in a data file that is comma separated - reading the file into a list, and then using the list to fill the field area for form submission..

thread-error-example.ubot

Link to post
Share on other sites

Here is an example for you,

 

navigate("http://www.google.com", "Wait")
wait for element(<id="footer">, "", "Appear")
type text(<name="q">, "free bots", "Standard")
click(<name="btnG">, "Left Click", "No")
wait for element(<id="foot">, "", "Appear")
clear list(%urls)
add list to list(%urls, $list from text($scrape attribute(<outerhtml=w"<a href=\"*\" class=\"*\" onmousedown=\"return rwt(this*)\">*</a>">, "href"), $new line), "Delete", "Global")
if($comparison($list total(%urls), "<=", 10)) {
    then {
        set(#num threads, $list total(%urls), "Global")
    }
    else {
        set(#num threads, 10, "Global")
    }
}
set(#number accounts, $list total(%urls), "Global")
set(#num created, 0, "Global")
set(#used threads, 0, "Global")
loop(#number accounts) {
    loop while($comparison(#used threads, ">=", #num threads)) {
        wait(1)
    }
    loop process()
}
define loop process {
    increment(#used threads)
    increment(#num created)
    registration procedure()
}
define registration procedure {
    wait(1)
    thread {
        in new browser {
            registration code here()
            decrement(#used threads)
        }
    }
}
define registration code here {
    if($comparison(#num created, "<", #number accounts)) {
        then {
            goto url($next list item(%urls))
        }
        else {
        }
    }
}
define goto url(#url) {
    navigate(#url, "Wait")
    wait for browser event("Page Loaded", "")
    wait(10)
}
Link to post
Share on other sites

Well, that's some pretty slick scripting! ... Didn't work for what I am needing - but very powerful code and I will certainly start messing around with it again once I get the current issue solved! Thanks again magoo

Link to post
Share on other sites

You need to explain better what you need then, because all you had to do was add the functions from your own test bot above.

 

If you are trying to achieve what your  thread-error-example.ubot does, then this code has been modified to perform the tasks as per your bot. Each line of your text file is performed in a new thread with a max of ten threads open at once. Look at the logic and you will be able to add to it.

 

ui open file("some file with data in it - mine is comma separated", #mydatafile)
set(#readmydatafile, $read file(#mydatafile), "Global")
clear list(%mydatafileiread)
add list to list(%mydatafileiread, $list from text(#readmydatafile, ","), "Delete", "Global")
if($comparison($list total(%urls), "<=", 10)) {
    then {
        set(#num threads, $list total(%mydatafileiread), "Global")
    }
    else {
        set(#num threads, 10, "Global")
    }
}
set(#number accounts, $list total(%mydatafileiread), "Global")
set(#num created, 0, "Global")
set(#used threads, 0, "Global")
loop(#number accounts) {
    loop while($comparison(#used threads, ">=", #num threads)) {
        wait(1)
    }
    loop process()
}
define loop process {
    increment(#used threads)
    increment(#num created)
    registration procedure()
}
define registration procedure {
    wait(1)
    thread {
        in new browser {
            registration code here()
            decrement(#used threads)
        }
    }
}
define registration code here {
    if($comparison(#num created, "<", #number accounts)) {
        then {
            ubotplay($next list item(%mydatafileiread))
        }
        else {
        }
    }
}
define ubotplay(#some info from data file) {
    navigate("http://www.ubotstudio.com/playground/simple-form", "Wait")
    wait for element(<class="social_connect">, "", "Appear")
    type text(<username field>, #some info from data file, "Standard")
    click(<value="Submit">, "Left Click", "No")
    wait(2)
}
Link to post
Share on other sites

Magoo - dude... I finally understand. Thanks man, I don't know why I was making this process so hard when it can be achieved so easily. - Your example and input was just what I needed. - Thanks again.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...