1
\$\begingroup\$

I have been playing around with schedule from GitHub. How can I improve the code?

def main():
    wipe()

    run_at_time = user_choice()

    if run_at_time:

        schedule.every().day.at(run_at_time).do(multi_processing)
        print('Schedule starts at: ''' + run_at_time + ' - Waiting for time...')
        print(space)
        idle = int(round(schedule.idle_seconds()))

        Hours = (idle / 60) / 60
        Minutes = (idle / 60)

        print("Hours left:   " + str(float("%.2f" % ((Hours)))) + "h")
        print("Minutes left: " + str(float("%.2f" % ((Minutes)))))
        print("Seconds left: " + str(float("%.2f" % ((idle)))))

        print(space)

        while True:
            schedule.run_pending()
            time.sleep(1)
            idle = int(round(schedule.idle_seconds()))
            if (idle < 6.0) and (idle >= 0.0):
                print('Starting in: ' + str(idle))

    else:
        multi_processing()

def user_choice():

    while True:
        user_input = input('To run Schedule task - Press y\nTo run directly - Press n\n').lower()
        print(user_input)
        if (user_input == 'y'):
            print(Fore.RESET + space)
            time_user = input('What time to start script? Format - HH:MM\n')
            print(space)
            return time_user

        elif (user_input == 'n'):
            return False

        print(space)
        print("Wrong input - Try again")’’’
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.