Skip to content

Instantly share code, notes, and snippets.

@lukec11
Created June 5, 2020 07:02
Show Gist options
  • Save lukec11/b23865b3de10acaeefd68661fe89c726 to your computer and use it in GitHub Desktop.
Save lukec11/b23865b3de10acaeefd68661fe89c726 to your computer and use it in GitHub Desktop.
obs-timer-linux
from datetime import datetime, timedelta
import time
import os
setHour = int(input('Hour: '))
setMin = int(input('Minute: '))
setTime = datetime(
year = datetime.today().year,
month = datetime.today().month,
day = datetime.now().day,
hour = setHour,
minute = setMin
)
while True: #constantly looping timer because life is stupid
currentTime = datetime.now()
diff = setTime - currentTime # time difference
timeArr = str(diff).split(':')
ftime = f'{timeArr[1]}:{timeArr[2].split(".")[0]}'
print(ftime)
with open ('timer.txt', 'w') as f: #opens timer file
f.seek(0) # goes to beginning of file
f.write(ftime) # Writes the current time into the file
f.truncate() # Cuts off the file
time.sleep(1) #sleeps 1s until next update so we don't need threading
if (ftime) == '00:00': #kill the program if the timer reaches 0
exit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment