diff --git a/timer.py b/timer.py index 1204552..af7501f 100755 --- a/timer.py +++ b/timer.py @@ -1,5 +1,9 @@ #!/usr/bin/python +""" +OBS countdown timer for OBS +""" + import argparse import os import time @@ -13,16 +17,17 @@ 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) + """ 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) \ No newline at end of file +write_countdown(args.file, args.timer)