Automating a login with Pyautogui

I am doing some automation process using pyautogui to get some files from Google Drive and send them to somewhere else.

So far it's working great if i am already logged in (just a small sample of the code):

import pyautogui 
import pyperclip
pyautogui.press('winleft')
pyautogui.write('chrome')
pyautogui.press('enter')
pyautogui.alert('We going to start soon, press OK')
pyperclip.copy('the link to my google drive account')
pyautogui.hotkey('ctrl', 'v')
pyautogui.press('enter')

I know how i can change the above code to make it work if i am logged out. Just need to add some more lines of pyautogui.write, pyautogui.press and pyautogui.click.

But, my question is, what can be done to do a checking if i am logged in already or not?


Solution 1:

You could use pyautogui to check the colour of a pixel. All you have to do is find one pixel on the logged out screen of a different colour than the logged in screen and find its position and hexcode. replace the x and y in the following code of this pixel.

color = getpixel(x, y)

if color == (unique rgb value of logged out screen.)

#place the rest of your code