refactor: 优化代码格式,提升可读性
This commit is contained in:
1 parent
fb0c07c91a
commit
6ecd9fa1ae
6 files changed
+91
-27
No files matched your search
@@ -310,7 +310,9 @@ class fudai_analyse:
|
|||||||
self._just_switched_room: bool = False # 是否刚刚切换了直播间
|
self._just_switched_room: bool = False # 是否刚刚切换了直播间
|
||||||
|
|
||||||
# 高价值房间重访相关状态
|
# 高价值房间重访相关状态
|
||||||
self._last_high_value_revisit_ts: float = time.time() # 最后一次重访时间戳,初始化为当前时间避免启动后立即重访
|
self._last_high_value_revisit_ts: float = (
|
||||||
|
time.time()
|
||||||
|
) # 最后一次重访时间戳,初始化为当前时间避免启动后立即重访
|
||||||
self._current_run_revisit_count: int = 0 # 本次运行的重访次数
|
self._current_run_revisit_count: int = 0 # 本次运行的重访次数
|
||||||
self._current_run_high_value_rooms: list[dict[str, Any]] = (
|
self._current_run_high_value_rooms: list[dict[str, Any]] = (
|
||||||
[]
|
[]
|
||||||
@@ -1604,7 +1606,9 @@ class fudai_analyse:
|
|||||||
|
|
||||||
def _seek_reservation_room(item: dict) -> bool:
|
def _seek_reservation_room(item: dict) -> bool:
|
||||||
try:
|
try:
|
||||||
return bool(self._seek_reservation_room(item, operation_type="预约"))
|
return bool(
|
||||||
|
self._seek_reservation_room(item, operation_type="预约")
|
||||||
|
)
|
||||||
except Exception:
|
except Exception:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@@ -2046,8 +2050,12 @@ class fudai_analyse:
|
|||||||
analyser=self,
|
analyser=self,
|
||||||
revisit_enabled=revisit_enabled,
|
revisit_enabled=revisit_enabled,
|
||||||
only_current_run=only_current_run,
|
only_current_run=only_current_run,
|
||||||
min_interval_seconds=getattr(self, "high_value_room_revisit_min_interval_seconds", 300),
|
min_interval_seconds=getattr(
|
||||||
max_revisit_per_run=getattr(self, "high_value_room_revisit_max_per_run", 5),
|
self, "high_value_room_revisit_min_interval_seconds", 300
|
||||||
|
),
|
||||||
|
max_revisit_per_run=getattr(
|
||||||
|
self, "high_value_room_revisit_max_per_run", 5
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
if should_revisit:
|
if should_revisit:
|
||||||
@@ -2055,8 +2063,12 @@ class fudai_analyse:
|
|||||||
candidates = douyin_high_value_room.get_revisit_candidates(
|
candidates = douyin_high_value_room.get_revisit_candidates(
|
||||||
analyser=self,
|
analyser=self,
|
||||||
only_current_run=only_current_run,
|
only_current_run=only_current_run,
|
||||||
min_prize_value=getattr(self, "high_value_room_revisit_min_prize_value", 0.0),
|
min_prize_value=getattr(
|
||||||
max_age_days=getattr(self, "high_value_room_revisit_max_age_days", 30),
|
self, "high_value_room_revisit_min_prize_value", 0.0
|
||||||
|
),
|
||||||
|
max_age_days=getattr(
|
||||||
|
self, "high_value_room_revisit_max_age_days", 30
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
if candidates:
|
if candidates:
|
||||||
@@ -2522,7 +2534,9 @@ class fudai_analyse:
|
|||||||
"""
|
"""
|
||||||
return douyin_swipe_handler.SwipeHandler.maybe_reset_after_swipes(self)
|
return douyin_swipe_handler.SwipeHandler.maybe_reset_after_swipes(self)
|
||||||
|
|
||||||
def _seek_reservation_room(self, item: dict[str, Any], operation_type: str = "预约") -> bool:
|
def _seek_reservation_room(
|
||||||
|
self, item: dict[str, Any], operation_type: str = "预约"
|
||||||
|
) -> bool:
|
||||||
"""根据预约记录里的 pos_seen 与当前 room_pos 进行回退,靠近目标直播间。
|
"""根据预约记录里的 pos_seen 与当前 room_pos 进行回退,靠近目标直播间。
|
||||||
|
|
||||||
说明:
|
说明:
|
||||||
@@ -2842,7 +2856,9 @@ class fudai_analyse:
|
|||||||
# 注意:basic_join_decision 内部已经关闭详情并切换直播间,不需要再次关闭
|
# 注意:basic_join_decision 内部已经关闭详情并切换直播间,不需要再次关闭
|
||||||
try:
|
try:
|
||||||
douyin_fudai_core.basic_join_decision(
|
douyin_fudai_core.basic_join_decision(
|
||||||
self, detail, skip_result=(skip, skip_reason)
|
self,
|
||||||
|
detail,
|
||||||
|
skip_result=(skip, skip_reason),
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
try:
|
try:
|
||||||
@@ -3277,7 +3293,9 @@ class fudai_analyse:
|
|||||||
elapsed_seconds=round(elapsed, 2),
|
elapsed_seconds=round(elapsed, 2),
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
join_result = douyin_fudai_core.basic_join_decision(self, detail, skip_result=(False, "already_checked_in_step3"))
|
join_result = douyin_fudai_core.basic_join_decision(
|
||||||
|
self, detail, skip_result=(False, "already_checked_in_step3")
|
||||||
|
)
|
||||||
|
|
||||||
# 检查是否参与成功:如果 _last_successful_attend_ts 刚刚更新,说明参与成功
|
# 检查是否参与成功:如果 _last_successful_attend_ts 刚刚更新,说明参与成功
|
||||||
attend_after_ts = getattr(self, "_last_successful_attend_ts", 0.0) or 0.0
|
attend_after_ts = getattr(self, "_last_successful_attend_ts", 0.0) or 0.0
|
||||||
|
|||||||
@@ -362,7 +362,9 @@ def execute_room_revisit(analyser: Any, target_room: Dict[str, Any]) -> bool:
|
|||||||
target_pos=pos_seen,
|
target_pos=pos_seen,
|
||||||
)
|
)
|
||||||
|
|
||||||
success = analyser._seek_reservation_room(target_room, operation_type="高价值房间")
|
success = analyser._seek_reservation_room(
|
||||||
|
target_room, operation_type="高价值房间"
|
||||||
|
)
|
||||||
|
|
||||||
if success:
|
if success:
|
||||||
analyser._log_kv(
|
analyser._log_kv(
|
||||||
|
|||||||
@@ -304,7 +304,19 @@ def check_shopping_redpacket_popup(analyser) -> bool:
|
|||||||
pass
|
pass
|
||||||
return False
|
return False
|
||||||
|
|
||||||
keywords = ("邀你搶購物紅包", "搶購物紅包", "購物紅包", "邀你搶", "搶紅包", "搶", "最高領取", "邀你抢购物红包", "抢购物红包", "购物红包", "邀你抢")
|
keywords = (
|
||||||
|
"邀你搶購物紅包",
|
||||||
|
"搶購物紅包",
|
||||||
|
"購物紅包",
|
||||||
|
"邀你搶",
|
||||||
|
"搶紅包",
|
||||||
|
"搶",
|
||||||
|
"最高領取",
|
||||||
|
"邀你抢购物红包",
|
||||||
|
"抢购物红包",
|
||||||
|
"购物红包",
|
||||||
|
"邀你抢",
|
||||||
|
)
|
||||||
if any(kw in hay for kw in keywords):
|
if any(kw in hay for kw in keywords):
|
||||||
matched = [kw for kw in keywords if kw in hay]
|
matched = [kw for kw in keywords if kw in hay]
|
||||||
total_elapsed = time.time() - check_start
|
total_elapsed = time.time() - check_start
|
||||||
@@ -380,7 +392,16 @@ def check_shopping_redpacket_popup(analyser) -> bool:
|
|||||||
)
|
)
|
||||||
|
|
||||||
combined_text = " ".join(texts).strip()
|
combined_text = " ".join(texts).strip()
|
||||||
final_keywords = ("購物紅包", "邀你搶", "搶紅包", "购物红包", "邀你抢", "抢红包", "最高領取", "最高领取")
|
final_keywords = (
|
||||||
|
"購物紅包",
|
||||||
|
"邀你搶",
|
||||||
|
"搶紅包",
|
||||||
|
"购物红包",
|
||||||
|
"邀你抢",
|
||||||
|
"抢红包",
|
||||||
|
"最高領取",
|
||||||
|
"最高领取",
|
||||||
|
)
|
||||||
result = any(kw in combined_text for kw in final_keywords)
|
result = any(kw in combined_text for kw in final_keywords)
|
||||||
if not result and has_popup_pixel:
|
if not result and has_popup_pixel:
|
||||||
result = True
|
result = True
|
||||||
|
|||||||
@@ -302,9 +302,7 @@ class ReservationHandler:
|
|||||||
|
|
||||||
@staticmethod # type: ignore[misc]
|
@staticmethod # type: ignore[misc]
|
||||||
def seek_reservation_room(
|
def seek_reservation_room(
|
||||||
analyser: Any,
|
analyser: Any, item: Dict[str, Any], operation_type: str = "预约"
|
||||||
item: Dict[str, Any],
|
|
||||||
operation_type: str = "预约"
|
|
||||||
) -> bool:
|
) -> bool:
|
||||||
"""根据预约记录里的 pos_seen 与当前 room_pos 进行回退,靠近目标直播间。
|
"""根据预约记录里的 pos_seen 与当前 room_pos 进行回退,靠近目标直播间。
|
||||||
|
|
||||||
|
|||||||
+16
-4
@@ -985,13 +985,25 @@ class Runner:
|
|||||||
if params.high_value_room_revisit_only_current_run:
|
if params.high_value_room_revisit_only_current_run:
|
||||||
cmd.append("--high-value-room-revisit-only-current-run")
|
cmd.append("--high-value-room-revisit-only-current-run")
|
||||||
if params.high_value_room_revisit_min_interval_seconds != 300:
|
if params.high_value_room_revisit_min_interval_seconds != 300:
|
||||||
cmd += ["--high-value-room-revisit-min-interval-seconds", str(params.high_value_room_revisit_min_interval_seconds)]
|
cmd += [
|
||||||
|
"--high-value-room-revisit-min-interval-seconds",
|
||||||
|
str(params.high_value_room_revisit_min_interval_seconds),
|
||||||
|
]
|
||||||
if params.high_value_room_revisit_max_per_run != 5:
|
if params.high_value_room_revisit_max_per_run != 5:
|
||||||
cmd += ["--high-value-room-revisit-max-per-run", str(params.high_value_room_revisit_max_per_run)]
|
cmd += [
|
||||||
|
"--high-value-room-revisit-max-per-run",
|
||||||
|
str(params.high_value_room_revisit_max_per_run),
|
||||||
|
]
|
||||||
if params.high_value_room_revisit_min_prize_value > 0:
|
if params.high_value_room_revisit_min_prize_value > 0:
|
||||||
cmd += ["--high-value-room-revisit-min-prize-value", str(params.high_value_room_revisit_min_prize_value)]
|
cmd += [
|
||||||
|
"--high-value-room-revisit-min-prize-value",
|
||||||
|
str(params.high_value_room_revisit_min_prize_value),
|
||||||
|
]
|
||||||
if params.high_value_room_revisit_max_age_days != 30:
|
if params.high_value_room_revisit_max_age_days != 30:
|
||||||
cmd += ["--high-value-room-revisit-max-age-days", str(params.high_value_room_revisit_max_age_days)]
|
cmd += [
|
||||||
|
"--high-value-room-revisit-max-age-days",
|
||||||
|
str(params.high_value_room_revisit_max_age_days),
|
||||||
|
]
|
||||||
|
|
||||||
# 预约回退校验
|
# 预约回退校验
|
||||||
if params.reservation_back_verify_enabled:
|
if params.reservation_back_verify_enabled:
|
||||||
|
|||||||
@@ -12,7 +12,11 @@ sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|||||||
|
|
||||||
from douyin.detection.douyin_pixel import detect_redpacket_popup_background
|
from douyin.detection.douyin_pixel import detect_redpacket_popup_background
|
||||||
from douyin.other.douyin_popups import check_shopping_redpacket_popup
|
from douyin.other.douyin_popups import check_shopping_redpacket_popup
|
||||||
from douyin.fudai.core.coords import SHOPPING_REDPACKET_AREA, STAGE_RED_PACKET_OCR, DIAG_SHOPPING_REDPACKET
|
from douyin.fudai.core.coords import (
|
||||||
|
SHOPPING_REDPACKET_AREA,
|
||||||
|
STAGE_RED_PACKET_OCR,
|
||||||
|
DIAG_SHOPPING_REDPACKET,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_pixel_detection():
|
def test_pixel_detection():
|
||||||
@@ -23,7 +27,7 @@ def test_pixel_detection():
|
|||||||
|
|
||||||
# 创建测试图像:模拟购物红包(红色背景)
|
# 创建测试图像:模拟购物红包(红色背景)
|
||||||
width, height = 1080, 2400
|
width, height = 1080, 2400
|
||||||
test_img = Image.new('RGB', (width, height), color=(255, 255, 255))
|
test_img = Image.new("RGB", (width, height), color=(255, 255, 255))
|
||||||
pixels = test_img.load()
|
pixels = test_img.load()
|
||||||
|
|
||||||
# 在中央区域添加红色像素(模拟购物红包)
|
# 在中央区域添加红色像素(模拟购物红包)
|
||||||
@@ -91,9 +95,18 @@ def test_ocr_keywords():
|
|||||||
|
|
||||||
# 关键词列表(与douyin_popups.py中的保持一致)
|
# 关键词列表(与douyin_popups.py中的保持一致)
|
||||||
keywords = [
|
keywords = [
|
||||||
'邀你搶購物紅包', '搶購物紅包', '購物紅包', '邀你搶',
|
"邀你搶購物紅包",
|
||||||
'搶紅包', '搶', '最高領取',
|
"搶購物紅包",
|
||||||
'邀你抢', '购物红包', '抢红包', '抢', '最高领取'
|
"購物紅包",
|
||||||
|
"邀你搶",
|
||||||
|
"搶紅包",
|
||||||
|
"搶",
|
||||||
|
"最高領取",
|
||||||
|
"邀你抢",
|
||||||
|
"购物红包",
|
||||||
|
"抢红包",
|
||||||
|
"抢",
|
||||||
|
"最高领取",
|
||||||
]
|
]
|
||||||
|
|
||||||
print(f"定义的关键词数量: {len(keywords)}")
|
print(f"定义的关键词数量: {len(keywords)}")
|
||||||
@@ -117,7 +130,7 @@ def create_redpacket_test_image():
|
|||||||
print("=" * 60)
|
print("=" * 60)
|
||||||
|
|
||||||
# 创建1080x2400的图像
|
# 创建1080x2400的图像
|
||||||
img = Image.new('RGB', (1080, 2400), color=(255, 255, 255))
|
img = Image.new("RGB", (1080, 2400), color=(255, 255, 255))
|
||||||
pixels = img.load()
|
pixels = img.load()
|
||||||
|
|
||||||
# 在中央画一个红色矩形(模拟购物红包)
|
# 在中央画一个红色矩形(模拟购物红包)
|
||||||
@@ -127,7 +140,7 @@ def create_redpacket_test_image():
|
|||||||
pixels[x, y] = red_color
|
pixels[x, y] = red_color
|
||||||
|
|
||||||
# 保存图像
|
# 保存图像
|
||||||
test_img_path = os.path.join(os.path.dirname(__file__), 'test_redpacket.png')
|
test_img_path = os.path.join(os.path.dirname(__file__), "test_redpacket.png")
|
||||||
img.save(test_img_path)
|
img.save(test_img_path)
|
||||||
print(f"✓ 测试图像已保存: {test_img_path}")
|
print(f"✓ 测试图像已保存: {test_img_path}")
|
||||||
print()
|
print()
|
||||||
@@ -135,7 +148,7 @@ def create_redpacket_test_image():
|
|||||||
return test_img_path
|
return test_img_path
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == "__main__":
|
||||||
print("\n")
|
print("\n")
|
||||||
print("╔" + "=" * 58 + "╗")
|
print("╔" + "=" * 58 + "╗")
|
||||||
print("║" + " " * 58 + "║")
|
print("║" + " " * 58 + "║")
|
||||||
|
|||||||
Reference in new issue
Block a user