import time, os
from datetime import datetime

os.system('cls')
print('ALL NEW PYTHON SCRIPT SCHEDULER')
print('A Very Hot Summers Day v05 AUG 2022.')
print('Messrs Beak & Barker ~ The Py-thagoreans.')
print('')
print('Current settings:')

## NOTE: Set time to shutdown Windows: [Default: '19:10' (7.10pm)].
asdt = '19:10'
print('• Shutdown Windows PC at [' + asdt + '] hours.')

## NOTE: Name of python script to run:
my_py_name = 'Cynthia.py'

## NOTE: Set minutes element to run script: [Default: 59 mins].
run_mins = '00'
print('• Run ' + my_py_name + ' at [' + run_mins + '] minutes past the hour.')
print('')

while True:
    now = datetime.now()
    date_time = now.strftime('%H:%M:%S')
    min_time = now.strftime('%M')
    print('Current time: ' + date_time , end='\r')
    if run_mins == '00': #NOTE This is to make
        run_mins = '60'  #NOTE the sum below work correctly
    if int(min_time) == (int(run_mins) - 1): #NOTE Changed everthing to Integers so it could do the sum and start this bit the minute before
        ## Run python script buffer: Default 55 secs.
        for rp in range (59,0,-1): #NOTE Set to nearly the full minute for my OCD 
            print('  Python script [' + my_py_name + '] will run in [' + str(rp) + '] seconds).', end='\r')
            time.sleep(1)
        print() #NOTE I've currently taken the cls out of Cynthia. This print() is to stop it overwriting the line on the screen...
        os.system(my_py_name)

    if date_time >= asdt:
        ## Windows shutdown buffer: Default 50 secs.
        print('[x] Shutdown sequence has commenced... [x]')
        for sd in range (50,0,-1):
            print('  Windows will shutdown in [' + str(sd) + '] seconds.', end='\r')
            time.sleep(1)
        os.system('shutdown /s /t 1')
    
    time.sleep(1)
