Sunday, August 31, 2008

Simple Timer in python to track my customer usage.

I have customized a timer written in python that will suffice my need for my Internet shop, I know allot of good ready apps out like CafeconLeche and Outkafe I'm still fixing my dev box so I have some thing to test on before I deploy it to my ltspsrver. Below is the source code:

#!/usr/bin/python2.5

#####################################
## Author: Christian Wyglendowski ##
## Customize by: AC ##
## Date: 08.31.08 ##
#####################################

import time
import threading
class Timer(threading.Thread):
def __init__(self, seconds):
self.runTime = seconds
threading.Thread.__init__(self)
def run(self):
time.sleep(self.runTime)
print "Buzzzz!! Time's up! workstation ",ws
t = time.strftime("%H:%M:%S")
print t

##Q:How many second in one hour?
##A:1 hour = 3600 seconds
##Q:How many second in thirty minutes?
##A:1 minute = 60 seconds
## 30 minutes = 60 x 30 = 1800 seconds

ws = raw_input("workstaion no.: ")
num = input("In seconds: ")
stTime = time.strftime("%H:%M:%S")
print stTime
t = Timer(num)
t.start()



How to use it just make the code executable (eg. chmod +x timer.py) then run it ./timer.py it will ask which workstation that needs to track the usage then how many second will the client use the computer so remember 30 min equals to 1800 second and 1 hour is equal to 3600 second then let the script do the counting for you. Below is a sample output:

$./timer.py
workstaion no.: 1
In seconds: 1800
15:30:31 ----> start Time
Buzzzz!! Time's up! workstation 1
16:00:31 -----> end time

next time i'll try to put a alam sound or it will blink a red light on the screen if time is up, for now this is ok for me.
note: this is only good for 4 - 10 workstation coz you'll be opening lots of terminal.

No comments: