修改acList数据的目录

This commit is contained in:
2025-10-29 16:54:18 +08:00
parent 0c78a025f4
commit 7de4fff7cf
5 changed files with 59 additions and 37 deletions

2
.idea/misc.xml generated
View File

@@ -3,5 +3,5 @@
<component name="Black"> <component name="Black">
<option name="sdkName" value="Python 3.12 (AI-IOS)" /> <option name="sdkName" value="Python 3.12 (AI-IOS)" />
</component> </component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.12" project-jdk-type="Python SDK" /> <component name="ProjectRootManager" version="2" project-jdk-name="IOSAI" project-jdk-type="Python SDK" />
</project> </project>

View File

@@ -422,7 +422,7 @@ def addTempAnchorData():
if not data: if not data:
return ResultData(code=400, message="请求数据为空").toJson() return ResultData(code=400, message="请求数据为空").toJson()
# 追加到 JSON 文件 # 追加到 JSON 文件
AiUtils.save_aclist_flat_append(data, "log/acList.json") AiUtils.save_aclist_flat_append(data, "data/acList.json")
return ResultData(data="ok").toJson() return ResultData(data="ok").toJson()
# 获取当前屏幕上的聊天信息 # 获取当前屏幕上的聊天信息
@@ -505,7 +505,7 @@ def upLoadLogLogs():
def queryAnchorList(): def queryAnchorList():
# 项目根目录(当前文件在 infos 下,回退两层到根目录) # 项目根目录(当前文件在 infos 下,回退两层到根目录)
root_dir = Path(__file__).resolve().parent.parent root_dir = Path(__file__).resolve().parent.parent
file_path = root_dir / "log" / "acList.json" file_path = root_dir / "data" / "acList.json"
data = [] data = []
if file_path.exists(): if file_path.exists():
@@ -532,7 +532,7 @@ def updateAnchorList():
new_status = 1 if state else 0 new_status = 1 if state else 0
# 用工具类解析路径,避免 cwd 影响 # 用工具类解析路径,避免 cwd 影响
file_path = AiUtils._resolve_path("log/acList.json") file_path = AiUtils._resolve_path("data/acList.json")
# 加载 JSON # 加载 JSON
try: try:

View File

@@ -1096,10 +1096,10 @@ class AiUtils(object):
# -------- 追加(对象数组平铺追加) -------- # -------- 追加(对象数组平铺追加) --------
@classmethod @classmethod
def save_aclist_flat_append(cls, acList, filename="log/acList.json"): def save_aclist_flat_append(cls, acList, filename="data/acList.json"):
""" """
将 anchor 对象数组平铺追加到 JSON 文件(数组)中。 将 anchor 对象数组平铺追加到 JSON 文件(数组)中。
文件固定写到 项目根目录/log/acList.json 文件固定写到 项目根目录/data/acList.json
""" """
# 找到当前文件所在目录,回退到项目根目录 # 找到当前文件所在目录,回退到项目根目录
@@ -1123,7 +1123,7 @@ class AiUtils(object):
LogManager.info(f"[acList] 已追加 {len(to_add)} 条,当前总数={len(data)} -> {file_path}") LogManager.info(f"[acList] 已追加 {len(to_add)} 条,当前总数={len(data)} -> {file_path}")
@classmethod @classmethod
def pop_aclist_first(cls, filename="log/acList.json", mode="pop"): def pop_aclist_first(cls, filename="data/acList.json", mode="pop"):
""" """
从 JSON 数组/对象(anchorList)中取出第一个 anchor 对象。 从 JSON 数组/对象(anchorList)中取出第一个 anchor 对象。
- mode="pop" : 取出并删除 - mode="pop" : 取出并删除
@@ -1131,6 +1131,8 @@ class AiUtils(object):
返回形如:{"anchorId": "...", "country": "...", ...} 返回形如:{"anchorId": "...", "country": "...", ...}
""" """
file_path = cls._resolve_path(filename) file_path = cls._resolve_path(filename)
if not file_path.exists(): if not file_path.exists():
return None return None
@@ -1169,7 +1171,7 @@ class AiUtils(object):
return first return first
@classmethod @classmethod
def bulk_update_anchors(cls, updates, filename="log/acList.json", case_insensitive=False): def bulk_update_anchors(cls, updates, filename="data/acList.json", case_insensitive=False):
""" """
批量修改(文件根必须是数组,沿用 _read_json_list 的约定) 批量修改(文件根必须是数组,沿用 _read_json_list 的约定)
- updates: - updates:
@@ -1257,7 +1259,7 @@ class AiUtils(object):
@classmethod @classmethod
def delete_anchors_by_ids(cls, ids: list[str], filename: str = "acList.json") -> int: def delete_anchors_by_ids(cls, ids: list[str], filename: str = "acList.json") -> int:
""" """
根据 anchorId 列表,从项目根目录/log/acList.json 中删除匹配的 anchor。 根据 anchorId 列表,从项目根目录/data/acList.json 中删除匹配的 anchor。
- ids: 要删除的 anchorId 列表 - ids: 要删除的 anchorId 列表
- filename: 默认为 acList.json可以传文件名或绝对路径 - filename: 默认为 acList.json可以传文件名或绝对路径
返回:删除数量 返回:删除数量
@@ -1267,7 +1269,7 @@ class AiUtils(object):
if Path(filename).is_absolute(): if Path(filename).is_absolute():
file_path = Path(filename) file_path = Path(filename)
else: else:
file_path = root_dir / "log" / filename file_path = root_dir / "data" / filename
if not file_path.exists(): if not file_path.exists():
return 0 return 0
@@ -1309,7 +1311,7 @@ class AiUtils(object):
return (base / p).resolve() return (base / p).resolve()
@classmethod @classmethod
def peek_aclist_first(cls, filename="log/acList.json"): def peek_aclist_first(cls, filename="data/acList.json"):
file_path = cls._resolve_path(filename) file_path = cls._resolve_path(filename)
if not file_path.exists(): if not file_path.exists():
print(f"[peek] 文件不存在: {file_path}") print(f"[peek] 文件不存在: {file_path}")

View File

@@ -200,10 +200,13 @@ class JsonUtils:
return updated return updated
@classmethod @classmethod
def query_all_json_items(cls, filename="log/last_message.json") -> list: def query_all_json_items(cls, filename="log/last_message.json") -> list:
""" """
查询 JSON 文件(数组)中的所有项,并剔除 sender 和 text 为空的记录 查询 JSON 文件(数组)中的所有项,并剔除 sender 为空的记录
:param filename: JSON 文件路径 :param filename: JSON 文件路径
:return: list可能为空 :return: list可能为空
""" """
@@ -212,8 +215,8 @@ class JsonUtils:
if not isinstance(data, list): if not isinstance(data, list):
return [] return []
# 过滤 sender 和 text 为空字符串的项 # 过滤 sender 和 text 为空字符串的项
return [item for item in data if return [item for item in data if isinstance(item, dict) and item.get("sender", "").strip() and item.get("text", "").strip()]
isinstance(item, dict) and item.get("sender", "").strip() and item.get("text", "").strip()]
@classmethod @classmethod

View File

@@ -61,7 +61,7 @@ class ScriptManager():
cx, cy = coord[0] # ✅ 注意这里取第一个点 cx, cy = coord[0] # ✅ 注意这里取第一个点
session.click(int(cx / 3), int(cy / 3)) session.click(int(cx / 3), int(cy / 3))
print(f"点击评论的坐标:{int(cx / 3)}, {int(cy / 3)}") LogManager.method_info(f"点击评论的坐标:{int(cx / 3)}, {int(cy / 3)}", "养号", udid)
time.sleep(2) time.sleep(2)
# 截图二判(防止键盘弹出后坐标变化) # 截图二判(防止键盘弹出后坐标变化)
@@ -79,17 +79,16 @@ class ScriptManager():
coord2 = OCRUtils.find_template(str(self.comment_add_dir), filePath) coord2 = OCRUtils.find_template(str(self.comment_add_dir), filePath)
if coord2: # 二判命中 if coord2: # 二判命中
print(f"方案1") LogManager.method_info(f"方案1", "养号", udid)
cx2, cy2 = coord2[0] cx2, cy2 = coord2[0]
print(f"添加评论:{cx2, cy2}")
session.tap(int(cx2 / 3), int(cy2 / 3)) session.tap(int(cx2 / 3), int(cy2 / 3))
print(f"点击添加评论的坐标:{int(cx2 / 3)}, {int(cy2 / 3)}") LogManager.method_info(f"点击添加评论的坐标:{int(cx2 / 3)}, {int(cy2 / 3)}", "养号", udid)
session.send_keys(f"{single_comment}\n") session.send_keys(f"{single_comment}\n")
time.sleep(2) time.sleep(2)
LogManager.method_info("评论成功", "养号", udid) LogManager.method_info("评论成功", "养号", udid)
else: else:
time.sleep(1) time.sleep(1)
print(f"方案2") LogManager.method_info(f"方案2", "养号", udid)
img = session.screenshot() img = session.screenshot()
filePath = os.path.join(os.path.dirname(filePath), "bgv_comment.png") filePath = os.path.join(os.path.dirname(filePath), "bgv_comment.png")
img.save(filePath) img.save(filePath)
@@ -110,7 +109,7 @@ class ScriptManager():
# 养号 # 养号
def growAccount(self, udid, isComment, event, is_monitoring=False): def growAccount(self, udid, isComment, event, is_monitoring=False):
print("调用刷视频") LogManager.method_info(f"调用刷视频", "养号", udid)
while not event.is_set(): while not event.is_set():
try: try:
@@ -131,6 +130,8 @@ class ScriptManager():
recomend_cy = 0 recomend_cy = 0
# ========= 主循环 ========= # ========= 主循环 =========
while not event.is_set(): while not event.is_set():
# 设置手机的节点深度为15,判断该页面是否正确 # 设置手机的节点深度为15,判断该页面是否正确
session.appium_settings({"snapshotMaxDepth": 15}) session.appium_settings({"snapshotMaxDepth": 15})
@@ -216,13 +217,7 @@ class ScriptManager():
# ControlUtils.swipe_up(udid) # ControlUtils.swipe_up(udid)
else: else:
LogManager.method_error("找不到首页按钮。出错了", "养号", udid) LogManager.method_error("找不到首页按钮。出错了", "养号", udid)
# else:
# nextTime = random.randint(1, 5)
# for _ in range(nextTime):
# if event.is_set():
# break
# event.wait(timeout=1)
# client.swipe_up()
if isComment and random.random() > 0.70: if isComment and random.random() > 0.70:
self.comment_flow(filePath, session, udid, recomend_cx, recomend_cy) self.comment_flow(filePath, session, udid, recomend_cx, recomend_cy)
@@ -414,6 +409,7 @@ class ScriptManager():
retries = 0 retries = 0
while not event.is_set(): while not event.is_set():
try: try:
self.greetNewFollowers(udid, needReply, isComment, event) self.greetNewFollowers(udid, needReply, isComment, event)
except Exception as e: except Exception as e:
@@ -424,6 +420,7 @@ class ScriptManager():
if event.is_set(): if event.is_set():
LogManager.method_info("外层 while 检测到停止,即将 break", "关注打招呼", udid) LogManager.method_info("外层 while 检测到停止,即将 break", "关注打招呼", udid)
break break
print("任务终止")
LogManager.method_error("greetNewFollowers 重试次数耗尽,任务终止", "关注打招呼", udid) LogManager.method_error("greetNewFollowers 重试次数耗尽,任务终止", "关注打招呼", udid)
# 关注打招呼 # 关注打招呼
@@ -465,9 +462,11 @@ class ScriptManager():
# 循环条件。1、 循环关闭 2、 数据处理完毕 # 循环条件。1、 循环关闭 2、 数据处理完毕
while not event.is_set(): while not event.is_set():
print(f"关注打招呼开始循环,设备是:{udid}")
LogManager.method_info("=== 外层 while 新一轮 ===", "关注打招呼", udid) LogManager.method_info("=== 外层 while 新一轮 ===", "关注打招呼", udid)
if event.is_set(): if event.is_set():
print("任务终止3")
break break
# 获取一个主播, # 获取一个主播,
@@ -523,6 +522,7 @@ class ScriptManager():
input.clear_text() input.clear_text()
event.wait(timeout=1) event.wait(timeout=1)
# 输入主播id # 输入主播id
LogManager.method_info(f"输入主播id:{aid or '暂无数据'}", "关注打招呼", udid)
input.set_text(f"{aid or '暂无数据'}\n") input.set_text(f"{aid or '暂无数据'}\n")
# 定位 "关注" 按钮 通过关注按钮的位置点击主播首页 # 定位 "关注" 按钮 通过关注按钮的位置点击主播首页
@@ -667,6 +667,7 @@ class ScriptManager():
# 准备打招呼的文案 # 准备打招呼的文案
text = random.choice(privateMessageList) text = random.choice(privateMessageList)
# text = "hello"
LogManager.method_info(f"取出打招呼的数据,{text}", "关注打招呼", LogManager.method_info(f"取出打招呼的数据,{text}", "关注打招呼",
udid) udid)
@@ -684,6 +685,8 @@ class ScriptManager():
chatInput = session.xpath("//TextView") chatInput = session.xpath("//TextView")
if chatInput.exists: if chatInput.exists:
chatInput.click() chatInput.click()
LogManager.method_info(f"即将发送的私信内容:{msg or '暂无数据'}", "关注打招呼", udid)
chatInput.set_text(f"{msg or '暂无数据'}\n") chatInput.set_text(f"{msg or '暂无数据'}\n")
event.wait(timeout=2) event.wait(timeout=2)
# 发送消息 # 发送消息
@@ -733,11 +736,14 @@ class ScriptManager():
print("即将要回复消息") print("即将要回复消息")
LogManager.method_info("即将要回复消息", "关注打招呼", udid) LogManager.method_info("即将要回复消息", "关注打招呼", udid)
LogManager.method_info(f"是否需要进行监控消息:{needReply}", "监控消息")
if needReply: if needReply:
print("如果需要回复主播消息。走此逻辑") print("如果需要回复主播消息。走此逻辑")
print("----------------------------------------------------------") print("----------------------------------------------------------")
print("监控回复消息") LogManager.method_info(f"进入准备监控消息方法", "监控消息")
# 执行回复消息逻辑 # 执行回复消息逻辑
self.monitorMessages(session, udid, event) self.monitorMessages(session, udid, event)
@@ -757,6 +763,7 @@ class ScriptManager():
session.appium_settings({"snapshotMaxDepth": 15}) session.appium_settings({"snapshotMaxDepth": 15})
else: else:
session.appium_settings({"snapshotMaxDepth": 15}) session.appium_settings({"snapshotMaxDepth": 15})
print("任务终止2")
print("greetNewFollowers方法执行完毕") print("greetNewFollowers方法执行完毕")
@@ -875,6 +882,8 @@ class ScriptManager():
input.clear_text() input.clear_text()
event.wait(timeout=1) event.wait(timeout=1)
# 输入主播id # 输入主播id
LogManager.method_info(f"搜索主播名称:{aid or '暂无数据'}", "关注打招呼(联盟号)", udid)
input.set_text(f"{aid or '暂无数据'}\n") input.set_text(f"{aid or '暂无数据'}\n")
# 定位 "关注" 按钮 通过关注按钮的位置点击主播首页 # 定位 "关注" 按钮 通过关注按钮的位置点击主播首页
@@ -942,8 +951,9 @@ class ScriptManager():
# 准备打招呼的文案 # 准备打招呼的文案
text = random.choice(privateMessageList) text = random.choice(privateMessageList)
# text = "hello"
# sweetm_0
if needTranslate: if needTranslate:
# 翻译成主播国家的语言 # 翻译成主播国家的语言
LogManager.method_info(f"需要翻译:{text},参数为:国家为{anchorCountry}, 即将进行翻译", LogManager.method_info(f"需要翻译:{text},参数为:国家为{anchorCountry}, 即将进行翻译",
@@ -961,6 +971,8 @@ class ScriptManager():
chatInput = session.xpath("//TextView") chatInput = session.xpath("//TextView")
if chatInput.exists: if chatInput.exists:
chatInput.click() chatInput.click()
LogManager.method_info(f"即将发送的私信内容:{msg or '暂无数据'}", "关注打招呼(联盟号)", udid)
chatInput.set_text(f"{msg or '暂无数据'}\n") chatInput.set_text(f"{msg or '暂无数据'}\n")
event.wait(timeout=2) event.wait(timeout=2)
# 发送消息 # 发送消息
@@ -1008,6 +1020,7 @@ class ScriptManager():
print("----------------------------------------------------------") print("----------------------------------------------------------")
print("监控回复消息") print("监控回复消息")
# 执行回复消息逻辑 # 执行回复消息逻辑
self.monitorMessages(session, udid, event) self.monitorMessages(session, udid, event)
@@ -1314,6 +1327,10 @@ class ScriptManager():
sel.click() # 聚焦 sel.click() # 聚焦
event.wait(timeout=1) event.wait(timeout=1)
sel.clear_text() sel.clear_text()
LogManager.method_info(f"发送的消息检测不到对方发送的消息不走ai{text or '暂无数据'}", "检测消息",
udid)
sel.set_text(f"{text or '暂无数据'}\n") sel.set_text(f"{text or '暂无数据'}\n")
else: else:
LogManager.method_error("找不到输入框,重启", "检测消息", udid) LogManager.method_error("找不到输入框,重启", "检测消息", udid)
@@ -1328,6 +1345,8 @@ class ScriptManager():
sel.click() # 聚焦 sel.click() # 聚焦
event.wait(timeout=1) event.wait(timeout=1)
sel.clear_text() sel.clear_text()
LogManager.method_info(f"发送的消息检测到对方发送的消息进行走ai没记忆{aiResult or '暂无数据'}", "检测消息",
udid)
sel.set_text(f"{aiResult or '暂无数据'}\n") sel.set_text(f"{aiResult or '暂无数据'}\n")
else: else:
LogManager.method_error("找不到输入框,重启", "检测消息", udid) LogManager.method_error("找不到输入框,重启", "检测消息", udid)
@@ -1348,6 +1367,10 @@ class ScriptManager():
sel.click() # 聚焦 sel.click() # 聚焦
event.wait(timeout=1) event.wait(timeout=1)
sel.clear_text() sel.clear_text()
LogManager.method_info(
f"发送的消息检测到对方发送的消息进行走ai有记忆{aiResult or '暂无数据'}",
"检测消息",
udid)
sel.set_text(f"{aiResult or '暂无数据'}\n") sel.set_text(f"{aiResult or '暂无数据'}\n")
LogManager.method_info(f"存储的sessionId:{anchorWithSession}", "检测消息", udid) LogManager.method_info(f"存储的sessionId:{anchorWithSession}", "检测消息", udid)
@@ -1444,14 +1467,6 @@ class ScriptManager():
else: else:
# print("回到首页刷视频")
# # ControlUtils.backToHome(session)
# homeButton = AiUtils.findHomeButton(udid)
# if homeButton.exists:
# homeButton.click() # 当前的消息为0则调用刷视频的方法
# # 调用刷视频的方法
# self.growAccount(udid, event, True)
return return
else: else:
LogManager.method_error(f"检测不到收件箱", "检测消息", udid) LogManager.method_error(f"检测不到收件箱", "检测消息", udid)
@@ -1635,7 +1650,9 @@ class ScriptManager():
LogManager.method_info(f"点击坐标: ({tap_x}, {tap_y}),账号: {target_account}", "切换账号", udid) LogManager.method_info(f"点击坐标: ({tap_x}, {tap_y}),账号: {target_account}", "切换账号", udid)
session.tap(tap_x, tap_y) session.tap(tap_x, tap_y)
time.sleep(5) time.sleep(5)
return 200, "成功" return 200, "成功"
except Exception as e: except Exception as e: