-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
65 lines (54 loc) · 2.09 KB
/
Copy pathmain.py
File metadata and controls
65 lines (54 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
from pyautogui import locateOnScreen, center, click
from time import sleep
from configparser import ConfigParser
import winsound # Solo Windows, ver abajo para multiplataforma
#Default values
delay_between_tries = 0.2
delay_after_succeding = 1
delay_after_failing = 5
#If the config has values, use those instead
config = ConfigParser()
config.read('settings.ini')
if config.has_option("SETTINGS", "delay_between_tries"):
delay_between_tries = float(config["SETTINGS"]["delay_between_tries"])
if config.has_option("SETTINGS", "delay_after_succeding"):
delay_after_succeding = float(config["SETTINGS"]["delay_after_succeding"])
if config.has_option("SETTINGS", "delay_after_failing"):
delay_after_failing = float(config["SETTINGS"]["delay_after_failing"])
def try_click(image, confidence=0.6):
"""Intenta localizar y hacer click en una imagen. Retorna True si lo logra."""
location = locateOnScreen(image, confidence=confidence)
if location is None:
return False
point = center(location)
click(point.x, point.y)
return True
def emit_sound():
"""Emite un sonido de alerta."""
try:
winsound.MessageBeep(winsound.MB_ICONEXCLAMATION)
except Exception:
# Multiplataforma: si no hay winsound, usa print con bell
print("\a")
#Main loop
while True:
sleep(delay_between_tries)
# Intento 1: imagen principal
try:
if try_click("reference.png"):
sleep(delay_after_succeding)
continue
except Exception as e:
print(f"Error con reference.png: {e}")
# Intento 2: imagen alternativa
print("No se encontró reference.png, intentando con reference_alt.png...")
try:
if try_click("reference_alt.png"):
sleep(delay_after_succeding)
continue
except Exception as e:
print(f"Error con reference_alt.png: {e}")
# Ambas fallaron: emitir sonido y esperar
print(f"Ambas imágenes fallaron. Emitiendo sonido y esperando {delay_after_failing}s...")
emit_sound()
sleep(delay_after_failing)