'commit'
This commit is contained in:
@@ -151,7 +151,7 @@ def click_image_template(d, template_path, timeout=5.0, threshold=0.8):
|
|||||||
max_val, max_loc, r_w, r_h = best_match
|
max_val, max_loc, r_w, r_h = best_match
|
||||||
center_x = max_loc[0] + r_w // 2
|
center_x = max_loc[0] + r_w // 2
|
||||||
center_y = max_loc[1] + r_h // 2
|
center_y = max_loc[1] + r_h // 2
|
||||||
logger.info(f"Found template at ({center_x}, {center_y}) with confidence {max_val:.2f}")
|
logger.info(f"成功点击图片模板: {template_path}, 匹配度: {max_val:.2f}")
|
||||||
d.click(center_x, center_y)
|
d.click(center_x, center_y)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@@ -160,6 +160,38 @@ def click_image_template(d, template_path, timeout=5.0, threshold=0.8):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def setup_logger(name, log_file=None):
|
||||||
|
"""
|
||||||
|
配置日志,支持同时输出到控制台和文件
|
||||||
|
"""
|
||||||
|
if log_file is None:
|
||||||
|
log_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "Logs")
|
||||||
|
if not os.path.exists(log_dir):
|
||||||
|
os.makedirs(log_dir)
|
||||||
|
log_file = os.path.join(log_dir, f"{name}_{time.strftime('%Y%m%d')}.log")
|
||||||
|
|
||||||
|
logger = logging.getLogger(name)
|
||||||
|
logger.setLevel(logging.INFO)
|
||||||
|
|
||||||
|
# 如果已经有 handler,不再添加
|
||||||
|
if logger.handlers:
|
||||||
|
return logger
|
||||||
|
|
||||||
|
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
||||||
|
|
||||||
|
# 控制台 Handler
|
||||||
|
ch = logging.StreamHandler()
|
||||||
|
ch.setFormatter(formatter)
|
||||||
|
logger.addHandler(ch)
|
||||||
|
|
||||||
|
# 文件 Handler
|
||||||
|
fh = logging.FileHandler(log_file, encoding='utf-8')
|
||||||
|
fh.setFormatter(formatter)
|
||||||
|
logger.addHandler(fh)
|
||||||
|
|
||||||
|
return logger
|
||||||
|
|
||||||
|
|
||||||
def find_template_coords(img_path, template_path, threshold=0.8):
|
def find_template_coords(img_path, template_path, threshold=0.8):
|
||||||
"""
|
"""
|
||||||
在图片中查找模板并返回中心坐标
|
在图片中查找模板并返回中心坐标
|
||||||
|
|||||||
BIN
Apps/TelaiDian/Config/__pycache__/Setting.cpython-310.pyc
Normal file
BIN
Apps/TelaiDian/Config/__pycache__/Setting.cpython-310.pyc
Normal file
Binary file not shown.
BIN
Apps/TelaiDian/Config/__pycache__/__init__.cpython-310.pyc
Normal file
BIN
Apps/TelaiDian/Config/__pycache__/__init__.cpython-310.pyc
Normal file
Binary file not shown.
@@ -4,7 +4,7 @@ import logging
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
from Apps.TelaiDian.Kit import take_screenshot, get_image_content_md5, clean_station_name
|
from Apps.TelaiDian.Kit import take_screenshot, get_image_content_md5, clean_station_name, setup_logger
|
||||||
from Apps.TelaiDian.ReadImageKit import ReadImageKit
|
from Apps.TelaiDian.ReadImageKit import ReadImageKit
|
||||||
from Apps.TelaiDian.Service import TelaiDianService
|
from Apps.TelaiDian.Service import TelaiDianService
|
||||||
from Apps.TelaiDian.Config.Setting import (
|
from Apps.TelaiDian.Config.Setting import (
|
||||||
@@ -20,8 +20,8 @@ project_root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(_
|
|||||||
if project_root not in sys.path:
|
if project_root not in sys.path:
|
||||||
sys.path.append(project_root)
|
sys.path.append(project_root)
|
||||||
|
|
||||||
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
# 初始化日志
|
||||||
logger = logging.getLogger("TelaiDianCrawler")
|
logger = setup_logger("TelaiDianCrawler")
|
||||||
|
|
||||||
class TelaiDianCrawler(BaseCrawler):
|
class TelaiDianCrawler(BaseCrawler):
|
||||||
def __init__(self, service=None):
|
def __init__(self, service=None):
|
||||||
@@ -119,6 +119,20 @@ class TelaiDianCrawler(BaseCrawler):
|
|||||||
|
|
||||||
if os.path.exists(screenshot_path): os.remove(screenshot_path)
|
if os.path.exists(screenshot_path): os.remove(screenshot_path)
|
||||||
|
|
||||||
|
async def crawl_list(self):
|
||||||
|
"""
|
||||||
|
实现 BaseCrawler 的抽象方法
|
||||||
|
"""
|
||||||
|
d = u2.connect()
|
||||||
|
await self.crawl_list_logic(d)
|
||||||
|
|
||||||
|
async def crawl_detail(self, station_info):
|
||||||
|
"""
|
||||||
|
实现 BaseCrawler 的抽象方法
|
||||||
|
"""
|
||||||
|
# 逻辑已在 crawl_list_logic 中通过 crawl_detail_logic 调用
|
||||||
|
pass
|
||||||
|
|
||||||
async def main(service=None):
|
async def main(service=None):
|
||||||
crawler = TelaiDianCrawler(service=service)
|
crawler = TelaiDianCrawler(service=service)
|
||||||
await crawler.start()
|
await crawler.start()
|
||||||
|
|||||||
@@ -192,3 +192,34 @@ def clear_temp_dir(save_dir=None):
|
|||||||
os.remove(file_path)
|
os.remove(file_path)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Error deleting file {file_path}: {e}")
|
logger.error(f"Error deleting file {file_path}: {e}")
|
||||||
|
|
||||||
|
def setup_logger(name, log_file=None):
|
||||||
|
"""
|
||||||
|
配置日志,支持同时输出到控制台和文件
|
||||||
|
"""
|
||||||
|
if log_file is None:
|
||||||
|
log_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "Logs")
|
||||||
|
if not os.path.exists(log_dir):
|
||||||
|
os.makedirs(log_dir)
|
||||||
|
log_file = os.path.join(log_dir, f"{name}_{time.strftime('%Y%m%d')}.log")
|
||||||
|
|
||||||
|
logger = logging.getLogger(name)
|
||||||
|
logger.setLevel(logging.INFO)
|
||||||
|
|
||||||
|
# 如果已经有 handler,不再添加
|
||||||
|
if logger.handlers:
|
||||||
|
return logger
|
||||||
|
|
||||||
|
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
||||||
|
|
||||||
|
# 控制台 Handler
|
||||||
|
ch = logging.StreamHandler()
|
||||||
|
ch.setFormatter(formatter)
|
||||||
|
logger.addHandler(ch)
|
||||||
|
|
||||||
|
# 文件 Handler
|
||||||
|
fh = logging.FileHandler(log_file, encoding='utf-8')
|
||||||
|
fh.setFormatter(formatter)
|
||||||
|
logger.addHandler(fh)
|
||||||
|
|
||||||
|
return logger
|
||||||
|
|||||||
@@ -4,13 +4,10 @@ import logging
|
|||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
import uiautomator2 as u2
|
import uiautomator2 as u2
|
||||||
from Apps.TelaiDian.Kit import take_screenshot
|
from Apps.TelaiDian.Kit import take_screenshot, setup_logger
|
||||||
|
|
||||||
logging.basicConfig(
|
# 初始化日志
|
||||||
level=logging.INFO,
|
logger = setup_logger("OpenTelaiDian")
|
||||||
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
|
|
||||||
)
|
|
||||||
logger = logging.getLogger("OpenTelaiDian")
|
|
||||||
|
|
||||||
async def open_mini_program():
|
async def open_mini_program():
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -10,10 +10,11 @@ if project_root not in sys.path:
|
|||||||
sys.path.append(project_root)
|
sys.path.append(project_root)
|
||||||
|
|
||||||
from Util.VLMKit import VLMKit
|
from Util.VLMKit import VLMKit
|
||||||
from Apps.TelaiDian.Kit import draw_rectangles, detect_cards_cv
|
from Apps.TelaiDian.Kit import draw_rectangles, detect_cards_cv, setup_logger
|
||||||
from Apps.TelaiDian.Config.Setting import SAFE_EXCLUDE_RATIO, BOTTOM_SAFE_EXCLUDE_RATIO
|
from Apps.TelaiDian.Config.Setting import SAFE_EXCLUDE_RATIO, BOTTOM_SAFE_EXCLUDE_RATIO
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
# 初始化日志
|
||||||
|
logger = setup_logger("ReadImageKit")
|
||||||
|
|
||||||
class ReadImageKit:
|
class ReadImageKit:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|||||||
@@ -16,10 +16,10 @@ from Config.Config import DB_URL
|
|||||||
from Model.StationProfile import StationProfile
|
from Model.StationProfile import StationProfile
|
||||||
from Model.StationStatus import StationStatus
|
from Model.StationStatus import StationStatus
|
||||||
from Model.StationPriceSchedule import StationPriceSchedule
|
from Model.StationPriceSchedule import StationPriceSchedule
|
||||||
|
from Apps.TelaiDian.Kit import setup_logger
|
||||||
|
|
||||||
# 配置日志
|
# 初始化日志
|
||||||
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
logger = setup_logger("TelaiDianService")
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
class TelaiDianService:
|
class TelaiDianService:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|||||||
BIN
Apps/TelaiDian/__pycache__/Crawler.cpython-310.pyc
Normal file
BIN
Apps/TelaiDian/__pycache__/Crawler.cpython-310.pyc
Normal file
Binary file not shown.
BIN
Apps/TelaiDian/__pycache__/Kit.cpython-310.pyc
Normal file
BIN
Apps/TelaiDian/__pycache__/Kit.cpython-310.pyc
Normal file
Binary file not shown.
BIN
Apps/TelaiDian/__pycache__/Opener.cpython-310.pyc
Normal file
BIN
Apps/TelaiDian/__pycache__/Opener.cpython-310.pyc
Normal file
Binary file not shown.
BIN
Apps/TelaiDian/__pycache__/ReadImageKit.cpython-310.pyc
Normal file
BIN
Apps/TelaiDian/__pycache__/ReadImageKit.cpython-310.pyc
Normal file
Binary file not shown.
BIN
Apps/TelaiDian/__pycache__/Service.cpython-310.pyc
Normal file
BIN
Apps/TelaiDian/__pycache__/Service.cpython-310.pyc
Normal file
Binary file not shown.
BIN
Apps/TelaiDian/__pycache__/__init__.cpython-310.pyc
Normal file
BIN
Apps/TelaiDian/__pycache__/__init__.cpython-310.pyc
Normal file
Binary file not shown.
@@ -246,6 +246,37 @@ def detect_rabbit_ad_close(image_path, debug_dir=None):
|
|||||||
|
|
||||||
return [best[3], best[4]]
|
return [best[3], best[4]]
|
||||||
|
|
||||||
|
def setup_logger(name, log_file=None):
|
||||||
|
"""
|
||||||
|
配置日志,支持同时输出到控制台和文件
|
||||||
|
"""
|
||||||
|
if log_file is None:
|
||||||
|
log_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "Logs")
|
||||||
|
if not os.path.exists(log_dir):
|
||||||
|
os.makedirs(log_dir)
|
||||||
|
log_file = os.path.join(log_dir, f"{name}_{time.strftime('%Y%m%d')}.log")
|
||||||
|
|
||||||
|
logger = logging.getLogger(name)
|
||||||
|
logger.setLevel(logging.INFO)
|
||||||
|
|
||||||
|
# 如果已经有 handler,不再添加
|
||||||
|
if logger.handlers:
|
||||||
|
return logger
|
||||||
|
|
||||||
|
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
||||||
|
|
||||||
|
# 控制台 Handler
|
||||||
|
ch = logging.StreamHandler()
|
||||||
|
ch.setFormatter(formatter)
|
||||||
|
logger.addHandler(ch)
|
||||||
|
|
||||||
|
# 文件 Handler
|
||||||
|
fh = logging.FileHandler(log_file, encoding='utf-8')
|
||||||
|
fh.setFormatter(formatter)
|
||||||
|
logger.addHandler(fh)
|
||||||
|
|
||||||
|
return logger
|
||||||
|
|
||||||
|
|
||||||
def detect_black_agree_button(image_path, debug_dir=None):
|
def detect_black_agree_button(image_path, debug_dir=None):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -269,3 +269,34 @@ def draw_rectangles(image_path, points, output_path=None):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"绘制矩形框失败: {e}")
|
logger.error(f"绘制矩形框失败: {e}")
|
||||||
return image_path
|
return image_path
|
||||||
|
|
||||||
|
def setup_logger(name, log_file=None):
|
||||||
|
"""
|
||||||
|
配置日志,支持同时输出到控制台和文件
|
||||||
|
"""
|
||||||
|
if log_file is None:
|
||||||
|
log_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "Logs")
|
||||||
|
if not os.path.exists(log_dir):
|
||||||
|
os.makedirs(log_dir)
|
||||||
|
log_file = os.path.join(log_dir, f"{name}_{time.strftime('%Y%m%d')}.log")
|
||||||
|
|
||||||
|
logger = logging.getLogger(name)
|
||||||
|
logger.setLevel(logging.INFO)
|
||||||
|
|
||||||
|
# 如果已经有 handler,不再添加
|
||||||
|
if logger.handlers:
|
||||||
|
return logger
|
||||||
|
|
||||||
|
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
||||||
|
|
||||||
|
# 控制台 Handler
|
||||||
|
ch = logging.StreamHandler()
|
||||||
|
ch.setFormatter(formatter)
|
||||||
|
logger.addHandler(ch)
|
||||||
|
|
||||||
|
# 文件 Handler
|
||||||
|
fh = logging.FileHandler(log_file, encoding='utf-8')
|
||||||
|
fh.setFormatter(formatter)
|
||||||
|
logger.addHandler(fh)
|
||||||
|
|
||||||
|
return logger
|
||||||
|
|||||||
@@ -1,16 +1,16 @@
|
|||||||
# 黄海在公司内网开发时的配置信息
|
# 黄海在公司内网开发时的配置信息
|
||||||
# DORIS_HOST = "10.10.14.204"
|
DORIS_HOST = "10.10.14.204"
|
||||||
# DORIS_PORT = 9030
|
DORIS_PORT = 9030
|
||||||
# DORIS_FENODES = "10.10.14.204:8030"
|
DORIS_FENODES = "10.10.14.204:8030"
|
||||||
# REDIS_HOST = '10.10.14.14'
|
REDIS_HOST = '10.10.14.14'
|
||||||
# REDIS_PASSWORD = None # 如果没有密码则设为 None
|
REDIS_PASSWORD = None # 如果没有密码则设为 None
|
||||||
|
|
||||||
# 黄海在家开发时的配置信息
|
# 黄海在家开发时的配置信息
|
||||||
DORIS_HOST = "www.hzkjai.com"
|
# DORIS_HOST = "www.hzkjai.com"
|
||||||
DORIS_PORT = 27025
|
# DORIS_PORT = 27025
|
||||||
DORIS_FENODES = "www.hzkjai.com:27024"
|
# DORIS_FENODES = "www.hzkjai.com:27024"
|
||||||
REDIS_HOST = '127.0.0.1'
|
# REDIS_HOST = '127.0.0.1'
|
||||||
REDIS_PASSWORD = "DsideaL147258369"
|
# REDIS_PASSWORD = "DsideaL147258369"
|
||||||
|
|
||||||
# 视觉模型配置
|
# 视觉模型配置
|
||||||
VL_MODEL_NAME = "qwen3-vl-flash"
|
VL_MODEL_NAME = "qwen3-vl-flash"
|
||||||
|
|||||||
Binary file not shown.
@@ -14,16 +14,17 @@ logging.basicConfig(
|
|||||||
level=logging.INFO,
|
level=logging.INFO,
|
||||||
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
|
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
|
||||||
)
|
)
|
||||||
logger = logging.getLogger("T4_TelaiDian")
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from Apps.TelaiDian.Service import TelaiDianService
|
from Apps.TelaiDian.Service import TelaiDianService
|
||||||
from Apps.TelaiDian import Opener, Crawler, Kit
|
from Apps.TelaiDian import Opener, Crawler, Kit
|
||||||
|
# 初始化日志文件记录
|
||||||
|
logger = Kit.setup_logger("T4_TelaiDian")
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
logger.info("\n🛑 用户在初始化阶段手动停止了程序。")
|
logging.info("\n🛑 用户在初始化阶段手动停止了程序。")
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"❌ 初始化导入失败: {e}")
|
logging.error(f"❌ 初始化导入失败: {e}")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
async def run_process():
|
async def run_process():
|
||||||
|
|||||||
Reference in New Issue
Block a user