471,338 Members | 1,012 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,338 software developers and data experts.

How to - scheduler.py

Hi,

I'm using windows XP and I`m wondering what is the best way to scheduled a start and stop time entered manually, let said btwn : Sep 06 10:00 2007 to Sep 06 11:00 2007. (I'm using windows XP). (Want just pure python script no task sheduler). Should I use ?:

./scheduler.py "sep 6 12:00 2007" "sep 6 13:00 2007" if so, how can I call a class ?

Tks
Sep 6 '07 #1
5 2683
bartonc
6,596 Expert 4TB
Hi,

I'm using windows XP and I`m wondering what is the best way to scheduled a start and stop time entered manually, let said btwn : Sep 06 10:00 2007 to Sep 06 11:00 2007. (I'm using windows XP). (Want just pure python script no task sheduler). Should I use ?:

./scheduler.py "sep 6 12:00 2007" "sep 6 13:00 2007" if so, how can I call a class ?

Tks
I haven't played with this much, but here are some of the things that you will need:
Expand|Select|Wrap|Line Numbers
  1. >>> import time
  2. >>> import sched
  3. >>> def timedAction(arg1):
  4. ...     print arg1
  5. ...     
  6. >>> s = sched.scheduler(time.time, time.sleep)
  7. >>> startTime = time.mktime(time.strptime("sep 6 18:25 2007", '%b %d %H:%M %Y'))
  8. >>> timer1 = s.enterabs(startTime, 0, timedAction, ("Hello world @ %f" %time.time(),))
  9. >>> startTime = time.mktime(time.strptime("sep 6 18:25 2007", '%b %d %H:%M %Y'))
  10. >>> timer1 = s.enterabs(startTime, 0, timedAction, ("Hello world @ %f" %time.time(),))
  11. >>> s.run()
  12. Hello world @ 1189122855.187000
Sep 7 '07 #2
Hello Bartonc,

What will be the right syntaxe if I want to add startDateTime = input_raw('Pls enter date and time : ') instead of a static date/time?
Sep 7 '07 #3
bartonc
6,596 Expert 4TB
Hello Bartonc,

What will be the right syntaxe if I want to add startDateTime = input_raw('Pls enter date and time : ') instead of a static date/time?
Expand|Select|Wrap|Line Numbers
  1. while True:
  2.     startDateTime = input_raw('Pls enter date and time Mo Day HH:MM YYYY: ')
  3.     try:
  4.         timeTuple = time.strptime(startDateTime, '%b %d %H:%M %Y')
  5.         break
  6.     except ValueError:
  7.         print "That is not a valid date. Please use Mo Day HH:MM YYYY."
  8. startTime = time.mktime(timeTuple)
(Which, by the way, is a very odd date and time format.) Although you are asking a lot of the user to get the date typed in correctly and could do better checking.
Sep 7 '07 #4
Hi Bartonc,

looks nice but I need to put another raw_input to stop the scheduler,
how should look the syntax now ???
Sep 7 '07 #5
bartonc
6,596 Expert 4TB
Hi Bartonc,

looks nice but I need to put another raw_input to stop the scheduler,
how should look the syntax now ???
Then it's time to make it a funtion:
Expand|Select|Wrap|Line Numbers
  1. myOddDateFormat = "Mo Day HH:MM YYYY"
  2.  
  3. def GetDate(prompt):
  4.     while True:
  5.         startDateTime = input_raw("%s :%s: " %(prompt, myOddDateFormat))
  6.         try:
  7.             timeTuple = time.strptime(startDateTime, '%b %d %H:%M %Y')
  8.             break
  9.         except ValueError:
  10.             print "That is not a valid date. Please use %s." %myOddDateFormat
  11.     return time.mktime(timeTuple)
  12.  
  13. startTime = GetDate('Pls enter starting date and time')
  14. stopTime = GetDate('Pls enter stopping date and time')
Sep 7 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by keepyourstupidspam | last post: by
1 post views Thread by Neil Ginsberg | last post: by
8 posts views Thread by VMI | last post: by
2 posts views Thread by yamca | last post: by
4 posts views Thread by Sid Price | last post: by
1 post views Thread by =?Utf-8?B?YXVzdGlyb2I=?= | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.