Setting random WAIT

Discussions and Tech Support specific to the iMacros Firefox add-on.
Forum rules
Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the search box (at the top of each forum page) to see if a similar problem or question has already been addressed.
3. Try searching the iMacros Wiki - it contains the complete iMacros reference as well as plenty of samples and tutorials.
4. We can respond much faster to your posts if you include the following information: CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST
joe_brown
Posts: 33
Joined: Mon Aug 06, 2007 8:49 pm

Post by joe_brown » Tue Mar 04, 2008 11:05 am

OK, actually thought, you would be able to modify my code to fit your needs (doesn't seem like you'd really be into coding though..)

Thus here is something more straightforward for you.
Kindly setup the following:


1.- create file "D:\Book1.csv" as:

Code: Select all

a;1
b;3
c;5
d;7
e;9
f;2
g;4
h;6
i;8
j;10
k;1
l;3
m;5
n;7
o;9
p;2
q;4
r;6
s;8
t;10
u;1
v;3
w;5
x;7
y;9
z;2
- this will be the sample CSV data-file


2.- create in your iMacros directory a file named "readcsv.js":

Code: Select all

var inputfile='D:/Book1.csv', // the full path to the input csv file (note: use forward-slashes or double the backslashes)
    separator=';', // the separator used in the input CSV file (M$ xls default: ';')
    fr,i,s,myarray; // local vars - to avoid conflicts with iMacros JS code

try{
  fr=new java.io.BufferedReader(new java.io.FileReader(inputfile));
  for(i=1;i<=3;i++){
    s=fr.readLine();
    if(s==null){s=''}else{s=''+s};
    myarray=s.split(separator);
    iimDisplay('COL1='+myarray[0]+"\nCOL2="+myarray[1]);
    iimPlay('CODE:WAIT SECONDS='+myarray[1]);
  }
  fr.close();
  fr=null;
}catch(e){
  alert(''+e);
};

iimDisplay('Done.');
Next click "Refresh Macro List" in your Firefox to see the readcsv.js file in your iMacros list.

And finally play the readcsv.js iMacro

----------------------

The iMacro is generic, therefore you can play around with it.

The "data" for the wait-command is in the second column to show you, that it doesn't have to be the first column of the csv-file, but basically any column (you just choose the right "COL#-1" element from the myarray array).

To avoid having to wait too long until the iMacro finishes, I've limited the example to the first 3 lines, but of course any number of lines can be read..
If any lines need to be skipped, just add an another for-cycle just after the first line in the try-block and call fr.readLine() within it as many times as many lines you want to skip from the csv-file.

Have fun.

Cheers,
Joe
figman
Posts: 12
Joined: Thu Feb 21, 2008 11:44 am

Post by figman » Tue Mar 04, 2008 1:11 pm

Thanks Joe, this looks good. I just need to know how and where to call the .iim code within the javascript. For example I would need to call "Demo-Loop-Csv-2-Web.iim"
figman
Posts: 12
Joined: Thu Feb 21, 2008 11:44 am

Post by figman » Fri Mar 07, 2008 1:39 am

OR alternatively....
Just using the javascript that you mention above, how and where can I
add the code to visit ebay.com and fill in the search form?
joe_brown
Posts: 33
Joined: Mon Aug 06, 2007 8:49 pm

Post by joe_brown » Fri Mar 07, 2008 2:09 am

Not sure, what exactly you are trying to achieve.

If you have an IIM-macro recorded/written to perform an activity and you want to have a "random" delay (read from the csv-file as you mention) between the different runs of this macro, then you'd add the line

Code: Select all

iimPlay('yourmacro.iim');
just after the line

Code: Select all

iimPlay('CODE:WAIT SECONDS='+myarray[1]);
in my previously posted code.

If you had something different in mind, then please sketch it a bit more in detail.

Cheers,
Joe
figman
Posts: 12
Joined: Thu Feb 21, 2008 11:44 am

Post by figman » Fri Mar 07, 2008 4:11 pm

Thanks Joe, that works great :)
I have a new problem now. :?
The iim call: iimPlay('yourmacro.iim'); is used to post one line of text at a time from the csv file with each loop and it does so perfectly when run on its own but calling it from readcsv.js posts the first line every single loop (in other words always posting line 1 of the csv). How can I fix this?
joe_brown
Posts: 33
Joined: Mon Aug 06, 2007 8:49 pm

Post by joe_brown » Fri Mar 07, 2008 8:18 pm

That is not really a problem - you just need to consider driving the datasource line out from this JS-code rather then by the build-in LOOP variable.

Meaning ..

I suppose, somewhere in your IIM code you have a line alike:

Code: Select all

SET !DATASOURCE_LINE {{!LOOP}}
Now replace the variable in that line for one of VAR1~VAR3 (depends on if you are using any of these in your IIM already) .. alike:

Code: Select all

SET !DATASOURCE_LINE {{!VAR1}}
Then go back to the JS-code and set the value of the chosen variable to be dependent on the for-cycle control-variable just before calling your IIM .. will then look alike:

Code: Select all

iimSet('-var_VAR1',''+i);  // Note: the 2nd arg must be a string, not a number
iimPlay('yourmacro.iim');
[Refresh Macro List] and play the driving JS-iMacro.

Cheers,
Joe
Hello 71
Posts: 96
Joined: Mon Feb 18, 2008 12:06 am
Location: Toronto, ON, Canada

Re: Setting random WAIT

Post by Hello 71 » Sat Mar 29, 2008 2:14 am

Which question?
figman
Posts: 12
Joined: Thu Feb 21, 2008 11:44 am

Re: Setting random WAIT

Post by figman » Sat Mar 29, 2008 11:02 am

Sorry Joe for the long wait, I have been away for a couple of weeks.
Ok I want to use (if possible) the code you originally suggested on page 1 (see wait.js below) along with the advice you gave me in your last post:

Code: Select all

iimSet('-var_VAR1',''+i);  // Note: the 2nd arg must be a string, not a number
iimPlay('yourmacro.iim');
Here is what I have got, please show me how to put it together.

wait.js

Code: Select all

for(var t,i=1;i<10;i++){
t=Math.round(10*Math.random());
iimDisplay('Wait #'+i+': '+t+' secs');
iimPlay('CODE:WAIT SECONDS='+t);
};
search.iim

Code: Select all

VERSION BUILD=3700331       
'Uses a Windows script to submit several datasets to a website, e. g. for filling an online database
TAB T=1     
TAB CLOSEALLOTHERS  
URL GOTO=http://www.ebay.com/
' Specify input file (if !COL variables are used, IIM automatically assume a CSV format of the input file
'CSV = Comma Separated Values in each line of the file
CMDLINE !DATASOURCE ebay.csv
'Number of columns in the CSV file. This must be accurate!
SET !DATASOURCE_COLUMNS 8
'Start at line 2 to skip the header in the file
SET !LOOP 2
'Increase the current position in the file with each loop 
SET !DATASOURCE_LINE {{!LOOP}}
' Fill web form 
TAG POS=1 TYPE=INPUT:SUBMIT FORM=NAME:headerSearch ATTR=VALUE:Search
SorenC
Posts: 36
Joined: Wed Oct 28, 2009 4:33 pm

Re: Setting random WAIT

Post by SorenC » Sun Nov 08, 2009 1:06 pm

Hey everyone. :)

I've been going through this and similar threads regarding random wait time. But so far i havent been able to figure out how the heck to implant it.

Im using a macro similar to http://wiki.imacros.net/Demo-Loop-Csv-2-Web. But with some alterations.

My Macro:

Code: Select all

VERSION BUILD=6240709 RECORDER=FX
TAB T=1
CMDLINE !DATASOURCE users.csv
SET !DATASOURCE_COLUMNS 2
SET !LOOP 2
SET !DATASOURCE_LINE {{!LOOP}}
SET !ERRORIGNORE YES
URL GOTO=http://www.facebook.com/
TAG POS=1 TYPE=INPUT:TEXT FORM=ACTION:https://login.facebook.com/login.php?login_attempt=1 ATTR=ID:email CONTENT={{!COL1}}
SET !ENCRYPTION NO
TAG POS=1 TYPE=INPUT:PASSWORD FORM=ACTION:https://login.facebook.com/login.php?login_attempt=1 ATTR=ID:pass CONTENT={{!COL2}}
TAG POS=1 TYPE=INPUT:SUBMIT FORM=ID:login_form ATTR=VALUE:Login
URL GOTO=http://genau.dk/aaretstatovering/index.php?mode=stort&unik_idnr=118
URL GOTO=http://genau.dk/aaretstatovering/voteny.php?unik_idnr=118
FRAME F=0
TAG POS=1 TYPE=A ATTR=TXT:Logout
WAIT SECONDS=240
But at:

Code: Select all

WAIT SECONDS=240
I would like it to take a random amount of time, between 60secs and 400secs.

How do i accomplish this?.

ps: Im using the FF plugin for this.
kors4r
Posts: 3
Joined: Sat Aug 21, 2010 11:00 pm

Re:

Post by kors4r » Thu Sep 23, 2010 12:03 am

joe_brown wrote:Well, I know, this is not, what you want to hear, but javascript (ergo java) can actually read from files - eg here is one of the functions I am using in one of my iMacros:

Code: Select all

function frdln(n){
  var fr,s='';
  try{
    fr=new java.io.BufferedReader(new java.io.FileReader(n));
    s=fr.readLine();
    if(s==null){s=''}else{s=''+s};
    fr.close();
    fr=null;
  }catch(e){
    alert(''+e);
  };
  return s;
};
It accepts the filename to read from as the only parameter and returns the first line from that file (in this specific case I have the whole data in that file in one line as entries delimited by commas, therefore I did not feel the need to write anything more sophisticated..).

Cheers,
Joe
hi

i was searching for this code almost two days :)

thanks!

but!
how can I delete first line of readed file (n), after reading?

i mean - my file have 100 lines
this code read first line
thats ok for me, but
only by first run
in second run of function frdln I want to read next line from file (first line is not necessary anymore, so I want to delete first line by first run fo function)

sorry for my english, can you help me??

best regards
bugmenot666
Posts: 39
Joined: Wed Apr 08, 2009 2:01 pm

Re: Setting random WAIT

Post by bugmenot666 » Thu Aug 23, 2012 11:30 am

Wait for a random time (1 to 10 seconds) after a page is loaded:

Code: Select all

SET !VAR1 EVAL("var randomNumber=Math.floor(Math.random()*10 + 1); randomNumber;")
URL GOTO=http://www.iopus.com
' waits 1 to 10 seconds
WAIT SECONDS={{!VAR1}}
source: http://wiki.imacros.net/EVAL#Random_wait
infoleather
Posts: 2
Joined: Mon Sep 10, 2012 3:04 am
Location: New York
Contact:

Re: Setting random WAIT

Post by infoleather » Mon Sep 10, 2012 3:53 am

I can not use JavaScript, because of the the WAIT command I do need to read a CSV file, do some value...
The size of Women Purple Leather Shoulder bags also depends upon the needs of women. If you are working women who has to go her office daily then you may need cwmalls.com Women Leather Flap Messenger Bags that can contain files and gadgets.
Post Reply