stream_tools/timer.py

34 lines
875 B
Python
Raw Normal View History

2021-03-31 04:33:22 +02:00
#!/usr/bin/python
2021-03-31 04:47:25 +02:00
"""
OBS countdown timer for OBS
"""
2021-03-31 04:33:22 +02:00
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):
2021-03-31 04:47:25 +02:00
""" 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)
2021-03-31 04:33:22 +02:00
time.sleep(1)
2021-03-31 04:47:25 +02:00
write_countdown(args.file, args.timer)