Jump to content

Recommended Posts

Posted

I am working at a script (thanks @Chimp for the help on my previous thread) operating on Firefox, based on two time-set loops that are doing the same operations with some differences.
Now I need to execute a local video at a determinated hour (between 12 and 4).  
My question is

What is the best way to determine a precise hour (hh:mm)? I tried

While @Hour >= 12 & @MIN >= 00 And @HOUR <= 14 & @MIN < 30

But the loop is being ignored, although in the moment I use only @Min for my tests everything works fine.

This is the essential - and working - structure of the present script:

#include <ff.au3>
_FFStart()
While @MIN >= 00 And @MIN < 30  ; 1st Firefox loop

    Firefox url loop (contains functions and if conditions)

WEnd

;Open a new tab and runs a local video;

While @MIN >= 32 And @MIN <= 59 ; 2nd Firefox loop

    Firefox url loop (contains functions and if conditions)

WEnd

Thanks in advance

Posted (edited)

The reason the statement is not working is because your using "&" instead of "And" they have totally different functions :)

As for the code block your first loop will run from 0 to 30 min and then exit the loop,

The second loop starts at 32 to 59 minutes, with just the code posted if those loops are not inside of another larger loop I do not see how the second loop even starts because the first would exit at 30 minutes and then the code would continue bypassing the second loop entirely. 

A good way to fix that would be just one loop with If statements, also the code could run continually this way and never need to be restarted.

While 1
Sleep(10) 
If @Min >= 00 AND @Min < 30 Then
 ;Function
ElseIf @Min >= 32 AND @Min <=59
 ;Function
EndIf
WEnd

Also you can try assigning the macros to a variable so you do not have to keep reusing the macro and could even do a crude hour:min feature like this.

While 1
    Sleep(10)
    $iTime = Number(@Hour & @Min)
    If $iTime >= 1650 AND $iTime <= 1700 Then
       MsgBox(0, "", "It's between 4:50 and 5:00 !")
    EndIf
WEnd

 

Edited by ViciousXUSMC
Posted

The reason the statement is not working is because your using "&" instead of "And" they have totally different functions :)

As for the code block your first loop will run from 0 to 30 min and then exit the loop,

The second loop starts at 32 to 59 minutes, with just the code posted if those loops are not inside of another larger loop I do not see how the second loop even starts because the first would exit at 30 minutes and then the code would continue bypassing the second loop entirely. 

A good way to fix that would be just one loop with If statements, also the code could run continually this way and never need to be restarted.

While 1
Sleep(10) 
If @Min >= 00 AND @Min < 30 Then
 ;Function
ElseIf @Min >= 32 AND @Min <=59
 ;Function
EndIf
WEnd

Also you can try assigning the macros to a variable so you do not have to keep reusing the macro and could even do a crude hour:min feature like this.

While 1
    Sleep(10)
    $iTime = Number(@Hour & @Min)
    If $iTime >= 1650 AND $iTime <= 1700 Then
       MsgBox(0, "", "It's between 4:50 and 5:00 !")
    EndIf
WEnd

Hello world!

Sorry, I had not the occasion to post due to some issues, but I worked on your idea @ViciousXUSMC

I think that the easiest way to write more loops is to write more scripts, each one activating at a certain $iTime, right?

The problem is, if I use an infine loop (While 1) I can't even close FF at the end of the loop.

So I need to stop the loop, how?

Should I write a secondary script that stops the primary script?

Posted

The reason the statement is not working is because your using "&" instead of "And" they have totally different functions :)

As for the code block your first loop will run from 0 to 30 min and then exit the loop,

The second loop starts at 32 to 59 minutes, with just the code posted if those loops are not inside of another larger loop I do not see how the second loop even starts because the first would exit at 30 minutes and then the code would continue bypassing the second loop entirely. 

A good way to fix that would be just one loop with If statements, also the code could run continually this way and never need to be restarted.

While 1
Sleep(10) 
If @Min >= 00 AND @Min < 30 Then
 ;Function
ElseIf @Min >= 32 AND @Min <=59
 ;Function
EndIf
WEnd

Also you can try assigning the macros to a variable so you do not have to keep reusing the macro and could even do a crude hour:min feature like this.

While 1
    Sleep(10)
    $iTime = Number(@Hour & @Min)
    If $iTime >= 1650 AND $iTime <= 1700 Then
       MsgBox(0, "", "It's between 4:50 and 5:00 !")
    EndIf
WEnd

Hello world!

Sorry, I had not the occasion to post due to some issues, but I worked on your idea @ViciousXUSMC

I think that the easiest way to write more loops is to write more scripts, each one activating at a certain $iTime, right?

The problem is, if I use an infine loop (While 1) I can't even close FF at the end of the loop.

So I need to stop the loop, how?

Should I write a secondary script that stops the primary script?

Posted

Would be hard to help without knowing how your function works.

Sounds to me instead of needing to run between (start time) and ending at (stop time) you just need a (start time) only.

So just modify like so:

While 1
    Sleep(10)
    $iTime = Number(@Hour & @Min)
    If $iTime = 1650 Then MsgBox(0, "", "Function Started @ 4:50PM")
    If $iTimer = 1850 Then MsgBox(0, "", "Function Started @ 6:50PM")
WEnd

 

If your going to have a bunch of different start times that is a good chance to use Switch/EndSwitch instead of If/EndIf statements.

Posted

Would be hard to help without knowing how your function works.

Sounds to me instead of needing to run between (start time) and ending at (stop time) you just need a (start time) only.

So just modify like so:

While 1
    Sleep(10)
    $iTime = Number(@Hour & @Min)
    If $iTime = 1650 Then MsgBox(0, "", "Function Started @ 4:50PM")
    If $iTimer = 1850 Then MsgBox(0, "", "Function Started @ 6:50PM")
WEnd

 

If your going to have a bunch of different start times that is a good chance to use Switch/EndSwitch instead of If/EndIf statements.

I am sorry, I should have explained myself better from the beginning. I'll try to do it now.
Here the operations I need

1)To run firefox at a certain hour (HH:MM),
2)To open a random url taken from a list, let it open then close it
3)To keep doing it until a determined hour (HH:MM)
4)To change the list where the urls are taken from
5)Repeat 2) until is time for the script to stop itself (HH:MM).
6)To execute a local video at given times (HH:MM, HH:MM, etc)

Notes (number related)
1)Thanks to the FF libraries I can easily operate in Firefox, so no problem there.
2)To open the urls randomly I wrote this code (example of the code structure)

Global $aURLS[6]
$aURLS[1] = "www.youtube.com" 
$aURLS[2] = "www.yahoo.com"
$aURLS[3] = "www.vimeo.com"
$aURLS[4] = "www.dailymotion.com"
$aURLS[5] = "www.twitch.tv"

$x = Random(1, 5, 1)

_FFTabAdd($aURLS[$x], True, True)
WinWaitActive("Tab",0,10)

Sleep(5 * 1000) 

_FFTabClose("0", "index")
Sleep(5000)

    Select
    Case $x <= 2
    MouseClick(x,y)
    Sleep(15 * 1000) 
    MouseClick(x,y)

    Case $x >= 3
    MouseWheel("down", 1)                   
    Sleep(2000)
    MouseClick(x,y) 
    Sleep(15 * 1000)
    MouseClick(x,y)

EndSelect


So, that is the essential code I need to loop. The case select is necessary to maximize the video window in different websites.
3)I don't care if the script is only one or I have to divide it. I just need it to work correctly.
4)There are two (al least) lists of urls. This is a vital part of the script
6)This is vital too, so I am taking into consideration to write 3 scripts instead of only one. It looks easier, do you agree?

 

Posted

I'll look at this more later, but I can tell you that running separate loops like you posted in your example should behave no different than the While loop I posted so the issue that is happening must have something to do with your code.

If you really want to do this in a professional manner you should look at the IUIAutomation thread where you can click/full screen without using MouseClick() so that it will always work no matter the resolution, and I think FireFox UDF has methods to detect when a page has loaded so you can get rid of the excessive Sleep() you have for page loading.

Posted (edited)

I found out my mistake: ""

Daaaaamn quotes!

$iTime = Number(@Hour & @Min)
For $iTime = "1640" To "1642"

This "timer" appears to be workimg well! EDIT: well, seems it does not work if I don't include a piece of code I found surfing the net.

I checked the IUIAutomation thread. It looks very useful and I thank you for pointing it out to me, but I have the impression it requires to be more skilled than the level I am presently.

You are right, it exists the _FFLoadWait function, better than Sleep, thanks for the hint

I'll continue my work on the script, thank you for you help!

Edited by skyhigh

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...