mirror of
https://github.com/fishyboteso/fishyboteso.git
synced 2024-08-30 18:32:13 +00:00
dynamicly download tesseract if not installed when full auto is launched
This commit is contained in:
parent
69edc75c16
commit
b44039780c
@ -47,9 +47,9 @@ class WindowClient:
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
if not window_server.screen_ready():
|
if not window_server.screen_ready():
|
||||||
logging.info("waiting for screen...")
|
print("waiting for screen...")
|
||||||
helper.wait_until(window_server.screen_ready)
|
helper.wait_until(window_server.screen_ready)
|
||||||
logging.info("screen ready, continuing...")
|
print("screen ready, continuing...")
|
||||||
|
|
||||||
temp_img = WindowServer.Screen
|
temp_img = WindowServer.Screen
|
||||||
|
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
import math
|
import math
|
||||||
|
import os
|
||||||
|
import tempfile
|
||||||
import uuid
|
import uuid
|
||||||
|
from zipfile import ZipFile
|
||||||
|
|
||||||
import cv2
|
import cv2
|
||||||
import logging
|
import logging
|
||||||
@ -18,6 +21,7 @@ from pynput import keyboard, mouse
|
|||||||
|
|
||||||
from fishy.helper import hotkey, helper
|
from fishy.helper import hotkey, helper
|
||||||
from fishy.helper.config import config
|
from fishy.helper.config import config
|
||||||
|
from fishy.helper.downloader import download_file_from_google_drive
|
||||||
from fishy.helper.hotkey import Key
|
from fishy.helper.hotkey import Key
|
||||||
|
|
||||||
mse = mouse.Controller()
|
mse = mouse.Controller()
|
||||||
@ -25,6 +29,26 @@ kb = keyboard.Controller()
|
|||||||
offset = 0
|
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):
|
def sign(x):
|
||||||
return -1 if x < 0 else 1
|
return -1 if x < 0 else 1
|
||||||
|
|
||||||
@ -108,24 +132,21 @@ class FullAuto(IEngine):
|
|||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
logging.info("Loading please wait...")
|
logging.info("Loading please wait...")
|
||||||
|
self.gui.bot_started(True)
|
||||||
fishing_event.unsubscribe()
|
fishing_event.unsubscribe()
|
||||||
self.fisher.toggle_start()
|
self.fisher.toggle_start()
|
||||||
self.controls.change_state()
|
|
||||||
|
|
||||||
self.window = WindowClient(color=cv2.COLOR_RGB2GRAY, show_name="Full auto debug")
|
self.window = WindowClient(color=cv2.COLOR_RGB2GRAY, show_name="Full auto debug")
|
||||||
if self.crop is None:
|
if self.crop is None:
|
||||||
self.update_crop()
|
self.update_crop()
|
||||||
self.window.crop = self.crop
|
self.window.crop = self.crop
|
||||||
|
|
||||||
self._tesseract_dir = config.get("tesseract_dir", None)
|
self._tesseract_dir = os.path.join(os.environ["APPDATA"], "Tesseract-OCR")
|
||||||
if self._tesseract_dir is None:
|
if not is_tesseract_installed():
|
||||||
logging.warning("Can't start without Tesseract Directory")
|
logging.info("tesseract not found")
|
||||||
self.gui.bot_started(False)
|
downlaoad_and_extract_tesseract()
|
||||||
self.toggle_start()
|
|
||||||
return
|
|
||||||
|
|
||||||
self.gui.bot_started(True)
|
|
||||||
|
|
||||||
|
self.controls.change_state()
|
||||||
while self.start and WindowClient.running():
|
while self.start and WindowClient.running():
|
||||||
self.window.show(self.show, func=image_pre_process)
|
self.window.show(self.show, func=image_pre_process)
|
||||||
if not self.show:
|
if not self.show:
|
||||||
|
@ -1,4 +1,10 @@
|
|||||||
|
import logging
|
||||||
|
import os
|
||||||
|
import tempfile
|
||||||
import typing
|
import typing
|
||||||
|
from zipfile import ZipFile
|
||||||
|
|
||||||
|
from google.auth.transport import requests
|
||||||
|
|
||||||
from fishy import web
|
from fishy import web
|
||||||
from fishy.gui.notification import _give_notification_link
|
from fishy.gui.notification import _give_notification_link
|
||||||
@ -7,6 +13,7 @@ from tkinter import *
|
|||||||
from tkinter.ttk import *
|
from tkinter.ttk import *
|
||||||
|
|
||||||
from fishy.helper.config import config
|
from fishy.helper.config import config
|
||||||
|
from fishy.helper.downloader import download_file_from_google_drive
|
||||||
from fishy.helper.popup import PopUp
|
from fishy.helper.popup import PopUp
|
||||||
|
|
||||||
if typing.TYPE_CHECKING:
|
if typing.TYPE_CHECKING:
|
||||||
|
31
fishy/helper/downloader.py
Normal file
31
fishy/helper/downloader.py
Normal 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)
|
Loading…
Reference in New Issue
Block a user