|
@@ -5,8 +5,8 @@ import traceback
|
|
|
from tqdm import tqdm
|
|
from tqdm import tqdm
|
|
|
from urllib.parse import parse_qs, urlparse
|
|
from urllib.parse import parse_qs, urlparse
|
|
|
|
|
|
|
|
-from app.infra.crawler.wechat import get_article_list_from_account
|
|
|
|
|
from app.infra.crawler.wechat import get_article_detail
|
|
from app.infra.crawler.wechat import get_article_detail
|
|
|
|
|
+from app.infra.crawler.wechat import get_article_list_from_account
|
|
|
|
|
|
|
|
from app.core.config import GlobalConfigSettings
|
|
from app.core.config import GlobalConfigSettings
|
|
|
from app.core.database import DatabaseManager
|
|
from app.core.database import DatabaseManager
|
|
@@ -28,7 +28,7 @@ class AutoReplyCardsMonitor(AutoReplyCardsMonitorConst):
|
|
|
pool=pool, log_service=log_service
|
|
pool=pool, log_service=log_service
|
|
|
)
|
|
)
|
|
|
self.tool: AutoReplyCardsMonitorUtils = AutoReplyCardsMonitorUtils(
|
|
self.tool: AutoReplyCardsMonitorUtils = AutoReplyCardsMonitorUtils(
|
|
|
- oss_config=config.aliyun_oss
|
|
|
|
|
|
|
+ config=config
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
# 存储卡片信息
|
|
# 存储卡片信息
|
|
@@ -37,11 +37,43 @@ class AutoReplyCardsMonitor(AutoReplyCardsMonitorConst):
|
|
|
cover_obj = await self.tool.get_cover_url(
|
|
cover_obj = await self.tool.get_cover_url(
|
|
|
xml_obj["aes_key"], xml_obj["file_size"], xml_obj["file_id"]
|
|
xml_obj["aes_key"], xml_obj["file_size"], xml_obj["file_id"]
|
|
|
)
|
|
)
|
|
|
- cover_oss = self.tool.download_and_upload_cover(task_id, index, cover_obj)
|
|
|
|
|
|
|
+ file_name = f"{task_id}_{index}.jpg"
|
|
|
|
|
+ save_path = self.tool.download_cover(file_name, cover_obj)
|
|
|
|
|
+ if save_path is None:
|
|
|
|
|
+ return
|
|
|
|
|
+ exist_covers = await self.mapper.fetch_exist_covers(root_source_id)
|
|
|
|
|
+ if exist_covers:
|
|
|
|
|
+ exist_cover_id = self.tool.check_cover(save_path, exist_covers)
|
|
|
|
|
+ if exist_cover_id is not False:
|
|
|
|
|
+ cover_id = exist_cover_id
|
|
|
|
|
+ self.tool.remove_local_cover(save_path)
|
|
|
|
|
+ else:
|
|
|
|
|
+ # upload to oss
|
|
|
|
|
+ oss_key, cover_id = self.tool.upload_cover(file_name, save_path)
|
|
|
|
|
+ if oss_key is not None:
|
|
|
|
|
+ await self.mapper.save_cover(
|
|
|
|
|
+ cover_id=cover_id,
|
|
|
|
|
+ root_source_id=root_source_id,
|
|
|
|
|
+ oss_path=oss_key,
|
|
|
|
|
+ )
|
|
|
|
|
+ else:
|
|
|
|
|
+ self.tool.remove_local_cover(save_path)
|
|
|
|
|
+ return
|
|
|
|
|
+ else:
|
|
|
|
|
+ # upload to oss
|
|
|
|
|
+ oss_key, cover_id = self.tool.upload_cover(file_name, save_path)
|
|
|
|
|
+ if oss_key is not None:
|
|
|
|
|
+ await self.mapper.save_cover(
|
|
|
|
|
+ cover_id=cover_id, root_source_id=root_source_id, oss_path=oss_key
|
|
|
|
|
+ )
|
|
|
|
|
+ else:
|
|
|
|
|
+ self.tool.remove_local_cover(save_path)
|
|
|
|
|
+ return
|
|
|
|
|
+
|
|
|
query = """
|
|
query = """
|
|
|
INSERT INTO cooperate_auto_reply_detail
|
|
INSERT INTO cooperate_auto_reply_detail
|
|
|
(
|
|
(
|
|
|
- task_id, position, msg_type, card_title, card_cover,
|
|
|
|
|
|
|
+ task_id, position, msg_type, card_title, card_cover_id,
|
|
|
video_id, root_source_id, mini_program_name, task_result
|
|
video_id, root_source_id, mini_program_name, task_result
|
|
|
) VALUES
|
|
) VALUES
|
|
|
(
|
|
(
|
|
@@ -54,7 +86,7 @@ class AutoReplyCardsMonitor(AutoReplyCardsMonitorConst):
|
|
|
index,
|
|
index,
|
|
|
msg_type,
|
|
msg_type,
|
|
|
xml_obj["title"],
|
|
xml_obj["title"],
|
|
|
- cover_oss,
|
|
|
|
|
|
|
+ cover_id,
|
|
|
video_id,
|
|
video_id,
|
|
|
root_source_id,
|
|
root_source_id,
|
|
|
xml_obj["mini_program"],
|
|
xml_obj["mini_program"],
|
|
@@ -103,16 +135,15 @@ class AutoReplyCardsMonitor(AutoReplyCardsMonitorConst):
|
|
|
|
|
|
|
|
else:
|
|
else:
|
|
|
article_detail = fetch_response["data"]["data"]
|
|
article_detail = fetch_response["data"]["data"]
|
|
|
- article_text = article_detail["body_text"]
|
|
|
|
|
- article_images = article_detail["image_url_list"]
|
|
|
|
|
- read_cnt = article_detail["view_count"]
|
|
|
|
|
- like_cnt = article_detail["like_count"]
|
|
|
|
|
- publish_timestamp = int(article_detail["publish_timestamp"] / 1000)
|
|
|
|
|
|
|
+ article_text = article_detail.get("body_text", "")
|
|
|
|
|
+ article_images = article_detail.get("image_url_list", [])
|
|
|
|
|
+ read_cnt = article_detail.get("view_count") or 0
|
|
|
|
|
+ like_cnt = article_detail.get("like_count") or 0
|
|
|
|
|
+ pt = article_detail.get("publish_timestamp")
|
|
|
|
|
+ publish_timestamp = int(pt / 1000) if pt is not None else 0
|
|
|
parsed = urlparse(article_detail["content_link"])
|
|
parsed = urlparse(article_detail["content_link"])
|
|
|
params = parse_qs(parsed.query)
|
|
params = parse_qs(parsed.query)
|
|
|
wx_sn = params.get("sn", [None])[0]
|
|
wx_sn = params.get("sn", [None])[0]
|
|
|
- print(params)
|
|
|
|
|
- print(wx_sn)
|
|
|
|
|
mini_info = article_detail.get("mini_program")
|
|
mini_info = article_detail.get("mini_program")
|
|
|
if not mini_info:
|
|
if not mini_info:
|
|
|
# video_id, root_source_id = None, None
|
|
# video_id, root_source_id = None, None
|
|
@@ -150,7 +181,9 @@ class AutoReplyCardsMonitor(AutoReplyCardsMonitorConst):
|
|
|
else:
|
|
else:
|
|
|
for card_index, i in enumerate(mini_info, 1):
|
|
for card_index, i in enumerate(mini_info, 1):
|
|
|
try:
|
|
try:
|
|
|
- video_id, root_source_id = self.tool.extract_page_path(i["path"])
|
|
|
|
|
|
|
+ video_id, root_source_id = self.tool.extract_page_path(
|
|
|
|
|
+ i["path"]
|
|
|
|
|
+ )
|
|
|
card_title = i["title"]
|
|
card_title = i["title"]
|
|
|
card_cover = i["image_url"]
|
|
card_cover = i["image_url"]
|
|
|
mini_name = i["nike_name"]
|
|
mini_name = i["nike_name"]
|
|
@@ -208,7 +241,9 @@ class AutoReplyCardsMonitor(AutoReplyCardsMonitorConst):
|
|
|
if article_url:
|
|
if article_url:
|
|
|
await self.mapper.set_sample_url(gh_id, article_url)
|
|
await self.mapper.set_sample_url(gh_id, article_url)
|
|
|
|
|
|
|
|
- task_id = self.tool.generate_task_id(task_name="follow", gh_id=gh_id)
|
|
|
|
|
|
|
+ task_id = self.tool.generate_task_id(
|
|
|
|
|
+ task_name="follow", gh_id=gh_id
|
|
|
|
|
+ )
|
|
|
affected_rows = await self.mapper.insert_aigc_follow_account_task(
|
|
affected_rows = await self.mapper.insert_aigc_follow_account_task(
|
|
|
task_id, article_url
|
|
task_id, article_url
|
|
|
)
|
|
)
|
|
@@ -231,7 +266,9 @@ class AutoReplyCardsMonitor(AutoReplyCardsMonitorConst):
|
|
|
# 先插入 task, 再创建自动回复任务
|
|
# 先插入 task, 再创建自动回复任务
|
|
|
create_row = await self.mapper.create_auto_reply_task(task_id, gh_id)
|
|
create_row = await self.mapper.create_auto_reply_task(task_id, gh_id)
|
|
|
if create_row:
|
|
if create_row:
|
|
|
- affected_rows = await self.mapper.insert_aigc_auto_reply_task(task_id, gh_id)
|
|
|
|
|
|
|
+ affected_rows = await self.mapper.insert_aigc_auto_reply_task(
|
|
|
|
|
+ task_id, gh_id
|
|
|
|
|
+ )
|
|
|
if not affected_rows:
|
|
if not affected_rows:
|
|
|
print("发布任务至 AIGC 失败")
|
|
print("发布任务至 AIGC 失败")
|
|
|
else:
|
|
else:
|
|
@@ -245,7 +282,9 @@ class AutoReplyCardsMonitor(AutoReplyCardsMonitorConst):
|
|
|
account_list = self.tool.get_monitor_account_list()
|
|
account_list = self.tool.get_monitor_account_list()
|
|
|
for account in account_list:
|
|
for account in account_list:
|
|
|
try:
|
|
try:
|
|
|
- fetch_response = await self.mapper.fetch_account_status(account.公众号名)
|
|
|
|
|
|
|
+ fetch_response = await self.mapper.fetch_account_status(
|
|
|
|
|
+ account.公众号名
|
|
|
|
|
+ )
|
|
|
if not fetch_response:
|
|
if not fetch_response:
|
|
|
affected_rows = await self.mapper.fetch_cooperate_accounts(
|
|
affected_rows = await self.mapper.fetch_cooperate_accounts(
|
|
|
account.公众号名
|
|
account.公众号名
|
|
@@ -323,7 +362,7 @@ class AutoReplyCardsMonitor(AutoReplyCardsMonitorConst):
|
|
|
|
|
|
|
|
try:
|
|
try:
|
|
|
# parse xml
|
|
# parse xml
|
|
|
- xml_list = json.loads(result) if type(result) == str else result
|
|
|
|
|
|
|
+ xml_list = json.loads(result) if isinstance(result, str) else result
|
|
|
index = 0
|
|
index = 0
|
|
|
for item in xml_list:
|
|
for item in xml_list:
|
|
|
xml_obj_list = self.tool.extract_callback_xml(item)
|
|
xml_obj_list = self.tool.extract_callback_xml(item)
|