[Tutor] using Python with time

Andrew Wilkins toodles@yifan.net
Tue, 24 Apr 2001 11:24:16 +0800


Howdy Rob,

I don't know how helpful it is, but I'll mention it anyway. I'm coding this
python MUD system, and I wanted it to save every "XYZ minutes from the
moment the app is activated."

import time

#time() returns seconds since epoch, so you might want python to do some of
the work and convert
#it into separate fields with gmtime(). The index you want to use for
minutes is 4. Check
# http://www.python.org/doc/current/lib/module-time.html
#for documentation.

#This following bit can be pretty inaccurate if you are running other things
in the process...otherwise...

import time

last_time=time.gmtime(time.time())[4:6]
done=0

while not done:
	time_interval=1 #in minutes
	new_time=time.gmtime(time.time())[4:6]
	if (new_time[0]-last_time[0])>=time_interval and new_time[1]>=last_time[1]:
		print 'It was 1 minute since...'
		last_time=time.gmtime(time.time())[4:6]

#I tried the other one, where it tests for a specific time...eg. 10:32. I
got the hour, and it came as 3...
# and the time is 11:00, so i don't know how that one works...

I hope this helps...
Andrew Wilkins

> -----Original Message-----
> From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of
> rob@jam.rr.com
> Sent: Tuesday, 24 April 2001 10:09 AM
> To: tutor@python.org
> Subject: [Tutor] using Python with time
>
>
> I'd like to write a Python app that I can run "in the background" in
> both Windows and Linux/BSD/*nix, although it's hardly mission-critical
> that this be cross-platform. What I'd like it to do is notify me at
> certain times of day (say, at 10:32 a.m. and 3:40 p.m.) or after a given
> interval of time (say, every XYZ minutes from the moment the app is
> activated).
>
> My practical aim for it is to have a way to remind myself to practice
> mindfulness every so often during the day, but I'm also curious how to
> handle the timing part of the code. If anyone could recommend where I
> can look on the timing part, I'll credit helpful folk when I post the
> code to Useless Python!</bribe>
>
> Rob
> --
>
> Useless Python!
> If your Python is this useless, we need you.
> http://www.lowerstandard.com/python/pythonsource.html
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>