|
@@ -31,6 +31,10 @@ class MiniProgramConst:
|
|
|
# 更新root_source_id天数
|
|
|
ROOT_SOURCE_ID_UPDATE_DAYS = 3
|
|
|
|
|
|
+ # DEFAULT VIDEO ID
|
|
|
+ DEFAULT_VIDEO_ID = 1
|
|
|
+ ZERO_VIDEO_ID = 0
|
|
|
+
|
|
|
|
|
|
class RecycleMiniProgramDetailBase(MiniProgramConst):
|
|
|
|
|
@@ -40,8 +44,7 @@ class RecycleMiniProgramDetailBase(MiniProgramConst):
|
|
|
self.trace_id = trace_id
|
|
|
|
|
|
# 构造小程序信息对象
|
|
|
- @staticmethod
|
|
|
- async def create_mini_info(response: list[dict]) -> list[dict]:
|
|
|
+ def create_mini_info(self, response: list[dict]) -> list[dict]:
|
|
|
return [
|
|
|
{
|
|
|
"app_id": "wx89e7eb06478361d7",
|
|
@@ -49,7 +52,7 @@ class RecycleMiniProgramDetailBase(MiniProgramConst):
|
|
|
"image_url": "",
|
|
|
"nike_name": "票圈 l 3亿人喜欢的视频平台",
|
|
|
"root_source_id": item["root_source_id"],
|
|
|
- "video_id": item["video_id"],
|
|
|
+ "video_id": item["video_id"] if item["video_id"] else self.DEFAULT_VIDEO_ID,
|
|
|
"service_type": "0",
|
|
|
"title": "",
|
|
|
"type": "card",
|
|
@@ -189,27 +192,27 @@ class RecycleMiniProgramDetailTask(RecycleMiniProgramDetailBase):
|
|
|
root_source_id_detail = await self.fetch_root_source_id_from_db(
|
|
|
root_source_id_list
|
|
|
)
|
|
|
- mini_detail = await self.create_mini_info(root_source_id_detail)
|
|
|
-
|
|
|
- # no root_source_id_list in article
|
|
|
- try:
|
|
|
- article_detail = await get_article_detail(article_link=url)
|
|
|
- response_code = article_detail["code"]
|
|
|
- if response_code == self.ARTICLE_SUCCESS_CODE:
|
|
|
- mini_detail = article_detail["data"]["data"].get("mini_program", [])
|
|
|
-
|
|
|
- except Exception as e:
|
|
|
- await self.log_client.log(
|
|
|
- contents={
|
|
|
- "task": self.TASK_NAME,
|
|
|
- "trace_id": article["trace_id"],
|
|
|
- "message": "get article detail error",
|
|
|
- "data": {
|
|
|
- "error": str(e),
|
|
|
- "traceback": traceback.format_exc(),
|
|
|
- },
|
|
|
- }
|
|
|
- )
|
|
|
+ mini_detail = self.create_mini_info(root_source_id_detail)
|
|
|
+ else:
|
|
|
+ # no root_source_id_list in article
|
|
|
+ try:
|
|
|
+ article_detail = await get_article_detail(article_link=url)
|
|
|
+ response_code = article_detail["code"]
|
|
|
+ if response_code == self.ARTICLE_SUCCESS_CODE:
|
|
|
+ mini_detail = article_detail["data"]["data"].get("mini_program", [])
|
|
|
+
|
|
|
+ except Exception as e:
|
|
|
+ await self.log_client.log(
|
|
|
+ contents={
|
|
|
+ "task": self.TASK_NAME,
|
|
|
+ "trace_id": article["trace_id"],
|
|
|
+ "message": "get article detail error",
|
|
|
+ "data": {
|
|
|
+ "error": str(e),
|
|
|
+ "traceback": traceback.format_exc(),
|
|
|
+ },
|
|
|
+ }
|
|
|
+ )
|
|
|
|
|
|
# 将root_source_id信息插入mysql表格
|
|
|
if not mini_detail:
|
|
@@ -226,6 +229,10 @@ class RecycleMiniProgramDetailTask(RecycleMiniProgramDetailBase):
|
|
|
for video_index, mini_item in enumerate(mini_detail, start=1):
|
|
|
image_url = mini_item["image_url"]
|
|
|
nickname = mini_item["nike_name"]
|
|
|
+ # 将video_id为0的替换为1
|
|
|
+ if mini_item.get("video_id") == self.ZERO_VIDEO_ID:
|
|
|
+ mini_item["video_id"] = self.DEFAULT_VIDEO_ID
|
|
|
+
|
|
|
if mini_item.get("root_source_id") and mini_item.get("video_id"):
|
|
|
root_source_id, video_id = (
|
|
|
mini_item["root_source_id"],
|