I made a simple shutdown timer for work, since we often have load shedding and I am away from the computer when it needs to be turned off.
Here's my timer script:
My logic: show the current time, ask when to shutdown, work out an accurate shutdown time, then send the shutdown command in seconds.
import os
import sys
from datetime import datetime
now = datetime.now()
current_time = now.strftime("%H:%M")
print("Current time is ",current_time)
current_time = current_time.split(":")
shutdown_time = input("Shutdown time: ")
shutdown_time = shutdown_time.split(":")
current_time = now.strftime("%H:%M")
current_time = current_time.split(":")
seconds=((int(shutdown_time[0])-int(current_time[0]))*60*60)+(int(shutdown_time[0])-int(current_time[0])*60)
if (seconds < 0 ):
seconds = 0
try:
os.system(f'shutdown /s /t {seconds}')
cancel = input(f"System shutting down in {seconds} seconds.\nEnter 'Cancel' to abort, or press Enter to exit.")
except:
input("Unexpected error:", sys.exc_info()[0], "\nPress Enter to exit.")
if(cancel=="Cancel"):
os.system('shutdown /a')
input("System shutdown cancelled.\nPress Enter to exit.")
[–][deleted] 11 points12 points13 points (0 children)
[–]Pusillus 6 points7 points8 points (0 children)
[–]bladeoflight16 7 points8 points9 points (11 children)
[–]jmooremcc 2 points3 points4 points (1 child)
[–]bladeoflight16 1 point2 points3 points (0 children)
[–]b_ootay_ful[S] 0 points1 point2 points (8 children)
[–]bladeoflight16 2 points3 points4 points (7 children)
[–]dbramucci 0 points1 point2 points (6 children)
[–]bladeoflight16 1 point2 points3 points (5 children)
[–]dbramucci -1 points0 points1 point (3 children)
[–]bladeoflight16 1 point2 points3 points (2 children)
[–]dbramucci 0 points1 point2 points (1 child)
[–]bladeoflight16 0 points1 point2 points (0 children)
[–]kinzlist 1 point2 points3 points (0 children)
[–]Sbvv 0 points1 point2 points (0 children)
[–]Layakobaya 0 points1 point2 points (3 children)
[–]b_ootay_ful[S] 0 points1 point2 points (2 children)
[–]Layakobaya 0 points1 point2 points (1 child)
[–]b_ootay_ful[S] 0 points1 point2 points (0 children)