Files
auto_control/tasks/douyin/actions/base.py
T

52 lines
1.8 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""抖音操作基类与注册机制。
操作 = 抖音养号主循环里某个时机执行的一次具体行为(点赞/评论/关注等)。
这里的注册表只对抖音任务生效,其他任务有自己的 actions 包。
设计:抖音的 ACTIONS 注册表是独立的 dict,用 core.actions 的
register_action(ACTIONS) 装饰器注册,和全局/其他 app 互不污染。
新增抖音操作步骤(照着 like.py 抄):
1. 在 tasks/douyin/actions/ 下新建 my_action.py
2. 写一个 BaseAction 子类,用 @register_action 装饰,实现 execute:
from core.actions import BaseAction, register_action, should_trigger
from . import ACTIONS # 本任务注册表
@register_action(ACTIONS)
class MyAction(BaseAction):
action_type = "my_action"
name = "我的操作"
description = "做什么"
default_params = {"rate": 0.5}
def execute(self, d, params, worker):
if not should_trigger(params["rate"]):
return False
# ... 用 d(xpath=...) / d(text=...) 操作
return True
3. 在 tasks/douyin/actions/__init__.py 加一行:from . import my_action
做完前端自动出现该操作的可勾选项。
"""
from core.actions import (
BaseAction, register_action, create_action_registry,
list_actions, get_action, should_trigger,
)
# 抖音专属操作注册表(独立 dict,不污染其他 app)
ACTIONS = create_action_registry()
# 兼容旧导入:tasks/douyin/actions/__init__.py 原来从这里导出
def list_action_types():
"""返回所有已注册抖音操作的元信息(供前端展示)。"""
return list_actions(ACTIONS)
def get_action_class(action_type):
"""按 action_type 取抖音操作类。"""
return get_action(ACTIONS, action_type)