0

I want to set up some code that depending on the time of day (internal computer time i guess). It switches to do something else.

Heres in english:

y = 1 <br>
if 6:30am then<br>
  x = 1 + y<br>
if 7:00am then<br>
  x = 2 + y<br>
if any_other_time then<br>
  x = 0<br>

Here is what i have so far in my script.

import time<br>
clock = time.time()
y = 0
if clock < 6:30am
x = 2 + y

but i know this isn't right because time.time displays something different then 6:30am

0

IMHO i would use the datetime library

http://docs.python.org/library/datetime.html

eg.

>>> datetime.utcnow()   
datetime.datetime(2007, 12, 6, 15, 29, 43, 79060)

check this post too

https://stackoverflow.com/questions/1599060/how-can-i-get-an-accurate-utc-time-with-python

  • how is this looking: pastebin.com/uD7xr0bh – John Riselvato Nov 17 '10 at 18:57
  • Ohh run ntpclients on your servers too... :D – Arenstar Nov 17 '10 at 18:59
  • haha yeah i do. Trying to set up a bandwidth controller. So that at certain times, it shapes differenly. – John Riselvato Nov 17 '10 at 19:00
  • Are you focusing on a single server, or wanting to run it for the network? BTW, looks very interesting :D – Arenstar Nov 17 '10 at 19:02
  • More of a learning experience. I don't need it, but i am trying to teach my self Lartc. So i figured make up tasks a 'boss' would ask. So atleast when i do have a task like this i can already do it, or atleast have reference. – John Riselvato Nov 22 '10 at 18:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.