Hack Forums
[Python] Script to be executed in specific time. - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [Python] Script to be executed in specific time. (/showthread.php?tid=4070323)



Script to be executed in specific time. - zer0 t1me - Feb 19, 2014

I've made up a research about how can I make a script to be executed in spcecific time but without any result.
So the main question is : is it possible? and if so how ?

P.S. The best I have made up to now is something like : time.sleep("seconds").


* - ImportUsername - Feb 19, 2014

Could you give an example of why you re trying to do? Your explanation isn't entirely clear. However judging by what you have, it should be possible.


* - zer0 t1me - Feb 19, 2014

Okay a quick example :

PHP Code

<?php 
import time

while time == 21:25:
....
....
....
.... 



* - K-On! - Feb 19, 2014

Use cron or Windows Task Scheduler. They should fit your needs.


* - ImportUsername - Feb 19, 2014

You could try with time.gmtime()
for example, look at this:
Code
import time
print (str(time.gmtime()[3])+":"+str(time.gmtime()[4])+":"+str(time.gmtime()[5]))
#output will be the time in the format HH:MM:SS, example is 20:41:24

You could use this to do what you're trying to do:
Code
import time
time = "20:45"

while (str(time.gmtime()[3])+":"+str(time.gmtime()[4])) == time:
    print ("running during this minute only")



* - zer0 t1me - Feb 19, 2014

Thanks guys problem solved ! 🤝


* - deiski - Feb 19, 2014

(Feb 19, 2014 01:44 PM)ImportUsername Wrote:  You could try with time.gmtime()
for example, look at this:
Code
import time
print (str(time.gmtime()[3])+":"+str(time.gmtime()[4])+":"+str(time.gmtime()[5]))
#output will be the time in the format HH:MM:SS, example is 20:41:24

You could use this to do what you're trying to do:
Code
import time
time = "20:45"

while (str(time.gmtime()[3])+":"+str(time.gmtime()[4])) == time:
    print ("running during this minute only")

Couldn't have said it better myself.