Загрузка данных


import cv2
import numpy as np
import pytesseract
from PIL import ImageGrab
import time
import re

pytesseract.pytesseract.tesseract_cmd = r'C:\Program Files\Tesseract-OCR\tesseract.exe'

# захватываем всю верхнюю часть экрана
CROP_BOX = (0, 0, 1920, 400)

total_rub = 0
total_usd = 0
last_text = ""

print("Скрипт запущен! Нажми 'q' в окне с картинкой чтобы закрыть.")

while True:
    try:
        # делаем скрин
        img = ImageGrab.grab(bbox=CROP_BOX)
        img_np = np.array(img)
        img_bgr = cv2.cvtColor(img_np, cv2.COLOR_RGB2BGR)

        # покажем окно с тем, что видит скрипт прямо сейчас
        cv2.imshow("Chto vidit script", img_bgr)
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break

        # считываем абсолютно весь текст без фильтров
        text = pytesseract.image_to_string(img_bgr, lang='eng').strip()

        if text and text != last_text:
            rub_match = re.search(r'(\d[\d\s]*)\s*(?:RUB|RUBI|RUB!|руб|\$)', text, re.IGNORECASE)
            usd_match = re.search(r'(\d[\d\s]*)\s*(?:USD|USDI|USD!)', text, re.IGNORECASE)

            if rub_match:
                raw_val = rub_match.group(1).replace(' ', '')
                if raw_val.isdigit():
                    amount = int(raw_val)
                    if 100 <= amount <= 100000:
                        total_rub += amount
                        print(f"[+] Донат: {amount} RUB | Всего рублей: {total_rub}")
                        last_text = text

            elif usd_match:
                raw_val = usd_match.group(1).replace(' ', '')
                if raw_val.isdigit():
                    amount = int(raw_val)
                    if 1 <= amount <= 3000:
                        total_usd += amount
                        print(f"[+] Донат: {amount} USD | Всего баксов: {total_usd}")
                        last_text = text

    except Exception as e:
        print(f"Ошибка: {e}")

    time.sleep(1)

cv2.destroyAllWindows()