|
@@ -10,7 +10,6 @@ from applications.functions.mq import MQ
|
|
|
from applications.functions.log import logging
|
|
|
from applications.static.config import gh_id_dict
|
|
|
from applications.functions.item import VideoItem
|
|
|
-from applications.functions.common import Functions
|
|
|
|
|
|
|
|
|
def wx_search(keys):
|
|
@@ -32,11 +31,10 @@ def wx_search(keys):
|
|
|
return response.json()
|
|
|
|
|
|
|
|
|
-def process_weixin_video_obj(video_obj, user, trace_id, title):
|
|
|
+def process_weixin_video_obj(video_obj, user, trace_id):
|
|
|
"""
|
|
|
异步处理微信 video_obj
|
|
|
公众号和站内账号一一对应
|
|
|
- :param title:
|
|
|
:param trace_id:
|
|
|
:param user:
|
|
|
:param video_obj:
|
|
@@ -49,7 +47,7 @@ def process_weixin_video_obj(video_obj, user, trace_id, title):
|
|
|
item.add_video_info("user_id", user["uid"])
|
|
|
item.add_video_info("user_name", user["nick_name"])
|
|
|
item.add_video_info("video_id", video_obj['hashDocID'])
|
|
|
- item.add_video_info("video_title", title)
|
|
|
+ item.add_video_info("video_title", trace_id)
|
|
|
item.add_video_info("publish_time_stamp", int(publish_time_stamp))
|
|
|
item.add_video_info("video_url", video_obj["videoUrl"])
|
|
|
item.add_video_info("cover_url", video_obj["image"])
|
|
@@ -88,20 +86,22 @@ def return_video(video_path, title, trace_id):
|
|
|
)
|
|
|
else:
|
|
|
obj_list = title_result['data']['data']
|
|
|
- for obj in obj_list:
|
|
|
- try:
|
|
|
- title = obj['items'][0]['title'].replace('<em class=\"highlight\">', '').replace('</em>',
|
|
|
- '').replace("#",
|
|
|
- "")
|
|
|
- if Functions().sensitive_flag(title):
|
|
|
- return obj
|
|
|
- else:
|
|
|
- continue
|
|
|
- except Exception as e:
|
|
|
- print(e)
|
|
|
- continue
|
|
|
+ if obj_list:
|
|
|
+ return obj_list[0]
|
|
|
+ # for obj in obj_list:
|
|
|
+ # try:
|
|
|
+ # title = obj['items'][0]['title'].replace('<em class=\"highlight\">', '').replace('</em>',
|
|
|
+ # '').replace("#",
|
|
|
+ # "")
|
|
|
+ # if Functions().sensitive_flag(title):
|
|
|
+ # return obj
|
|
|
+ # else:
|
|
|
+ # continue
|
|
|
+ # except Exception as e:
|
|
|
+ # print(e)
|
|
|
+ # continue
|
|
|
|
|
|
- # search_keys
|
|
|
+ # # search_keys
|
|
|
search_keys_result = wx_search(keys=my_obj['search_keys'][0])
|
|
|
if search_keys_result['msg'] == '未知错误':
|
|
|
logging(
|
|
@@ -111,18 +111,20 @@ def return_video(video_path, title, trace_id):
|
|
|
)
|
|
|
else:
|
|
|
obj_list = search_keys_result['data']['data']
|
|
|
- for obj in obj_list:
|
|
|
- try:
|
|
|
- title = obj['items'][0]['title'].replace('<em class=\"highlight\">', '').replace('</em>',
|
|
|
- '').replace("#",
|
|
|
- "")
|
|
|
- if Functions().sensitive_flag(title):
|
|
|
- return obj
|
|
|
- else:
|
|
|
- continue
|
|
|
- except Exception as e:
|
|
|
- print(e)
|
|
|
- continue
|
|
|
+ if obj_list:
|
|
|
+ return obj_list[0]
|
|
|
+ # for obj in obj_list:
|
|
|
+ # try:
|
|
|
+ # title = obj['items'][0]['title'].replace('<em class=\"highlight\">', '').replace('</em>',
|
|
|
+ # '').replace("#",
|
|
|
+ # "")
|
|
|
+ # if Functions().sensitive_flag(title):
|
|
|
+ # return obj
|
|
|
+ # else:
|
|
|
+ # continue
|
|
|
+ # except Exception as e:
|
|
|
+ # print(e)
|
|
|
+ # continue
|
|
|
|
|
|
# theme
|
|
|
theme_result = wx_search(keys=my_obj['theme'])
|
|
@@ -134,18 +136,20 @@ def return_video(video_path, title, trace_id):
|
|
|
)
|
|
|
else:
|
|
|
obj_list = theme_result['data']['data']
|
|
|
- for obj in obj_list:
|
|
|
- try:
|
|
|
- title = obj['items'][0]['title'].replace('<em class=\"highlight\">', '').replace('</em>',
|
|
|
- '').replace("#",
|
|
|
- "")
|
|
|
- if Functions().sensitive_flag(title):
|
|
|
- return obj
|
|
|
- else:
|
|
|
- continue
|
|
|
- except Exception as e:
|
|
|
- print(e)
|
|
|
- continue
|
|
|
+ if obj_list:
|
|
|
+ return obj_list[0]
|
|
|
+ # for obj in obj_list:
|
|
|
+ # try:
|
|
|
+ # title = obj['items'][0]['title'].replace('<em class=\"highlight\">', '').replace('</em>',
|
|
|
+ # '').replace("#",
|
|
|
+ # "")
|
|
|
+ # if Functions().sensitive_flag(title):
|
|
|
+ # return obj
|
|
|
+ # else:
|
|
|
+ # continue
|
|
|
+ # except Exception as e:
|
|
|
+ # print(e)
|
|
|
+ # continue
|
|
|
return None
|
|
|
else:
|
|
|
logging(
|
|
@@ -173,13 +177,10 @@ def search_videos(video_path, title, trace_id, gh_id):
|
|
|
trace_id=trace_id,
|
|
|
data=video_obj
|
|
|
)
|
|
|
- title = video_obj['items'][0]['title'].replace('<em class=\"highlight\">', '').replace('</em>', '').replace("#",
|
|
|
- "")
|
|
|
process_weixin_video_obj(
|
|
|
video_obj=video_obj['items'][0],
|
|
|
user=gh_id_dict.get(gh_id),
|
|
|
- trace_id=trace_id,
|
|
|
- title=title
|
|
|
+ trace_id=trace_id
|
|
|
)
|
|
|
else:
|
|
|
logging(
|