Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Infinity loop
#1
Star 
Hello.

Good morning everyone :)

I warn you in advance that this is just the beginning of my adventure with "programming", so I ask for understanding and above all patience for my stupidity Big Grin
Due to the fact that for some time I'm terribly interested in python, I decided to try to write a program that could be useful to me and at the same time gain some knowledge.

To the point:

I would like to create a program that will detect a given image and perform certain actions. I've made myself a list of all the "rules" that must apply to it, i.e:

I've also created code that theoretically works and does what it wants to do, but it only does it once and I want it to do it indefinitely or until I stop it myself.
Can someone give me some advice? Sick
  ##### RULES ####

#x1, y1 = specific part of my screen
#x2, y2 = next specfic part of my screen
#"OPEN" picture always appear in x2,y2 

# Searching for picture "Open" in x2,y2
# if find, then:
#   Start searching for picture "Short" or "Long" in [(x1,y1) both are in the same area]
#   if find "Long", then:
#   click (100,100)
#   then wait for next picutre appears in (x2.y2)
#   If appears "XL" or "Short" then:
#   click (215,191)

#   if find "Short", then:
#   click (215,191)
#   then wait for next picutre appears in (x2.y2)
#   If appears "XS" or "Long" then:
#   click (137,191)

#if not find "OPEN", then searching until find
#repeat until i stoped. 
#repeat until I turn it off

#red = 137,191
#Blue = 215,191
I've also created code that theoretically works and does what it wants to do, but it only does it once and I want it to do it indefinitely or until I stop it myself.
Can someone give me some advice? Sick

from asyncore import loop
from pyautogui import *
import pyautogui
import time
import keyboard
import random
import win32api, win32con

while 1:             #Main loop, if true go to next     / if Not True, repeat until true 
    if pyautogui.locateOnScreen('Open1.png', region=(460,988,28,12), grayscale=True, confidence=0.8) != None:
        print("FOUND")
        time.sleep (1)   
        break  
    else:
        print("NOT FOUND")
        time.sleep(1)
        continue

while 1:            #Second loop 
    if pyautogui.locateOnScreen('Short1.png', region=(459,1022,30,12), grayscale=True, confidence=0.8) != None:
        print("SELL")
#        pyautogui.click(137, 191)
        break
    if pyautogui.locateOnScreen('Long1.png', region=(459,1023,27,12), grayscale=True, confidence=0.8) != None:
        print("LONG")
#        pyautogui.click(215, 191)
        break
    else:
        print("NOT FOUND")
        time.sleep(1)
        continue

while 1:                #Third loop 
    if pyautogui.locateOnScreen('XL1.png', region=(460,987,13,12), grayscale=True, confidence=0.8) != None:
        print("XL")
#        pyautogui.click(137, 191)
        break
    if pyautogui.locateOnScreen('Long1.png', region=(459,988,27,12), grayscale=True, confidence=0.8) != None:
        print("LONG1")
#        pyautogui.click(215, 191)
        break
    if pyautogui.locateOnScreen('XS1.png', region=(460,987,13,12), grayscale=True, confidence=0.8) != None:
        print("XS")
#        pyautogui.click(215, 191)
        break
    if pyautogui.locateOnScreen('Short1.png', region=(459,987,30,12), grayscale=True, confidence=0.8) != None:
        print("xSHORT1")
#        pyautogui.click(137, 191)
        break
    else:
        print("NOT FOUND")       
        time.sleep(1)
        continue   
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  int infinity Skaperen 2 1,867 Sep-13-2021, 04:42 AM
Last Post: Skaperen
  Importing a CSV loops to infinity in python bluethundr 2 3,549 May-03-2019, 03:28 PM
Last Post: bluethundr
  cannot convert float infinity to integer error despite rounding off floats Afterdarkreader 3 15,229 Dec-15-2017, 02:01 AM
Last Post: micseydel

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020