import time, os
from datetime import datetime

os.system('cls')
print('SCHEDULE | Independant Day Edition | 4th July 2022.')
print('Schedule set to run "cynthia.py" every 60 minutes.')
print('Schedule set to shutdown Windows PC at 19:00 hours.')
print('')

## NOTE: Set time to shutdown Windows (default 7pm in: '19:00' format) ##
asdt = '19:00'

## NOTE: Set periodicity for script run  (default 3600 secs (60 minutes)) ##
ptsd = 3600

## NOTE: To run the python script as soon as schedule starts - un-rem ##
## import cynthia

t = ptsd
while True:
    now = datetime.now()
    date_time = now.strftime('%H:%M')

    if t < 1:
        t = ptsd
        ## print('Check script launch ...')
        ## The Python script to run ##
        ## Cynthia-V.7.1.0.py
        os.system('Cynthia-V.7.1.0.py')
        #os.system('cynthia.py')
  
    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 = '\u221E  '
    else:
        dot = '  \u221E'
    print('Time to next scheduled job: [' + str(dot) + '] ' + timer, end='\r')
    time.sleep(1)
    t = t - 1

## Wend ##
