[tool] Add basic timer
This commit is contained in:
parent
954c79738b
commit
24057bf533
1 changed files with 28 additions and 0 deletions
28
timer.py
Executable file
28
timer.py
Executable file
|
@ -0,0 +1,28 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
import argparse
|
||||
import os
|
||||
import time
|
||||
|
||||
TIMER_FILE = '/home/kleph/stream/timer.txt'
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('-t', '--timer', help="start time in seconds", type=int, default=300)
|
||||
parser.add_argument('-f', '--file', help="where to write the time", type=str, default=TIMER_FILE)
|
||||
args = parser.parse_args()
|
||||
|
||||
|
||||
def write_countdown(filename, stimer):
|
||||
t = stimer
|
||||
with open(filename, 'w') as f:
|
||||
while t > 0:
|
||||
t -= 1
|
||||
min, sec = divmod(t, 60)
|
||||
print(f'{min:02d}:{sec:02d}')
|
||||
f.seek(0)
|
||||
f.write(f'{min:02d}:{sec:02d}')
|
||||
os.fsync(f)
|
||||
time.sleep(1)
|
||||
|
||||
|
||||
write_countdown(args.file, args.timer)
|
Loading…
Reference in a new issue