import time, os
from datetime import datetime

os.system('cls')
print('ALL NEW SCRIPT SCHEDULER')
print('Independence Day Version 4th JULY 2022')
print('Messrs Beak & Barker @ The Pie Factory')
print('')
print('Current settings:')

## NOTE: Name of python script to run. ##
my_py_name = 'Cynthia-V.7.2.0.py'
#   my_py_name = 'cynthia.py'

## NOTE: Set periodicity for to script run, Default: 3600 secs (60 minutes).
ptsd = 3600
print('Run "' + my_py_name + '" every ' + (str(int(ptsd/60))) + ' minutes.')

## NOTE: Set time to shutdown Windows, Default: '19:00' (7pm). ##
asdt = '19:00'
print('Shutdown Windows PC at ' + asdt + ' hours.')
print('')

## NOTE: To run the python script as soon as scheduler starts - un-rem ##
## import cynthia

t = ptsd
while True:
    now = datetime.now()
    date_time = now.strftime('%H:%M')

    if t < 1:
        t = ptsd
        os.system(my_py_name)
  
    if date_time >= asdt:
        ## Windows shutdown buffer: Default 40 secs. ##
        print('[x] Shutdown sequence has commenced... [x]')
        for sd in range (40,0,-1):
            print('(Windows will shutdown in [' + str(sd) + '] seconds).', end='\r')
            time.sleep(1)
        os.system('shutdown /s /t 1')
    
    mins = t // 60
    secs = t % 60
    timer = '{:02d}:{:02d}'.format(mins, secs)
    if t & 1:
        dot = '• '      
    else:
        dot = ' •'
    print('Time to next scheduled job: [' + str(dot) + '] ' + timer, end='\r')
    time.sleep(1)
    t = t - 1
