import time, os
from datetime import datetime

## RADIO bot schedule controller v22-02-2022.
## Set terminal screen size.
os.system('mode con: cols=72 lines=48')

c = 1
while (c > 0):
    now = datetime.now()
    date_time = now.strftime('%H:%M')
    ## print('Time now: ' + date_time)
    os.system('main.py')

    ## Set a time for scheduler to auto-shutdown Windows PC.
    asdt = '19:00' ## example: 7.00pm.
    print('  Windows set to shutdown after ' + str(asdt) + ' hours.')

    if date_time > asdt:
        print('> Shutdown sequence start in 10 secs...')
        time.sleep(10)
        os.system('shutdown /s /t 1')

    ## Set bot to run 'main.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:
            tick = '/'
        else:
            tick = '\\'

        ## Print on the same line and column.
        print('  Time remaining to next cycle: [' + str(tick) + '] ' + timer, end="\r")
        time.sleep(1)
        t = t - 1

## End