|
@@ -13,8 +13,9 @@ from application.common.feishu import FsData
|
|
|
from application.common.feishu.feishu_utils import FeishuUtils
|
|
|
from application.common.gpt import GPT4oMini
|
|
|
from application.common.mysql.sql import Sql
|
|
|
+from typing import Dict, Any
|
|
|
from application.common.redis.xng_redis import xng_in_video_data
|
|
|
-from application.config.config import zhufuquanzi_view_api,zhufuquanzi_history_api
|
|
|
+from application.config.config import zhufuquanzi_view_api,zhufuquanzi_history_api,zhufuquanzi_log_upload_api
|
|
|
|
|
|
sys.path.append(os.getcwd())
|
|
|
|
|
@@ -93,6 +94,41 @@ def video_history(video_view_lists):
|
|
|
print(f"{zhufuquanzi_history_api}响应不是有效的 JSON 格式")
|
|
|
|
|
|
|
|
|
+def log_upload(video_objs):
|
|
|
+ headers = {
|
|
|
+ "Content-Type": "application/json"
|
|
|
+ }
|
|
|
+ payload = {
|
|
|
+ "e": video_objs
|
|
|
+ }
|
|
|
+ try:
|
|
|
+ print(json.dumps(payload))
|
|
|
+ # 发送 POST 请求
|
|
|
+ response = requests.post(
|
|
|
+ zhufuquanzi_log_upload_api,
|
|
|
+ headers=headers,
|
|
|
+ json=payload # 自动将字典转换为 JSON
|
|
|
+ )
|
|
|
+ # 检查 HTTP 状态码
|
|
|
+ if response.status_code == 200:
|
|
|
+ # 解析 JSON 响应
|
|
|
+ result = response.json()
|
|
|
+ # 提取关键字段
|
|
|
+ code = result.get("code")
|
|
|
+ msg = result.get("msg")
|
|
|
+ # 业务逻辑处理(示例)
|
|
|
+ if code == 0:
|
|
|
+ print(f"{zhufuquanzi_log_upload_api}请求成功")
|
|
|
+ else:
|
|
|
+ print(f"{zhufuquanzi_log_upload_api}请求失败,错误码: {code}, 消息: {msg}")
|
|
|
+ else:
|
|
|
+ print(f"{zhufuquanzi_log_upload_api}HTTP 请求失败,状态码: {response.status_code}")
|
|
|
+ except requests.exceptions.RequestException as e:
|
|
|
+ print(f"{zhufuquanzi_log_upload_api}请求异常: {e}")
|
|
|
+ except json.JSONDecodeError:
|
|
|
+ print(f"{zhufuquanzi_log_upload_api}响应不是有效的 JSON 格式")
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
@@ -149,13 +185,16 @@ class ZFQZTJLRecommend(object):
|
|
|
),
|
|
|
return
|
|
|
video_view_lists = []
|
|
|
+ video_log_uploads = []
|
|
|
for index, video_obj in enumerate(response['data']['data'], 1):
|
|
|
+ print(video_obj)
|
|
|
try:
|
|
|
self.aliyun_log.logging(
|
|
|
code="1001", message="扫描到一条视频", data=video_obj
|
|
|
)
|
|
|
vid = video_obj['id']
|
|
|
video_view_lists.append(str(vid))
|
|
|
+ video_log_uploads.append(self.build_video_log(video_obj,index))
|
|
|
self.process_video_obj(video_obj,title_rule)
|
|
|
except Exception as e:
|
|
|
self.aliyun_log.logging(
|
|
@@ -169,7 +208,7 @@ class ZFQZTJLRecommend(object):
|
|
|
time.sleep(random.randint(5, 10))
|
|
|
# time.sleep(random.randint(5, 30))
|
|
|
video_history(video_view_lists)
|
|
|
-
|
|
|
+ log_upload(video_log_uploads)
|
|
|
def process_video_obj(self, video_obj, title_rule):
|
|
|
"""
|
|
|
处理视频
|
|
@@ -260,6 +299,32 @@ class ZFQZTJLRecommend(object):
|
|
|
):
|
|
|
self.limit_flag = True
|
|
|
|
|
|
+ def build_video_log(self, video_obj: Dict[str, Any], index: int) -> Dict[str, Any]:
|
|
|
+ """构建视频日志对象"""
|
|
|
+ return {
|
|
|
+ "ac": "show",
|
|
|
+ "md_ver": "2.0",
|
|
|
+ "data": {
|
|
|
+ "page": "discoverIndexPage",
|
|
|
+ "topic": "recommend",
|
|
|
+ "tpl_id": str(video_obj['tpl_id']),
|
|
|
+ "profile_ct": str(video_obj['p_ct']),
|
|
|
+ "flv": "0",
|
|
|
+ "sign": video_obj['sign'],
|
|
|
+ "serial_id": video_obj['serial_id'],
|
|
|
+ "type": "post",
|
|
|
+ "name": "post",
|
|
|
+ "src_page": "discoverIndexPage/recommend",
|
|
|
+ "aid": str(video_obj['album_id']),
|
|
|
+ "cid": str(video_obj['id']),
|
|
|
+ "feed_idx": index - 1,
|
|
|
+ "cmid": str(video_obj['user']['mid']),
|
|
|
+ "user_ct": "1638346045009"
|
|
|
+ },
|
|
|
+ "t": int(time.time() * 1000),
|
|
|
+ "ab": {}
|
|
|
+ }
|
|
|
+
|
|
|
def run(self):
|
|
|
self.get_recommend_list()
|
|
|
|