import time, os
from datetime import datetime

os.system('cls')
print('ALL NEW PYTHON SCRIPT SCHEDULER')
print('A Very Wet Autumns Day v06 NOV 2022.')
print('Messrs Beak & Barker ~ The Py-thagoreans.')
print('')
print('Current settings:')

## NOTE: Set time to start and finish running script.
asdt = '19:10' # Finish time
bsdt = '06:45' # Start time
csdt = '22:00:00' # BOOM Time
dsdt = '03:00:00' # Violet Time
esdt = '20:00:00' # Greatest Hits Time

icantrun = False
done = False

## NOTE: Name of python scripts to run:
#my_py_name1 = 'J:\HGMS\Cynthias\Cynthia.py'
my_py_name2 = 'J:\HGMS\Cynthias\Enormous_Cynthia.py'
#my_py_name3 = 'J:\HGMS\Cynthias\Cynthia.py'
my_py_name4 = 'J:\HGMS\Cynthias\Enormous_Cynthia.py'
#boom_name = 'C:\\Users\AlSmi\Dropbox\MUSIC-TIN\megaBOOM-Sorter\\mega.py'
#vi_name = 'J:\HGMS\Cynthias\Violet.py'
#great_name = 'C:\\Users\AlSmi\Dropbox\MUSIC-TIN\GREATEST\\Great.py'
## NOTE: Set minutes element to run script: [Default: 59 mins].
#run_mins1 = '00'
run_mins2 = '15'
#run_mins3 = '30'
run_mins4 = '45'

#print('• Run ' + my_py_name1 + ' at [' + run_mins1 + '] minutes past the hour.')
print('• Run ' + my_py_name2 + ' at [' + run_mins2 + '] minutes past the hour.')
#print('• Run ' + my_py_name3 + ' at [' + run_mins3 + '] minutes past the hour.')
print('• Run ' + my_py_name4 + ' at [' + run_mins4 + '] minutes past the hour.')
print('')

while True:


    now = datetime.now()
    date_time = now.strftime('%H:%M:%S')
    ###########################################################################################################
    whatday = datetime.weekday(datetime.now())
    #if whatday == 6:
    #    if date_time == dsdt:
            #os.system(vi_name)

    ###########################################################################################################
    min_time = now.strftime('%M')
    if date_time >= asdt:
        icantrun = True
    if date_time <= bsdt:
        icantrun = True
    if not icantrun:
        #NOTE If it is between the start and finish time
        print('Current time: ' + date_time + '  Running Hourly until  ' + asdt , end='\r')
    #    if run_mins1 == '00': #NOTE This is to make
    #        run_mins1 = '60'  #NOTE the sum below work correctly
    #    if int(min_time) == (int(run_mins1) - 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_name1 + '] 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_name1)
        # NOTE Changed everthing to Integers so it could do the sum and start this bit the minute before
        if int(min_time) == (int(run_mins2) - 1):
            ## 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_name2 + '] will run in [' + str(rp) + '] seconds).', end='\r')
                time.sleep(1)
            # NOTE I've currently taken the cls out of Cynthia. This print() is to stop it overwriting the line on the screen...
            print()
            os.system(my_py_name2)
    #    if int(min_time) == (int(run_mins3) - 1):
    #        ## 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_name3 + '] will run in [' + str(rp) + '] seconds).', end='\r')
    #            time.sleep(1)
    #        # NOTE I've currently taken the cls out of Cynthia. This print() is to stop it overwriting the line on the screen...
    #        print()
    #        os.system(my_py_name3)
        if int(min_time) == (int(run_mins4) - 1):
            ## 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_name4 + '] will run in [' + str(rp) + '] seconds).', end='\r')
                time.sleep(1)
            # NOTE I've currently taken the cls out of Cynthia. This print() is to stop it overwriting the line on the screen...
            print()
            os.system(my_py_name4)

    else:
        #NOTE If it is Outside the start and finish time
        print('Current time: ' + date_time + '  Script Sleeping until ' + bsdt , end='\r')
        icantrun = False
    
    time.sleep(1)
