blob: 28a54b30bf0f11bfbf163d419576ea9eb5751780 (
plain)
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
|
#! python3
#! /usr/bin/env python3
# Chapter 15 Practice Prettified Stopwatch
# Simple Stop Watch Program
# NOTE: Writing output to data text file rather than use pyperclip module.
# Then file can be attached to email or copied as needed. And a
# separate module outside the standard library is not required.
import time
import datetime
dataFile = open('stopWatchData.txt', 'a')
dt = datetime.datetime.now()
timeStamp = dt.strftime('\n%m/%d/%Y %H:%M\n')
dataFile.write(timeStamp)
print('Press ENTER to begin. Afterwards, press ENTER to click the stopwatch.')
print('Press CTRL-C to quit.')
input()
print('Started...')
startTime = time.time()
lastTime = startTime
lapNum = 1
try:
while True:
input()
lapTime = round(time.time() - lastTime, 2)
totalTime = round(time.time() - startTime, 2)
print('Lap #%s: %s (%s)' % (str(lapNum).ljust(2), str(totalTime).rjust(4), str(lapTime).rjust(5)), end='')
dataFile.write('Lap #%s: %s (%s)\n' % (str(lapNum).ljust(2), str(totalTime).rjust(4), str(lapTime).rjust(5)))
lapNum += 1
lastTime = time.time()
except KeyboardInterrupt:
print('\nDone.')
dataFile.close()
|