From 8653de86a53d16e19ae9e4981acd544aa44f3a93 Mon Sep 17 00:00:00 2001 From: Zhao Zuohong <1040110848@qq.com> Date: Fri, 19 Jul 2024 04:47:04 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B4=E7=90=86import?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- arknights_mower/__main__.py | 19 +-- arknights_mower/models/__init__.py | 24 ++++ arknights_mower/solvers/__init__.py | 17 --- arknights_mower/solvers/auto_fight.py | 10 +- arknights_mower/solvers/base_mixin.py | 4 +- arknights_mower/solvers/base_schedule.py | 29 ++-- arknights_mower/solvers/depotREC.py | 2 +- arknights_mower/solvers/navigation.py | 9 +- arknights_mower/solvers/operation.py | 4 +- .../solvers/reclamation_algorithm.py | 3 +- arknights_mower/solvers/recruit.py | 2 +- arknights_mower/solvers/report.py | 14 +- arknights_mower/solvers/secret_front.py | 14 +- arknights_mower/solvers/shop.py | 19 +-- arknights_mower/tests/recruit_tests.py | 2 +- arknights_mower/utils/config.py | 5 +- arknights_mower/utils/csleep.py | 23 +++ arknights_mower/utils/datetime.py | 16 +++ arknights_mower/utils/device/__init__.py | 4 - .../utils/device/adb_client/__init__.py | 3 - .../utils/device/adb_client/core.py | 18 +-- .../utils/device/adb_client/session.py | 6 +- .../utils/device/adb_client/socket.py | 2 +- .../utils/device/adb_client/utils.py | 10 +- arknights_mower/utils/device/device.py | 11 +- .../utils/device/maatouch/__init__.py | 2 +- .../utils/device/maatouch/command.py | 6 +- arknights_mower/utils/device/maatouch/core.py | 13 +- .../utils/device/maatouch/session.py | 5 +- .../utils/device/minitouch/__init__.py | 2 +- .../utils/device/minitouch/command.py | 6 +- .../utils/device/minitouch/core.py | 14 +- .../utils/device/minitouch/session.py | 2 +- arknights_mower/utils/device/scrcpy/core.py | 12 +- arknights_mower/utils/device/utils.py | 2 - arknights_mower/utils/graph.py | 3 +- arknights_mower/utils/image.py | 5 +- arknights_mower/utils/log.py | 2 +- arknights_mower/utils/matcher.py | 2 - arknights_mower/utils/recognize.py | 24 ++-- arknights_mower/utils/scheduler_task.py | 3 +- arknights_mower/utils/segment.py | 2 - arknights_mower/utils/simulator.py | 135 +++++++++--------- arknights_mower/utils/solver.py | 55 +++---- requirements.txt | 2 +- server.py | 3 +- 46 files changed, 255 insertions(+), 315 deletions(-) create mode 100644 arknights_mower/models/__init__.py create mode 100644 arknights_mower/utils/csleep.py diff --git a/arknights_mower/__main__.py b/arknights_mower/__main__.py index 157d1ecaf..209d03589 100644 --- a/arknights_mower/__main__.py +++ b/arknights_mower/__main__.py @@ -9,6 +9,8 @@ from arknights_mower.solvers.reclamation_algorithm import ReclamationAlgorithm from arknights_mower.solvers.secret_front import SecretFront from arknights_mower.utils import config, path, rapidocr +from arknights_mower.utils.csleep import MowerExit +from arknights_mower.utils.datetime import format_time from arknights_mower.utils.depot import 创建csv, 创建json from arknights_mower.utils.device.adb_client.session import Session from arknights_mower.utils.device.scrcpy import Scrcpy @@ -19,7 +21,6 @@ from arknights_mower.utils.path import get_path from arknights_mower.utils.plan import Plan, PlanConfig, Room from arknights_mower.utils.simulator import restart_simulator -from arknights_mower.utils.solver import MowerExit global base_scheduler base_scheduler = None @@ -59,22 +60,6 @@ def main(): simulate() -# newbing说用这个来定义休息时间省事 -def format_time(seconds): - if seconds < 0: # 权宜之计 配合刷生息演算 - return f"{0} 分钟" # 权宜之计 配合刷生息演算 - # 计算小时和分钟 - rest_hours = int(seconds / 3600) - rest_minutes = int((seconds % 3600) / 60) - # 根据小时是否为零来决定是否显示 - if rest_hours == 0: - return f"{rest_minutes} 分钟" - elif rest_minutes == 0: - return f"{rest_hours} 小时" - else: - return f"{rest_hours} 小时 {rest_minutes} 分钟" - - def get_logic_exp(trigger): for k in ["left", "operator", "right"]: if not isinstance(trigger[k], str): diff --git a/arknights_mower/models/__init__.py b/arknights_mower/models/__init__.py new file mode 100644 index 000000000..e7548ff19 --- /dev/null +++ b/arknights_mower/models/__init__.py @@ -0,0 +1,24 @@ +import lzma +import pickle + +from arknights_mower import __rootdir__ + +with lzma.open(f"{__rootdir__}/models/avatar.pkl", "rb") as f: + avatar = pickle.load(f) + + +with lzma.open(f"{__rootdir__}/models/secret_front.pkl", "rb") as f: + secret_front = pickle.load(f) + + +with lzma.open(f"{__rootdir__}/models/navigation.pkl", "rb") as f: + navigation = pickle.load(f) + +with lzma.open(f"{__rootdir__}/models/riic_base_digits.pkl", "rb") as f: + riic_base_digits = pickle.load(f) + +with lzma.open(f"{__rootdir__}/models/noto_sans.pkl", "rb") as f: + noto_sans = pickle.load(f) + +with lzma.open(f"{__rootdir__}/models/shop.pkl", "rb") as f: + shop = pickle.load(f) diff --git a/arknights_mower/solvers/__init__.py b/arknights_mower/solvers/__init__.py index 9e5912e6a..e69de29bb 100644 --- a/arknights_mower/solvers/__init__.py +++ b/arknights_mower/solvers/__init__.py @@ -1,17 +0,0 @@ -from .credit import CreditSolver -from .cultivate_depot import cultivate as cultivateDepotSolver -from .depotREC import depotREC as DepotSolver -from .mail import MailSolver -from .mission import MissionSolver -from .recruit import RecruitSolver -from .report import ReportSolver - -__all__ = [ - "CreditSolver", - "MailSolver", - "MissionSolver", - "RecruitSolver", - "DepotSolver", - "cultivateDepotSolver", - "ReportSolver", -] diff --git a/arknights_mower/solvers/auto_fight.py b/arknights_mower/solvers/auto_fight.py index 4dfede524..870ce9864 100644 --- a/arknights_mower/solvers/auto_fight.py +++ b/arknights_mower/solvers/auto_fight.py @@ -1,13 +1,10 @@ -import lzma -import pickle from time import sleep import cv2 from scipy.signal import argrelmax from skimage.metrics import structural_similarity -from arknights_mower import __rootdir__ -from arknights_mower.solvers.secret_front import templates +from arknights_mower.models import avatar, secret_front from arknights_mower.utils import typealias as tp from arknights_mower.utils.image import cropimg, loadres, thres2 from arknights_mower.utils.log import logger @@ -15,9 +12,6 @@ from arknights_mower.utils.tile_pos import Calc, find_level from arknights_mower.utils.vector import sa, va -with lzma.open(f"{__rootdir__}/models/avatar.pkl", "rb") as f: - avatar = pickle.load(f) - class AutoFight(BaseSolver): def run(self, level_name, opers, actions): @@ -62,7 +56,7 @@ def number(self, scope: tp.Scope, height: int, thres: int) -> int: ) score = [] for i in range(10): - im = templates[i] + im = secret_front[i] result = cv2.matchTemplate(digit, im, cv2.TM_SQDIFF_NORMED) min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(result) score.append(min_val) diff --git a/arknights_mower/solvers/base_mixin.py b/arknights_mower/solvers/base_mixin.py index 333da16a3..da3e6fb70 100644 --- a/arknights_mower/solvers/base_mixin.py +++ b/arknights_mower/solvers/base_mixin.py @@ -1,5 +1,3 @@ -from __future__ import annotations - import lzma import pickle from datetime import datetime, timedelta @@ -10,9 +8,9 @@ from arknights_mower import __rootdir__ from arknights_mower.utils import rapidocr, segment from arknights_mower.utils.character_recognize import operator_list +from arknights_mower.utils.csleep import MowerExit from arknights_mower.utils.image import cropimg, loadres, thres2 from arknights_mower.utils.log import logger -from arknights_mower.utils.solver import MowerExit with lzma.open(f"{__rootdir__}/models/operator_room.model", "rb") as f: OP_ROOM = pickle.loads(f.read()) diff --git a/arknights_mower/solvers/base_schedule.py b/arknights_mower/solvers/base_schedule.py index 45687065b..7a2bead9b 100644 --- a/arknights_mower/solvers/base_schedule.py +++ b/arknights_mower/solvers/base_schedule.py @@ -1,5 +1,3 @@ -from __future__ import annotations - import copy import json import os @@ -11,30 +9,27 @@ import cv2 -# 借用__main__.py里的时间计算器 -from arknights_mower.__main__ import format_time from arknights_mower.data import agent_list, base_room_list -from arknights_mower.solvers import ( - CreditSolver, - DepotSolver, - MailSolver, - RecruitSolver, - ReportSolver, - cultivateDepotSolver, -) from arknights_mower.solvers.base_mixin import BaseMixin +from arknights_mower.solvers.credit import CreditSolver from arknights_mower.solvers.credit_fight import CreditFight +from arknights_mower.solvers.cultivate_depot import cultivate as cultivateDepotSolver +from arknights_mower.solvers.depotREC import depotREC as DepotSolver +from arknights_mower.solvers.mail import MailSolver from arknights_mower.solvers.mission import MissionSolver from arknights_mower.solvers.navigation import NavigationSolver from arknights_mower.solvers.operation import OperationSolver from arknights_mower.solvers.reclamation_algorithm import ReclamationAlgorithm +from arknights_mower.solvers.recruit import RecruitSolver +from arknights_mower.solvers.report import ReportSolver from arknights_mower.solvers.secret_front import SecretFront from arknights_mower.solvers.shop import CreditShop from arknights_mower.solvers.skland import SKLand from arknights_mower.utils import config, detector, hot_update, rapidocr from arknights_mower.utils import typealias as tp -from arknights_mower.utils.datetime import get_server_weekday -from arknights_mower.utils.device import Device +from arknights_mower.utils.csleep import MowerExit, csleep +from arknights_mower.utils.datetime import format_time, get_server_weekday +from arknights_mower.utils.device.device import Device from arknights_mower.utils.digit_reader import DigitReader from arknights_mower.utils.graph import SceneGraphSolver from arknights_mower.utils.image import cropimg, loadres, thres2 @@ -52,8 +47,6 @@ scheduling, try_add_release_dorm, ) -from arknights_mower.utils.simulator import restart_simulator -from arknights_mower.utils.solver import MowerExit def daily_report( @@ -3381,7 +3374,7 @@ def maa_plan_solver(self): self.MAA.stop() break else: - self.csleep(5) + csleep(5) self.device.exit() self.check_current_focus() @@ -3414,6 +3407,8 @@ def maa_plan_solver(self): if remaining_time > 0: if remaining_time > 300: if self.close_simulator_when_idle: + from arknights_mower.utils.simulator import restart_simulator + restart_simulator(start=False) elif self.exit_game_when_idle: self.device.exit() diff --git a/arknights_mower/solvers/depotREC.py b/arknights_mower/solvers/depotREC.py index adb1b505e..6cd4d0a2c 100644 --- a/arknights_mower/solvers/depotREC.py +++ b/arknights_mower/solvers/depotREC.py @@ -13,7 +13,7 @@ from arknights_mower.utils.graph import SceneGraphSolver from .. import __rootdir__ -from ..utils.device import Device +from ..utils.device.device import Device from ..utils.image import loadimg from ..utils.log import logger from ..utils.path import get_path diff --git a/arknights_mower/solvers/navigation.py b/arknights_mower/solvers/navigation.py index 557f4085a..1886db5a9 100644 --- a/arknights_mower/solvers/navigation.py +++ b/arknights_mower/solvers/navigation.py @@ -1,10 +1,8 @@ -import lzma -import pickle import re import cv2 -from arknights_mower import __rootdir__ +from arknights_mower.models import navigation from arknights_mower.utils import hot_update from arknights_mower.utils.graph import SceneGraphSolver from arknights_mower.utils.log import logger @@ -144,9 +142,6 @@ "hard", ] -with lzma.open(f"{__rootdir__}/models/navigation.pkl", "rb") as f: - templates = pickle.load(f) - class NavigationSolver(SceneGraphSolver): def run(self, name: str): @@ -307,7 +302,7 @@ def transition(self): return for i in location[prefix]: result = cv2.matchTemplate( - self.recog.gray, templates[i], cv2.TM_SQDIFF_NORMED + self.recog.gray, navigation[i], cv2.TM_SQDIFF_NORMED ) min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(result) if min_val < val: diff --git a/arknights_mower/solvers/operation.py b/arknights_mower/solvers/operation.py index 45553a908..9276518b6 100644 --- a/arknights_mower/solvers/operation.py +++ b/arknights_mower/solvers/operation.py @@ -3,7 +3,7 @@ import cv2 -from arknights_mower.solvers.secret_front import templates +from arknights_mower.models import secret_front from arknights_mower.utils import config from arknights_mower.utils import typealias as tp from arknights_mower.utils.graph import SceneGraphSolver @@ -39,7 +39,7 @@ def number(self, scope: tp.Scope, height: Optional[int] = None): ) score = [] for i in range(10): - im = templates[i] + im = secret_front[i] result = cv2.matchTemplate(digit, im, cv2.TM_SQDIFF_NORMED) min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(result) score.append(min_val) diff --git a/arknights_mower/solvers/reclamation_algorithm.py b/arknights_mower/solvers/reclamation_algorithm.py index 18a9732eb..6d1d914b1 100644 --- a/arknights_mower/solvers/reclamation_algorithm.py +++ b/arknights_mower/solvers/reclamation_algorithm.py @@ -8,11 +8,12 @@ from arknights_mower.utils import rapidocr from arknights_mower.utils import typealias as tp +from arknights_mower.utils.csleep import MowerExit from arknights_mower.utils.image import cropimg, loadres, thres2 from arknights_mower.utils.log import logger from arknights_mower.utils.matcher import Matcher from arknights_mower.utils.scene import Scene -from arknights_mower.utils.solver import BaseSolver, MowerExit +from arknights_mower.utils.solver import BaseSolver src_pts = np.float32([[0, 97], [1920, 97], [-400, 1080], [2320, 1080]]) dst_pts = np.float32([[0, 0], [1920, 0], [0, 1000], [1920, 1000]]) diff --git a/arknights_mower/solvers/recruit.py b/arknights_mower/solvers/recruit.py index 1728f62f5..298c57443 100644 --- a/arknights_mower/solvers/recruit.py +++ b/arknights_mower/solvers/recruit.py @@ -13,7 +13,7 @@ result_template_list, ) from arknights_mower.utils import rapidocr, segment -from arknights_mower.utils.device import Device +from arknights_mower.utils.device.device import Device from arknights_mower.utils.digit_reader import DigitReader from arknights_mower.utils.email import recruit_rarity, recruit_template from arknights_mower.utils.graph import SceneGraphSolver diff --git a/arknights_mower/solvers/report.py b/arknights_mower/solvers/report.py index 70a17905e..8e7962aca 100644 --- a/arknights_mower/solvers/report.py +++ b/arknights_mower/solvers/report.py @@ -1,15 +1,11 @@ -from __future__ import annotations - import datetime -import lzma import os -import pickle import cv2 import pandas as pd -from arknights_mower.data import __rootdir__ -from arknights_mower.utils.device import Device +from arknights_mower.models import noto_sans +from arknights_mower.utils.device.device import Device from arknights_mower.utils.digit_reader import DigitReader from arknights_mower.utils.email import report_template from arknights_mower.utils.graph import SceneGraphSolver @@ -18,10 +14,6 @@ from arknights_mower.utils.path import get_path from arknights_mower.utils.recognize import Recognizer, Scene, tp -number = {} -with lzma.open(f"{__rootdir__}/models/noto_sans.pkl", "rb") as f: - number = pickle.load(f) - def remove_blank(target: str): if target is None or target == "": @@ -207,7 +199,7 @@ def get_number( score = [] for i in range(10): - im = number[i] + im = noto_sans[i] result = cv2.matchTemplate(digit, im, cv2.TM_SQDIFF_NORMED) min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(result) score.append(min_val) diff --git a/arknights_mower/solvers/secret_front.py b/arknights_mower/solvers/secret_front.py index 77497efc3..1663986b9 100644 --- a/arknights_mower/solvers/secret_front.py +++ b/arknights_mower/solvers/secret_front.py @@ -1,21 +1,17 @@ -import lzma -import pickle from datetime import datetime, timedelta from typing import Optional import cv2 -from arknights_mower import __rootdir__ +from arknights_mower.models import secret_front from arknights_mower.utils import config from arknights_mower.utils import typealias as tp +from arknights_mower.utils.csleep import MowerExit from arknights_mower.utils.image import cropimg, thres2 from arknights_mower.utils.log import logger from arknights_mower.utils.matcher import Matcher from arknights_mower.utils.recognize import Scene -from arknights_mower.utils.solver import BaseSolver, MowerExit - -with lzma.open(f"{__rootdir__}/models/secret_front.pkl", "rb") as f: - templates = pickle.load(f) +from arknights_mower.utils.solver import BaseSolver def exp(card): @@ -113,7 +109,7 @@ def number(self, scope: tp.Scope, height: Optional[int] = None): ) score = [] for i in range(10): - im = templates[i] + im = secret_front[i] result = cv2.matchTemplate(digit, im, cv2.TM_SQDIFF_NORMED) min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(result) score.append(min_val) @@ -137,7 +133,7 @@ def stage_card(self, total, idx): img = cv2.copyMakeBorder(img, 10, 10, 10, 10, cv2.BORDER_CONSTANT, None, (0,)) score = [] for i in self.target: - result = cv2.matchTemplate(img, templates[i], cv2.TM_SQDIFF_NORMED) + result = cv2.matchTemplate(img, secret_front[i], cv2.TM_SQDIFF_NORMED) min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(result) score.append(min_val) name = list(self.target)[score.index(min(score))] diff --git a/arknights_mower/solvers/shop.py b/arknights_mower/solvers/shop.py index e2729aa35..5369f4f70 100644 --- a/arknights_mower/solvers/shop.py +++ b/arknights_mower/solvers/shop.py @@ -1,9 +1,6 @@ -import lzma -import pickle - import cv2 -from arknights_mower import __rootdir__ +from arknights_mower.models import noto_sans, riic_base_digits, shop from arknights_mower.utils import config from arknights_mower.utils import typealias as tp from arknights_mower.utils.graph import SceneGraphSolver @@ -12,14 +9,6 @@ from arknights_mower.utils.scene import Scene from arknights_mower.utils.vector import sa, va -with lzma.open(f"{__rootdir__}/models/riic_base_digits.pkl", "rb") as f: - base_templates = pickle.load(f) -with lzma.open(f"{__rootdir__}/models/noto_sans.pkl", "rb") as f: - noto_templates = pickle.load(f) -with lzma.open(f"{__rootdir__}/models/shop.pkl", "rb") as f: - shop_templates = pickle.load(f) - - card_w, card_h = 352, 354 top, left = 222, 25 gap = 28 @@ -52,10 +41,10 @@ def number( img = cropimg(self.recog.gray, scope) if font == "riic_base": - templates = base_templates + templates = riic_base_digits default_height = 28 else: - templates = noto_templates + templates = noto_sans default_height = 29 if height and height != default_height: @@ -113,7 +102,7 @@ def product_info(self): target, 10, 10, 30, 10, cv2.BORDER_CONSTANT, None, (0,) ) target = thres2(target, 127) - for name, img in shop_templates.items(): + for name, img in shop.items(): result = cv2.matchTemplate(target, img, cv2.TM_SQDIFF_NORMED) min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(result) if min_val < score: diff --git a/arknights_mower/tests/recruit_tests.py b/arknights_mower/tests/recruit_tests.py index ca43fb090..1eb7a970f 100644 --- a/arknights_mower/tests/recruit_tests.py +++ b/arknights_mower/tests/recruit_tests.py @@ -1,5 +1,5 @@ # -!- coding: utf-8 -!- -from __future__ import annotations + import os import pathlib diff --git a/arknights_mower/utils/config.py b/arknights_mower/utils/config.py index 0351a5673..cfab25a1d 100644 --- a/arknights_mower/utils/config.py +++ b/arknights_mower/utils/config.py @@ -1,5 +1,3 @@ -from __future__ import annotations - import shutil import sys @@ -10,6 +8,7 @@ except ImportError: from collections import Mapping from pathlib import Path +from threading import Event from typing import Any from .. import __pyinstall__, __system__ @@ -161,4 +160,4 @@ def init_adb_buildin() -> Path: conf = {} droidcast = {"enable": False, "session": requests.Session(), "port": 0, "process": None} TAP_TO_LAUNCH = {"enable": False, "x": 0, "y": 0} -stop_mower = None +stop_mower = Event() diff --git a/arknights_mower/utils/csleep.py b/arknights_mower/utils/csleep.py new file mode 100644 index 000000000..e83d344d7 --- /dev/null +++ b/arknights_mower/utils/csleep.py @@ -0,0 +1,23 @@ +import time +from datetime import datetime, timedelta + +from arknights_mower.utils import config + + +class MowerExit(Exception): + pass + + +def csleep(interval: float = 1): + """check and sleep""" + stop_time = datetime.now() + timedelta(seconds=interval) + while True: + if config.stop_mower.is_set(): + raise MowerExit + remaining = stop_time - datetime.now() + if remaining > timedelta(seconds=1): + time.sleep(1) + elif remaining > timedelta(): + time.sleep(remaining.total_seconds()) + else: + return diff --git a/arknights_mower/utils/datetime.py b/arknights_mower/utils/datetime.py index bbf187eb0..cd5b4e31e 100644 --- a/arknights_mower/utils/datetime.py +++ b/arknights_mower/utils/datetime.py @@ -17,3 +17,19 @@ def the_same_time(a: datetime = None, b: datetime = None) -> bool: def get_server_weekday(): return datetime.now(pytz.timezone("Asia/Dubai")).weekday() + + +# newbing说用这个来定义休息时间省事 +def format_time(seconds): + if seconds < 0: # 权宜之计 配合刷生息演算 + return f"{0} 分钟" # 权宜之计 配合刷生息演算 + # 计算小时和分钟 + rest_hours = int(seconds / 3600) + rest_minutes = int((seconds % 3600) / 60) + # 根据小时是否为零来决定是否显示 + if rest_hours == 0: + return f"{rest_minutes} 分钟" + elif rest_minutes == 0: + return f"{rest_hours} 小时" + else: + return f"{rest_hours} 小时 {rest_minutes} 分钟" diff --git a/arknights_mower/utils/device/__init__.py b/arknights_mower/utils/device/__init__.py index af102bfa7..e69de29bb 100644 --- a/arknights_mower/utils/device/__init__.py +++ b/arknights_mower/utils/device/__init__.py @@ -1,4 +0,0 @@ -from .adb_client.const import KeyCode -from .device import Device - -__all__ = ["KeyCode", "Device"] diff --git a/arknights_mower/utils/device/adb_client/__init__.py b/arknights_mower/utils/device/adb_client/__init__.py index eacd3f0d2..e69de29bb 100644 --- a/arknights_mower/utils/device/adb_client/__init__.py +++ b/arknights_mower/utils/device/adb_client/__init__.py @@ -1,3 +0,0 @@ -from .core import Client as ADBClient - -__all__ = ["ADBClient"] diff --git a/arknights_mower/utils/device/adb_client/core.py b/arknights_mower/utils/device/adb_client/core.py index 50e051c45..393a85cad 100644 --- a/arknights_mower/utils/device/adb_client/core.py +++ b/arknights_mower/utils/device/adb_client/core.py @@ -1,17 +1,15 @@ -from __future__ import annotations - import socket import subprocess import time from typing import Optional, Union from arknights_mower import __system__ - -from ... import config -from ...log import logger -from .session import Session -from .socket import Socket -from .utils import adb_buildin, run_cmd +from arknights_mower.utils import config +from arknights_mower.utils.csleep import csleep +from arknights_mower.utils.device.adb_client.session import Session +from arknights_mower.utils.device.adb_client.socket import Socket +from arknights_mower.utils.device.adb_client.utils import adb_buildin, run_cmd +from arknights_mower.utils.log import logger class Client(object): @@ -44,9 +42,7 @@ def __init_adb(self) -> None: def __init_device(self) -> None: # wait for the newly started ADB server to probe emulators - from arknights_mower.utils.solver import BaseSolver - - BaseSolver.csleep(1) + csleep(1) if self.device_id is None or self.device_id not in config.ADB_DEVICE: self.device_id = self.__choose_devices() if self.device_id is None: diff --git a/arknights_mower/utils/device/adb_client/session.py b/arknights_mower/utils/device/adb_client/session.py index bdcecf164..425ad61eb 100644 --- a/arknights_mower/utils/device/adb_client/session.py +++ b/arknights_mower/utils/device/adb_client/session.py @@ -4,9 +4,9 @@ import struct import time -from ... import config -from ...log import logger -from .socket import Socket +from arknights_mower.utils import config +from arknights_mower.utils.device.adb_client.socket import Socket +from arknights_mower.utils.log import logger class Session(object): diff --git a/arknights_mower/utils/device/adb_client/socket.py b/arknights_mower/utils/device/adb_client/socket.py index 0bb297935..dc5266e62 100644 --- a/arknights_mower/utils/device/adb_client/socket.py +++ b/arknights_mower/utils/device/adb_client/socket.py @@ -2,7 +2,7 @@ import socket -from ...log import logger +from arknights_mower.utils.log import logger class Socket(object): diff --git a/arknights_mower/utils/device/adb_client/utils.py b/arknights_mower/utils/device/adb_client/utils.py index 561058297..a24bfce05 100644 --- a/arknights_mower/utils/device/adb_client/utils.py +++ b/arknights_mower/utils/device/adb_client/utils.py @@ -1,13 +1,11 @@ -from __future__ import annotations - import shutil import subprocess from typing import Union -from .... import __system__ -from ... import config -from ...log import logger -from ..utils import download_file +from arknights_mower import __system__ +from arknights_mower.utils import config +from arknights_mower.utils.device.utils import download_file +from arknights_mower.utils.log import logger ADB_BUILDIN_URL = "https://oss.nano.ac/arknights_mower/adb-binaries" ADB_BUILDIN_FILELIST = { diff --git a/arknights_mower/utils/device/device.py b/arknights_mower/utils/device/device.py index c6c0c3944..41872e0b4 100644 --- a/arknights_mower/utils/device/device.py +++ b/arknights_mower/utils/device/device.py @@ -9,17 +9,16 @@ import numpy as np from arknights_mower import __rootdir__, __system__ +from arknights_mower.utils import config +from arknights_mower.utils.device.adb_client.core import Client as ADBClient from arknights_mower.utils.device.adb_client.session import Session +from arknights_mower.utils.device.maatouch import MaaTouch +from arknights_mower.utils.device.scrcpy import Scrcpy from arknights_mower.utils.image import bytes2img +from arknights_mower.utils.log import logger, save_screenshot from arknights_mower.utils.network import get_new_port, is_port_in_use from arknights_mower.utils.simulator import restart_simulator -from .. import config -from ..log import logger, save_screenshot -from .adb_client import ADBClient -from .maatouch import MaaTouch -from .scrcpy import Scrcpy - class Device(object): """Android Device""" diff --git a/arknights_mower/utils/device/maatouch/__init__.py b/arknights_mower/utils/device/maatouch/__init__.py index 36eadbf5b..246ec9d65 100644 --- a/arknights_mower/utils/device/maatouch/__init__.py +++ b/arknights_mower/utils/device/maatouch/__init__.py @@ -1,3 +1,3 @@ -from .core import Client as MaaTouch +from arknights_mower.utils.device.minitouch.core import Client as MaaTouch __all__ = ["MaaTouch"] diff --git a/arknights_mower/utils/device/maatouch/command.py b/arknights_mower/utils/device/maatouch/command.py index b6cb24954..48cd7273b 100644 --- a/arknights_mower/utils/device/maatouch/command.py +++ b/arknights_mower/utils/device/maatouch/command.py @@ -1,9 +1,7 @@ -from __future__ import annotations - import time -from ...log import logger -from .session import Session +from arknights_mower.utils.device.maatouch.session import Session +from arknights_mower.utils.log import logger DEFAULT_DELAY = 0.05 diff --git a/arknights_mower/utils/device/maatouch/core.py b/arknights_mower/utils/device/maatouch/core.py index eed907233..214dc0358 100644 --- a/arknights_mower/utils/device/maatouch/core.py +++ b/arknights_mower/utils/device/maatouch/core.py @@ -1,14 +1,11 @@ -from __future__ import annotations - from typing import Union from arknights_mower import __rootdir__ - -from ... import config -from ...log import logger -from ..adb_client import ADBClient -from .command import CommandBuilder -from .session import Session +from arknights_mower.utils import config +from arknights_mower.utils.device.adb_client.core import Client as ADBClient +from arknights_mower.utils.device.maatouch.command import CommandBuilder +from arknights_mower.utils.device.maatouch.session import Session +from arknights_mower.utils.log import logger MNT_PATH = "/data/local/tmp/maatouch" diff --git a/arknights_mower/utils/device/maatouch/session.py b/arknights_mower/utils/device/maatouch/session.py index 62a17357f..f4f2c87ac 100644 --- a/arknights_mower/utils/device/maatouch/session.py +++ b/arknights_mower/utils/device/maatouch/session.py @@ -3,9 +3,8 @@ import subprocess from arknights_mower import __system__ -from arknights_mower.utils.device.adb_client import ADBClient - -from ...log import logger +from arknights_mower.utils.device.adb_client.core import Client as ADBClient +from arknights_mower.utils.log import logger class Session(object): diff --git a/arknights_mower/utils/device/minitouch/__init__.py b/arknights_mower/utils/device/minitouch/__init__.py index 18bbe6c94..89fa85a3e 100644 --- a/arknights_mower/utils/device/minitouch/__init__.py +++ b/arknights_mower/utils/device/minitouch/__init__.py @@ -1,3 +1,3 @@ -from .core import Client as MiniTouch +from arknights_mower.utils.device.minitouch.core import Client as MiniTouch __all__ = ["MiniTouch"] diff --git a/arknights_mower/utils/device/minitouch/command.py b/arknights_mower/utils/device/minitouch/command.py index b6cb24954..eb21dedef 100644 --- a/arknights_mower/utils/device/minitouch/command.py +++ b/arknights_mower/utils/device/minitouch/command.py @@ -1,9 +1,7 @@ -from __future__ import annotations - import time -from ...log import logger -from .session import Session +from arknights_mower.utils.device.minitouch.session import Session +from arknights_mower.utils.log import logger DEFAULT_DELAY = 0.05 diff --git a/arknights_mower/utils/device/minitouch/core.py b/arknights_mower/utils/device/minitouch/core.py index 85937560f..b9a53d961 100644 --- a/arknights_mower/utils/device/minitouch/core.py +++ b/arknights_mower/utils/device/minitouch/core.py @@ -1,17 +1,15 @@ -from __future__ import annotations - import os import time # import random from typing import Union -from ... import config -from ...log import log_sync, logger -from ..adb_client import ADBClient -from ..utils import download_file -from .command import CommandBuilder -from .session import Session +from arknights_mower.utils import config +from arknights_mower.utils.device.adb_client.core import Client as ADBClient +from arknights_mower.utils.device.minitouch.command import CommandBuilder +from arknights_mower.utils.device.minitouch.session import Session +from arknights_mower.utils.device.utils import download_file +from arknights_mower.utils.log import log_sync, logger # MNT_PREBUILT_URL = 'https://github.com/williamfzc/stf-binaries/raw/master/node_modules/minitouch-prebuilt/prebuilt' MNT_PREBUILT_URL = "https://oss.nano.ac/arknights_mower/minitouch" diff --git a/arknights_mower/utils/device/minitouch/session.py b/arknights_mower/utils/device/minitouch/session.py index b2b06a729..5dec3db8d 100644 --- a/arknights_mower/utils/device/minitouch/session.py +++ b/arknights_mower/utils/device/minitouch/session.py @@ -2,7 +2,7 @@ import socket -from ...log import logger +from arknights_mower.utils.log import logger DEFAULT_HOST = "127.0.0.1" diff --git a/arknights_mower/utils/device/scrcpy/core.py b/arknights_mower/utils/device/scrcpy/core.py index 1b8c33a72..8c319fe5f 100644 --- a/arknights_mower/utils/device/scrcpy/core.py +++ b/arknights_mower/utils/device/scrcpy/core.py @@ -10,12 +10,12 @@ import numpy as np -from .... import __rootdir__ -from ...log import logger -from ..adb_client import ADBClient -from ..adb_client.socket import Socket -from . import const -from .control import ControlSender +from arknights_mower import __rootdir__ +from arknights_mower.utils.device.adb_client.core import Client as ADBClient +from arknights_mower.utils.device.adb_client.socket import Socket +from arknights_mower.utils.device.scrcpy import const +from arknights_mower.utils.device.scrcpy.control import ControlSender +from arknights_mower.utils.log import logger SCR_PATH = "/data/local/tmp/minitouch" diff --git a/arknights_mower/utils/device/utils.py b/arknights_mower/utils/device/utils.py index 880d2e020..a913d6740 100644 --- a/arknights_mower/utils/device/utils.py +++ b/arknights_mower/utils/device/utils.py @@ -1,5 +1,3 @@ -from __future__ import annotations - import tempfile import requests diff --git a/arknights_mower/utils/graph.py b/arknights_mower/utils/graph.py index 51cb037ca..59b185eb8 100644 --- a/arknights_mower/utils/graph.py +++ b/arknights_mower/utils/graph.py @@ -2,9 +2,10 @@ import networkx as nx +from arknights_mower.utils.csleep import MowerExit from arknights_mower.utils.log import logger from arknights_mower.utils.scene import Scene, SceneComment -from arknights_mower.utils.solver import BaseSolver, MowerExit +from arknights_mower.utils.solver import BaseSolver DG = nx.DiGraph() diff --git a/arknights_mower/utils/image.py b/arknights_mower/utils/image.py index e0cebf856..ba25d3239 100644 --- a/arknights_mower/utils/image.py +++ b/arknights_mower/utils/image.py @@ -5,11 +5,10 @@ import numpy as np from arknights_mower import __rootdir__ +from arknights_mower.utils import typealias as tp +from arknights_mower.utils.log import logger, save_screenshot from arknights_mower.utils.path import get_path -from . import typealias as tp -from .log import logger, save_screenshot - def bytes2img(data: bytes, gray: bool = False) -> Union[tp.Image, tp.GrayImage]: """bytes -> image""" diff --git a/arknights_mower/utils/log.py b/arknights_mower/utils/log.py index 654c076d8..c9ff0f036 100644 --- a/arknights_mower/utils/log.py +++ b/arknights_mower/utils/log.py @@ -9,7 +9,7 @@ import colorlog -from . import config +from arknights_mower.utils import config BASIC_FORMAT = ( "%(asctime)s - %(levelname)s - %(pathname)s:%(lineno)d - %(funcName)s - %(message)s" diff --git a/arknights_mower/utils/matcher.py b/arknights_mower/utils/matcher.py index 6fac14f98..70eb4ac04 100644 --- a/arknights_mower/utils/matcher.py +++ b/arknights_mower/utils/matcher.py @@ -1,5 +1,3 @@ -from __future__ import annotations - import lzma import pickle import traceback diff --git a/arknights_mower/utils/recognize.py b/arknights_mower/utils/recognize.py index b946d090e..52b506590 100644 --- a/arknights_mower/utils/recognize.py +++ b/arknights_mower/utils/recognize.py @@ -1,5 +1,3 @@ -from __future__ import annotations - import time from typing import List, Optional, Tuple @@ -7,17 +5,17 @@ import numpy as np from skimage.metrics import structural_similarity +from arknights_mower import __rootdir__ +from arknights_mower.utils import config +from arknights_mower.utils import typealias as tp +from arknights_mower.utils.csleep import MowerExit +from arknights_mower.utils.device.device import Device +from arknights_mower.utils.image import bytes2img, cmatch, cropimg, loadres, thres2 +from arknights_mower.utils.log import logger, save_screenshot +from arknights_mower.utils.matcher import Matcher +from arknights_mower.utils.scene import Scene, SceneComment from arknights_mower.utils.vector import va -from .. import __rootdir__ -from . import config -from . import typealias as tp -from .device import Device -from .image import bytes2img, cmatch, cropimg, loadres, thres2 -from .log import logger, save_screenshot -from .matcher import Matcher -from .scene import Scene, SceneComment - class RecognizeError(Exception): pass @@ -88,9 +86,7 @@ def start(self, screencap: bytes = None) -> None: raise RuntimeError("init Recognizer failed") def update(self) -> None: - from arknights_mower.utils.solver import MowerExit - - if config.stop_mower is not None and config.stop_mower.is_set(): + if config.stop_mower.is_set(): raise MowerExit self.clear() diff --git a/arknights_mower/utils/scheduler_task.py b/arknights_mower/utils/scheduler_task.py index 6c20aeffd..42ae0e8b0 100644 --- a/arknights_mower/utils/scheduler_task.py +++ b/arknights_mower/utils/scheduler_task.py @@ -4,8 +4,7 @@ from arknights_mower.utils import config from arknights_mower.utils.datetime import the_same_time - -from ..utils.log import logger +from arknights_mower.utils.log import logger class TaskTypes(Enum): diff --git a/arknights_mower/utils/segment.py b/arknights_mower/utils/segment.py index f0adbde18..f46c6ea37 100644 --- a/arknights_mower/utils/segment.py +++ b/arknights_mower/utils/segment.py @@ -1,5 +1,3 @@ -from __future__ import annotations - import traceback import cv2 diff --git a/arknights_mower/utils/simulator.py b/arknights_mower/utils/simulator.py index 60d76cd36..2ad1d95b6 100644 --- a/arknights_mower/utils/simulator.py +++ b/arknights_mower/utils/simulator.py @@ -4,6 +4,7 @@ from arknights_mower import __system__ from arknights_mower.utils import config +from arknights_mower.utils.csleep import MowerExit, csleep from arknights_mower.utils.log import logger @@ -18,53 +19,55 @@ class Simulator_Type(Enum): def restart_simulator(stop=True, start=True): - from arknights_mower.utils.solver import BaseSolver - data = config.conf["simulator"] index = data["index"] simulator_type = data["name"] cmd = "" - if simulator_type in [ - Simulator_Type.Nox.value, - Simulator_Type.MuMu12.value, - Simulator_Type.Leidian9.value, - Simulator_Type.Waydroid.value, - Simulator_Type.ReDroid.value, - Simulator_Type.MuMuPro.value, - Simulator_Type.Genymotion.value, - ]: - if simulator_type == Simulator_Type.Nox.value: - cmd = "Nox.exe" - if int(index) >= 0: - cmd += f' -clone:Nox_{data["index"]}' - cmd += " -quit" - elif simulator_type == Simulator_Type.MuMu12.value: - cmd = "MuMuManager.exe api -v " - if int(index) >= 0: - cmd += f'{data["index"]} ' - cmd += "shutdown_player" - elif simulator_type == Simulator_Type.Waydroid.value: - cmd = "waydroid session stop" - elif simulator_type == Simulator_Type.Leidian9.value: - cmd = "ldconsole.exe quit --index " - if int(index) >= 0: - cmd += f'{data["index"]} ' - else: - cmd += "0" - elif simulator_type == Simulator_Type.ReDroid.value: - cmd = f"docker stop {data['index']} -t 0" - elif simulator_type == Simulator_Type.MuMuPro.value: - cmd = f"Contents/MacOS/mumutool close {data['index']}" - elif simulator_type == Simulator_Type.Genymotion.value: - cmd = f"./gmtool admin stop {index}" - if stop: - exec_cmd(cmd, data["simulator_folder"]) - logger.info(f"关闭{simulator_type}模拟器") - if data["name"] == "MuMu12" and config.fix_mumu12_adb_disconnect: - system("taskkill /f /t /im adb.exe") - logger.info("结束adb进程") - BaseSolver.csleep(2) + if simulator_type not in Simulator_Type: + logger.warning(f"尚未支持{simulator_type}重启/自动启动") + csleep(10) + return + + if simulator_type == Simulator_Type.Nox.value: + cmd = "Nox.exe" + if int(index) >= 0: + cmd += f" -clone:Nox_{index}" + cmd += " -quit" + elif simulator_type == Simulator_Type.MuMu12.value: + cmd = "MuMuManager.exe api -v " + if int(index) >= 0: + cmd += f"{index} " + cmd += "shutdown_player" + elif simulator_type == Simulator_Type.Waydroid.value: + cmd = "waydroid session stop" + elif simulator_type == Simulator_Type.Leidian9.value: + cmd = "ldconsole.exe quit --index " + if int(index) >= 0: + cmd += f"{index} " + else: + cmd += "0" + elif simulator_type == Simulator_Type.ReDroid.value: + cmd = f"docker stop {index} -t 0" + elif simulator_type == Simulator_Type.MuMuPro.value: + cmd = f"Contents/MacOS/mumutool close {index}" + elif simulator_type == Simulator_Type.Genymotion.value: + if __system__ == "windows": + cmd = "gmtool.exe" + elif __system__ == "darwin": + cmd = "Contents/MacOS/gmtool" + else: + cmd = "./gmtool" + cmd += f' admin stop "{index}"' + + if stop: + logger.info(f"关闭{simulator_type}模拟器") + exec_cmd(cmd, data["simulator_folder"]) + if simulator_type == "MuMu12" and config.fix_mumu12_adb_disconnect: + logger.info("结束adb进程") + system("taskkill /f /t /im adb.exe") + + if start: if simulator_type == Simulator_Type.Nox.value: cmd = cmd.replace(" -quit", "") elif simulator_type == Simulator_Type.MuMu12.value: @@ -74,32 +77,34 @@ def restart_simulator(stop=True, start=True): elif simulator_type == Simulator_Type.Leidian9.value: cmd = cmd.replace("quit", "launch") elif simulator_type == Simulator_Type.ReDroid.value: - cmd = f"docker start {data['index']}" + cmd = f"docker start {index}" elif simulator_type == Simulator_Type.MuMuPro.value: cmd = cmd.replace("close", "open") elif simulator_type == Simulator_Type.Genymotion.value: - cmd = f"./gmtool admin start {index}" - if start: - exec_cmd(cmd, data["simulator_folder"]) - logger.info(f"开始启动{simulator_type}模拟器,等待{data['wait_time']}秒") - BaseSolver.csleep(data["wait_time"]) - else: - logger.warning(f"尚未支持{simulator_type}重启/自动启动") - BaseSolver.csleep() + cmd = cmd.replace("stop", "start", 1) + logger.info(f"启动{simulator_type}模拟器") + exec_cmd(cmd, data["simulator_folder"]) def exec_cmd(cmd, folder_path): - try: - logger.info(cmd) - process = subprocess.Popen( - cmd, - shell=True, - cwd=folder_path, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, - universal_newlines=True, - creationflags=subprocess.CREATE_NO_WINDOW if __system__ == "windows" else 0, - ) - logger.info(process.communicate(timeout=2)) - except subprocess.TimeoutExpired: - process.kill() + logger.debug(cmd) + + wait_time = config.conf["simulator"]["wait_time"] + process = subprocess.Popen( + cmd, + shell=True, + cwd=folder_path, + creationflags=subprocess.CREATE_NO_WINDOW if __system__ == "windows" else 0, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + universal_newlines=True, + ) + while wait_time > 0: + try: + csleep(0) + logger.debug(process.communicate(timeout=1)) + break + except MowerExit: + raise + except subprocess.TimeoutExpired: + wait_time -= 1 diff --git a/arknights_mower/utils/solver.py b/arknights_mower/utils/solver.py index b6763b1ba..a20ce1c79 100644 --- a/arknights_mower/utils/solver.py +++ b/arknights_mower/utils/solver.py @@ -1,5 +1,3 @@ -from __future__ import annotations - import random import smtplib import sys @@ -22,8 +20,10 @@ from arknights_mower.utils import config from arknights_mower.utils import typealias as tp -from arknights_mower.utils.device import Device, KeyCode +from arknights_mower.utils.csleep import MowerExit, csleep +from arknights_mower.utils.device.adb_client.const import KeyCode from arknights_mower.utils.device.adb_client.session import Session +from arknights_mower.utils.device.device import Device from arknights_mower.utils.device.scrcpy import Scrcpy from arknights_mower.utils.image import cropimg, thres2 from arknights_mower.utils.log import logger @@ -37,10 +37,6 @@ class StrategyError(Exception): pass -class MowerExit(Exception): - pass - - class BaseSolver: """Base class, provide basic operation""" @@ -148,24 +144,9 @@ def get_pos( x, y = poly return (int(x), int(y)) - @staticmethod - def csleep(interval: float = 1): - """check and sleep""" - stop_time = datetime.now() + timedelta(seconds=interval) - while True: - if config.stop_mower is not None and config.stop_mower.is_set(): - raise MowerExit - remaining = stop_time - datetime.now() - if remaining > timedelta(seconds=1): - time.sleep(1) - elif remaining > timedelta(): - time.sleep(remaining.total_seconds()) - else: - return - def sleep(self, interval: float = 1) -> None: """sleeping for a interval""" - self.csleep(interval) + csleep(interval) self.recog.update() def input(self, referent: str, input_area: tp.Scope, text: str = None) -> None: @@ -198,7 +179,7 @@ def tap( interval: float = 1, ) -> None: """tap""" - if config.stop_mower is not None and config.stop_mower.is_set(): + if config.stop_mower.is_set(): raise MowerExit pos = self.get_pos(poly, x_rate, y_rate) self.device.tap(pos) @@ -310,7 +291,7 @@ def swipe( interval: float = 1, ) -> None: """swipe""" - if config.stop_mower is not None and config.stop_mower.is_set(): + if config.stop_mower.is_set(): raise MowerExit end = (start[0] + movement[0], start[1] + movement[1]) self.device.swipe(start, end, duration=duration) @@ -325,12 +306,12 @@ def swipe_only( interval: float = 1, ) -> None: """swipe only, no rebuild and recapture""" - if config.stop_mower is not None and config.stop_mower.is_set(): + if config.stop_mower.is_set(): raise MowerExit end = (start[0] + movement[0], start[1] + movement[1]) self.device.swipe(start, end, duration=duration) if interval > 0: - self.csleep(interval) + csleep(interval) # def swipe_seq(self, points: list[tp.Coordinate], duration: int = 100, interval: float = 1, rebuild: bool = True) -> None: # """ swipe with point sequence """ @@ -355,7 +336,7 @@ def swipe_noinertia( interval: float = 0.2, ) -> None: """swipe with no inertia (movement should be vertical)""" - if config.stop_mower is not None and config.stop_mower.is_set(): + if config.stop_mower.is_set(): raise MowerExit points = [start] if movement[0] == 0: @@ -713,7 +694,7 @@ def waiting_solver(self): return True logger.warning("相同场景等待超时") self.device.exit() - self.csleep(3) + csleep(3) self.check_current_focus() return False @@ -790,7 +771,7 @@ def handle_email_error(self, email_config, msg): except Exception as e: logger.error("邮件发送失败") logger.exception(e) - self.csleep(delay) + csleep(delay) # Server酱异常处理 def handle_serverJang_error(self, url, data): @@ -805,11 +786,11 @@ def handle_serverJang_error(self, url, data): logger.error( f"Server酱通知发送失败,错误信息:{json_data.get('message')}" ) - self.csleep(delay) + csleep(delay) except Exception as e: logger.error("Server酱通知发送失败") logger.exception(e) - self.csleep(delay) + csleep(delay) # PushPlus异常处理 def handle_pushplus_error(self, data): @@ -824,11 +805,11 @@ def handle_pushplus_error(self, data): logger.error( f"PushPlus通知发送失败,错误信息:{json_data.get('msg')}" ) - self.csleep(delay) + csleep(delay) except Exception as e: logger.error("PushPlus通知发送失败") logger.exception(e) - self.csleep(delay) + csleep(delay) def send_message( self, @@ -978,14 +959,14 @@ def send_message_old( self.handle_email_error(*args) break except Exception: - self.csleep(1) + csleep(1) elif method == "serverJang": for _ in range(retry_times): try: self.handle_serverJang_error(*args) break except Exception: - self.csleep(1) + csleep(1) elif method == "pushplus": for _ in range(retry_times): @@ -993,4 +974,4 @@ def send_message_old( self.handle_pushplus_error(*args) break except Exception: - self.csleep(1) + csleep(1) diff --git a/requirements.txt b/requirements.txt index e70eb972f..e91d49750 100644 --- a/requirements.txt +++ b/requirements.txt @@ -36,7 +36,7 @@ mpmath==1.3.0 networkx==3.3 numpy==1.26.4 onnxruntime==1.17.3 -opencv-python==4.9.0.80 +opencv-python-headless==4.9.0.80 packaging==24.0 pandas==2.2.2 pillow==10.3.0 diff --git a/server.py b/server.py index 8bd2c60a3..9f61d70a6 100755 --- a/server.py +++ b/server.py @@ -8,7 +8,7 @@ import time from functools import wraps from queue import Queue -from threading import Event, Thread +from threading import Thread import pytz from flask import Flask, abort, request, send_from_directory @@ -33,7 +33,6 @@ plan = {} operators = {} -config.stop_mower = Event() config.log_queue = Queue() config.wh = None