dynamicly download tesseract if not installed when full auto is launched

This commit is contained in:
Adam Saudagar 2020-10-18 06:13:24 +05:30
parent 69edc75c16
commit b44039780c
4 changed files with 70 additions and 11 deletions

View File

@ -47,9 +47,9 @@ class WindowClient:
return None
if not window_server.screen_ready():
logging.info("waiting for screen...")
print("waiting for screen...")
helper.wait_until(window_server.screen_ready)
logging.info("screen ready, continuing...")
print("screen ready, continuing...")
temp_img = WindowServer.Screen

View File

@ -1,5 +1,8 @@
import math
import os
import tempfile
import uuid
from zipfile import ZipFile
import cv2
import logging
@ -18,6 +21,7 @@ from pynput import keyboard, mouse
from fishy.helper import hotkey, helper
from fishy.helper.config import config
from fishy.helper.downloader import download_file_from_google_drive
from fishy.helper.hotkey import Key
mse = mouse.Controller()
@ -25,6 +29,26 @@ kb = keyboard.Controller()
offset = 0
def downlaoad_and_extract_tesseract():
logging.info("Tesseract-OCR downlaoding, Please wait...")
f = tempfile.NamedTemporaryFile(delete=False)
download_file_from_google_drive("16llzcBlaCsG9fm-rY2dD4Gvopnhm3XoE", f)
f.close()
logging.info("Tesseract-OCR downloaded, now installing")
addon_dir = os.path.join(os.environ["APPDATA"], "Tesseract-OCR")
with ZipFile(f.name, 'r') as z:
z.extractall(path=addon_dir)
logging.info("Tesseract-OCR installed")
def is_tesseract_installed():
return os.path.exists(os.path.join(os.environ["APPDATA"], "Tesseract-OCR"))
def sign(x):
return -1 if x < 0 else 1
@ -108,24 +132,21 @@ class FullAuto(IEngine):
def run(self):
logging.info("Loading please wait...")
self.gui.bot_started(True)
fishing_event.unsubscribe()
self.fisher.toggle_start()
self.controls.change_state()
self.window = WindowClient(color=cv2.COLOR_RGB2GRAY, show_name="Full auto debug")
if self.crop is None:
self.update_crop()
self.window.crop = self.crop
self._tesseract_dir = config.get("tesseract_dir", None)
if self._tesseract_dir is None:
logging.warning("Can't start without Tesseract Directory")
self.gui.bot_started(False)
self.toggle_start()
return
self.gui.bot_started(True)
self._tesseract_dir = os.path.join(os.environ["APPDATA"], "Tesseract-OCR")
if not is_tesseract_installed():
logging.info("tesseract not found")
downlaoad_and_extract_tesseract()
self.controls.change_state()
while self.start and WindowClient.running():
self.window.show(self.show, func=image_pre_process)
if not self.show:

View File

@ -1,4 +1,10 @@
import logging
import os
import tempfile
import typing
from zipfile import ZipFile
from google.auth.transport import requests
from fishy import web
from fishy.gui.notification import _give_notification_link
@ -7,6 +13,7 @@ from tkinter import *
from tkinter.ttk import *
from fishy.helper.config import config
from fishy.helper.downloader import download_file_from_google_drive
from fishy.helper.popup import PopUp
if typing.TYPE_CHECKING:

View File

@ -0,0 +1,31 @@
import requests
def download_file_from_google_drive(id, file):
URL = "https://docs.google.com/uc?export=download"
session = requests.Session()
response = session.get(URL, params={'id': id}, stream=True)
token = get_confirm_token(response)
if token:
params = {'id': id, 'confirm': token}
response = session.get(URL, params=params, stream=True)
save_response_content(response, file)
def get_confirm_token(response):
for key, value in response.cookies.items():
if key.startswith('download_warning'):
return value
return None
def save_response_content(response, f):
CHUNK_SIZE = 32768
for chunk in response.iter_content(CHUNK_SIZE):
if chunk: # filter out keep-alive new chunks
f.write(chunk)