import time, os
from datetime import datetime

## Scheduler v26.05.2022

## NOTE: Set terminal screen size.
os.system('mode con: cols=75 lines=20')

c = 1
while (c > 0):
    now = datetime.now()
    date_time = now.strftime('%H:%M')
    ## print('Time now: ' + date_time)

    ## NOTE: The Python file(s) script(s) to run.

    ## Remove any tracks in REJECTS playlist from all other (listed) playists.
    ## os.system('rejects.py')

    ## Add any new tracks in ADDNEW playlist to MASTER db.
    ## os.system('violet-baby-sister.py')

    ## Remove played tracks from INFINITY playlist and top-up from db (to 50 max).
    os.system('cynthia.py') 

    ## NOTE: Set a time for scheduler to auto-shutdown Windows PC.
    asdt = '19:00' ## <== example: 7.00pm.
    print('')      ## https://unicode.org/emoji/charts/emoji-list.html 
    print('  Windows will shutdown after ' + str(asdt) + ' hours.')

    if date_time > asdt:
        print('> Shutdown sequence wil start in 20 secs...')
        time.sleep(20)
        os.system('shutdown /s /t 1')

    ## NOTE: Example: Set 'scheduler.py' to run 'cynthia.py' every 60 mins. (t = 3600 seconds).
    t = 3600
    while (t > 0):
        mins = t // 60
        secs = t % 60
        timer = '{:02d}:{:02d}'.format(mins, secs)

        if t & 1:
            dot = '• '          
        else:
            dot = ' •'

        ## NOTE: Print on the same line.
        print('  Time remaining to next cycle: [' + str(dot) + '] ' + timer, end="\r")
        time.sleep(1)
        t = t - 1

## End ##
