No.3 Timed Shutdown
1 import datetime,os 2 print("---Timed Shutdown---") 3 print("1.Timed Shutdown") 4 print("2.Cancel Scheduled Shutdown") 5 try: 6 choice = int(input("")) 7 8 if choice == 2: 9 # os.system("shutdown -a") 10 if os.system("shutdown -a > nul 2> nul") == 1116: # 隐藏输出结果 >nul 2>nul 11 print("There is no Scheduled Shutdown!") 12 else: 13 print("Cancel Succeed!") 14 15 if choice == 1: 16 print("Setting Hour:") 17 hour = input("") 18 try: 19 hour = int(hour) 20 print("Setting Minute:") 21 minute = input("") 22 try: 23 minute = int(minute) 24 25 now = datetime.datetime.now() 26 now_hour = now.hour 27 now_minute = now.minute 28 29 hour_remain = (hour + minute / 60) - (now_hour + now_minute / 60) 30 minute_remain = hour_remain * 60 31 second_remain = hour_remain * 60 * 60 32 33 print("Setting Succeed!") 34 print("The power off is still left %d minute"% minute_remain) 35 36 os.system("shutdown -s -t %d "% second_remain) 37 38 except Exception: 39 print("Minute Set Error!") 40 41 except Exception: 42 print("Hour Set Error!") 43 44 except Exception: 45 print("Please follow the instructions