forked from Py-Contributors/awesomeScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
clock.py
64 lines (54 loc) · 1.74 KB
/
clock.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import sys
import datetime as dt
def clock():
try:
print("\n\tThe Time is \n")
while(1):
print("\r\t{}".format(dt.datetime.today()), end="")
except KeyboardInterrupt:
pass
def stopwatch():
starttime = dt.datetime.now()
print("\n\tStart Time: " + str(starttime))
print("\n\tTime Taken\n")
try:
while(1):
print("\r\t{}".format(dt.datetime.now() - starttime), end="")
except KeyboardInterrupt:
pass
def timer(op, time):
stoptime = dt.timedelta()
if op == '-s':
stoptime = dt.timedelta(seconds=time)
elif op == '-m':
stoptime = dt.timedelta(minutes=time)
else:
raise IndexError
try:
starttime = dt.datetime.now()
print("\n\tTime Left\n")
while dt.datetime.now() - starttime != stopwatch:
elapsed_time = dt.datetime.now() - starttime
print("\r\t{}".format(stoptime - elapsed_time), end="")
except KeyboardInterrupt:
pass
def help():
print("\n Clock Module")
print("\n\t The following options are available")
print("\n\t\t --clock\tTo display the digital clock. Use Ctrl+C to exit")
print("\n\t\t --stopwatch\tTo start the stopwatch. Use Ctrl+C to exit")
print("\n\t\t --timer With additional arguments")
print("\n\t\t\t -s <number> To start timer for <number> seconds")
print("\n\t\t\t -m <number> To start timer for <number> minutes")
if __name__ == "__main__":
try:
if sys.argv[1] == '--clock':
clock()
elif sys.argv[1] == '--stopwatch':
stopwatch()
elif sys.argv[1] == '--timer':
timer(sys.argv[2], int(sys.argv[3]))
else:
help()
except IndexError:
help()