Skip to content

Instantly share code, notes, and snippets.

@rochacbruno
Created July 30, 2020 22:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rochacbruno/104a9e84f44f392d72326e9cd4c02374 to your computer and use it in GitHub Desktop.
Save rochacbruno/104a9e84f44f392d72326e9cd4c02374 to your computer and use it in GitHub Desktop.
"""
Usage:
wait time: 600 (10 minutes)
title: 'Hello World'
duration: 7200 (2 hours)
$ python countdown.py 600 'Titulo da Live' 7200
"""
import os
import sys
import time
secs, msg, live = sys.argv[1:]
def countdown(t, l):
while t:
mins, secs = divmod(t, 60)
timeformat = "{:02d}:{:02d}".format(mins, secs)
print(timeformat, end="\r")
with open("countdown.txt", "w") as f:
f.write(timeformat)
time.sleep(1)
t -= 1
with open("countdown.txt", "w") as f:
f.write(msg)
time.sleep(300)
while l:
mins, secs = divmod(l, 60)
timeformat = "{} - {:02d}:{:02d} minutes".format(msg, mins, secs)
print(timeformat, end="\r")
with open("countdown.txt", "w") as f:
f.write(timeformat)
time.sleep(1)
l -= 1
with open("countdown.txt", "w") as f:
f.write("It is time to stop!!!")
while True:
os.system("mpg123 stop.mp3")
time.sleep(15)
print("Goodbye!\n\n\n\n\n")
countdown(int(secs), int(live))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment