33 lines
875 B
Python
Executable file
33 lines
875 B
Python
Executable file
#!/usr/bin/python
|
|
|
|
"""
|
|
OBS countdown timer for OBS
|
|
"""
|
|
|
|
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):
|
|
""" decrease counter anf write synchronously to dest file """
|
|
tsec = stimer
|
|
with open(filename, 'w') as destfile:
|
|
while tsec > 0:
|
|
tsec -= 1
|
|
minutes, sec = divmod(tsec, 60)
|
|
print(f'{minutes:02d}:{sec:02d}')
|
|
destfile.seek(0)
|
|
destfile.write(f'{minutes:02d}:{sec:02d}')
|
|
os.fsync(destfile)
|
|
time.sleep(1)
|
|
|
|
|
|
write_countdown(args.file, args.timer)
|