# Wizard Kit: Network Stability Test

import os
import sys

# Init
os.chdir(os.path.dirname(os.path.realpath(__file__)))
sys.path.append(os.getcwd())
from functions.common import *
init_global_vars()
os.system('title {}: Network Stability Test'.format(KIT_NAME_FULL))

# STATIC VARIABLES
NETWORK_TEST_URL = 'https://testmy.net/auto?extraID=A&schType=&st=1&r_time=0.1666667&xtimes=12&minDFS=&minUFS='
YOUTUBE_VID_URL = 'https://youtu.be/z7VYVjR_nwE'
PING_URL = 'google.com'

if __name__ == '__main__':
    try:
        stay_awake()
        clear_screen()
        print_info('{}: Network Stability Test\n'.format(KIT_NAME_FULL))

        # Open programs
        print_success('Starting browser tests')
        popen_program(['start', '', NETWORK_TEST_URL.replace('&', '^&')], shell=True)
        sleep(1)
        popen_program(['start', '', YOUTUBE_VID_URL], shell=True)

        # Start pinging
        try:
            run_program(['ping', '/t', PING_URL], pipe=False)
        except KeyboardInterrupt:
            # Gracefully close on interrupt
            pass

        # Done
        print_standard('\nDone.')
        pause('Press Enter to exit...')
        exit_script()
    except SystemExit as sys_exit:
      exit_script(sys_exit.code)
    except:
        major_exception()
