import cv2
import pyautogui
import numpy as np
import time
import telegram
import asyncio
bot = telegram.Bot(token='token tg')
chat_id = 'chat id tg'
# Загрузка изображений
img_vosem = cv2.imread('vosem.png', 0)
img_dva = cv2.imread('dva.png', 0)
async def send_message_async(chat_id, message):
await bot.send_message(chat_id=chat_id, text=message)
def locate_image(template, threshold=0.8):
screenshot = pyautogui.screenshot()
screenshot = np.array(screenshot)
screenshot = cv2.cvtColor(screenshot, cv2.COLOR_RGB2BGR)
screenshot_gray = cv2.cvtColor(screenshot, cv2.COLOR_BGR2GRAY)
result = cv2.matchTemplate(screenshot_gray, template, cv2.TM_CCOEFF_NORMED)
min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(result)
if max_val >= threshold:
return (max_loc[0], max_loc[1])
else:
return None
async def main():
while True:
vosem_loc = locate_image(img_vosem)
if vosem_loc:
message = f"Нашел 8. Корды: {vosem_loc}"
await send_message_async(chat_id, message)
time.sleep(5)
pyautogui.press('8')
time.sleep(5)
dva_loc = locate_image(img_dva)
if dva_loc:
message = f"Нашел 2. Корды: {dva_loc}"
await send_message_async(chat_id, message)
time.sleep(5)
pyautogui.press('2')
time.sleep(5)
loop = asyncio.get_event_loop()
loop.run_until_complete(main())