vendredi 11 décembre 2020

Loop won't continue after an if statement

I'm new to loops in python and I'm trying to end a loop if the value of a specific cell on google sheets changes to 30 or below. I have tried using "continue" instead of "break" and I have tried indenting the next loop to line up with the if statement but nothing has seemed to work. The first loop runs fine but, when the right conditions are met, it doesn't continue to the next and just repeats the first loop. Here's what I have so far:

        for b in range(179):

            time.sleep(5)

            #Get screenshot
            pyautogui.screenshot("Volume.png")

            #Crop out volume number
            im = Image.open("Volume.png")

            x1 = 2570
            y1 = 607
            x2 = 2671
            y2 = 637

            cropped = im.crop((x1, y1, x2, y2))

            cropped.save("Volume.png")

            #Convert image to text
            img = cv2.imread("Volume.png")

            text = image_to_string(img)

            #Import current volume 
            sheet.update_cell(3,2, text)



            change = sheet.cell(3,5).value
            floatt = float(change)

            if floatt <= 30:
                
                break

        #Start price
        for c in range(1):

            #Get screenshot
            pyautogui.screenshot("Price.png")

            #Crop out price number
            im = Image.open("Price.png")

            x1 = 1854
            y1 = 988
            x2 = 2074
            y2 = 1036

            cropped = im.crop((x1, y1, x2, y2))

            cropped.save("Price.png")

            #Convert image to text
            img = cv2.imread("Price.png")

            text = image_to_string(img)

            #Import start price
            sheet.update_cell(9,2, text)

Aucun commentaire:

Enregistrer un commentaire