| View previous topic :: View next topic |
| Author |
Message |
adi2247 Voice
Joined: 30 Nov 2010 Posts: 10
|
Posted: Tue Dec 21, 2010 5:41 am Post subject: Run a proc between specific times/days |
|
|
currently i have a proc similar to this:
| Code: | proc timer {min args} {
if {[scan $min %d] % 5 == 0} {
#Code goes here
}
} |
which runs a proc every 5 min, but i would also like to have it check to see if the system time is between 9am-5pm mon-fri before running.
i think it may be somthing similar to
| Code: |
proc timer {min args} {
set systemTime [clock seconds]
if { [clock format $systemTime -format %H] >= 9 && [clock format $systemTime -format %H] <= 17 &&
[scan $min %d] % 5 == 0} {
#code goes here
}
} |
which i would think would work but doesnt seem to be, inaddition im not sure how to equate day of the week to a numeric value to check against either. Anyhelp is greatly apreciated.
using this for reference http://www.tcl.tk/man/tcl/tutorial/Tcl41.html |
|
| Back to top |
|
 |
willyw Revered One
Joined: 15 Jan 2009 Posts: 1175
|
Posted: Tue Dec 21, 2010 1:08 pm Post subject: Re: Run a proc between specific times/days |
|
|
| adi2247 wrote: |
...
im not sure how to equate day of the week to a numeric value to check against either.
|
How about strftime ?
Try strftime %u
Ref:
http://www.eggheads.org/support/egghtml/1.6.20/tcl-commands.html
and find strftime
Also:
http://linux.about.com/library/cmd/blcmdl3_strftime.htm
Is the .tcl command enabled on your bot? If so, you can do some quick experiments with the strftime command.
Example:
| Code: |
<mynick> .tcl strftime %u
<botnick> Tcl: 2
|
(Today is Tuesday, and with strftime Monday =1) |
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Tue Dec 21, 2010 3:45 pm Post subject: |
|
|
If you've got the 1.6.20 version of eggdrop, then you could use the new "CRON" binding rather than the "TIME" binding. In that case, the code would look like this:
| Code: | bind cron - {*/5 * * * 1-5} timer
proc timer {minute hour day month weekday} {
#code goes here
} |
If you'd rather use the "TIME" binding, and parse the various arguments passed to the proc as integers, you'll have to remember that single-digit numbers are zero-prefixed, causing 08 and 09 to be treated as invalid octal numbers. This is fairly easy to solve though, using something like this:
| Code: | bind time - * someproc {min hour day month year} {
set min [string trimleft $min 0]
set hour [string trimleft $hour 0]
if {$min % 5 == 0 && $hour >= 9 && $hour <= 17} {
... |
This won't solve the issue of weekdays though, so you'll have to resort to strftime for this, as suggested by willyw _________________ NML_375, idling at #eggdrop@IrcNET |
|
| Back to top |
|
 |
username Op

Joined: 06 Oct 2005 Posts: 196 Location: Russian Federation, Podolsk
|
Posted: Wed Dec 22, 2010 4:28 am Post subject: |
|
|
nml375, but in http://www.eggheads.org/support/egghtml/1.6.20/tcl-commands.html#binda there is other arguments.
bind cron <flags> <mask> <proc>
proc-name <minute> <hour> <day> <weekday> <year>
And in bind description I read: | Quote: | | ...It can contain up to five fields: minute, hour, day, month, weekday; delimited by whitespace.... |
So, this is mistake in this line proc-name <minute> <hour> <day> <weekday> <year>? _________________ Архив TCL скриптов для ботов Eggdrop/Windrop:
http://egghelp.ru/ |
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Wed Dec 22, 2010 2:25 pm Post subject: |
|
|
username:
If you instead open the tcl-commands.doc that's included with the source, you'll read <weekday> instead of <year>, so it's my best guess they've made a typo with the html-docs. _________________ NML_375, idling at #eggdrop@IrcNET |
|
| Back to top |
|
 |
pseudo Halfop
Joined: 23 Nov 2009 Posts: 88 Location: Bulgaria
|
|
| Back to top |
|
 |
adi2247 Voice
Joined: 30 Nov 2010 Posts: 10
|
Posted: Thu Dec 23, 2010 3:15 pm Post subject: |
|
|
| ty all for the sugestions! i will try some of these and report back! |
|
| Back to top |
|
 |
adi2247 Voice
Joined: 30 Nov 2010 Posts: 10
|
Posted: Mon Dec 27, 2010 1:08 am Post subject: Re: Run a proc between specific times/days |
|
|
strftime seems to be working great for the most part. Sometimes i have to restart the bot completely vs a .rehash but that may or may not be related to the code below, and more related to numerous mysql connections, not sure yet. But if anyone sees anything glaringly wrong w the below please let me know
the two instances im using for this are:
| Code: | if { [strftime %u] >= 1 && [strftime %u] <= 6 && [strftime %H%M] >= 930 && [strftime %H%M] <= 1700 &&
[scan $min %d] % 5 == 0} { |
and
| Code: | if { [strftime %u] == 7 && [strftime %H] >= 18 && [scan $min %d] % 15 == 0 ||
[strftime %u] >= 1 && [strftime %u] <= 5 && [scan $min %d] % 15 == 0} { |
also what nml375 posted that strftime %H before noon will report back "01" or "02" for example vs just "1" or "2". However if you try to evaluate:
if { [strftime %H] >= 08 }
the bot will error and say this looks like an octal number just as nml375 mentioned.
** and i just realized that the first block of code i posted was NOT running before 10am today so the times will HAVE to be evaluated in the manner that nml375 posted as tcl/eggdrop aparently does not view 01 to == 1
thats a good finding
but the cron method if probably the the best way to run this proc m-f and ill look at the times seperately as mentioned in his post for simplicity
the second block of code i posted works fine since it only evaluates the hour if its greater than 2 digits anyway. cron may not work for this because it needs to look at different times if its a sunday |
|
| Back to top |
|
 |
|