Skip to content

Instantly share code, notes, and snippets.

@maxtacu

maxtacu/countertimer.py

Last active May 9, 2020
Embed
What would you like to do?
Python countdown timer https://youtu.be/9QSo3F6sM1w
import time
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('-t', '--time', type=int, required=True, help="Time in seconds")
parser.add_argument('-o', '--output',default="counter.txt", help="Output file")
args = parser.parse_args()
def countdown(t):
while t:
timefile = open(args.output, "w")
mins, secs = divmod(t, 60)
if mins > 59:
hours, mins = divmod(mins, 60)
else:
hours = 0
timeformat = f"{hours:02d}:{mins:02d}:{secs:02d}"
timefile.write(timeformat)
timefile.close()
time.sleep(1)
t -= 1
countdown(args.time)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.