Python Forum

Full Version: Python Script Repeating Number When Saving Facebook Photos
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Good afternoon.
I'm having an issue with my code where every time the fifth photo is being saved, it's named as number 4, causing a problem with saving since it's considered as a duplicate name. I've tried to fix it with the help of ChatGPT and Copilot, but the error persists.
The code:

import pyautogui
import time
import keyboard
pyautogui.PAUSE = 0.2

def check_for_b():
    return keyboard.is_pressed('b')

time.sleep(4)

numero_foto = 1

while True:
    
    pyautogui.rightClick(x=718, y=499)
    pyautogui.click(x=845, y=559)
    pyautogui.click(x=112, y=328)
    pyautogui.doubleClick(x=706, y=223)
    pyautogui.click(x=579, y=466)
    pyautogui.write(f"foto_{numero_foto}")
    pyautogui.press("enter")
    pyautogui.click(x=751, y=556)
    pyautogui.press("right")

    if not check_for_b():
        numero_foto += 1
    else:
        break
My guess is some of these clicks are not clicking where you think they should. Is there a popup window that might be moving around?
Mines does it on chrome. For example in download it saves all of the photos the same name. Allison.jpg, Allison(2).jpg, and Allison(3).jpg. I have to go in and rename it myself. I got this download extension on chrome from the internet. It's from Java. But it works like that.