#!/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)