|
@@ -4,67 +4,11 @@
|
|
|
"""
|
|
|
|
|
|
import os
|
|
|
-import json
|
|
|
-import uuid
|
|
|
-import requests
|
|
|
-import urllib.parse
|
|
|
-from datetime import datetime, timedelta
|
|
|
|
|
|
from applications.log import logging
|
|
|
from applications.functions.ask_kimi import ask_kimi
|
|
|
-from applications.functions.calculate import title_mix
|
|
|
-from applications.functions.auto_white import auto_white
|
|
|
-
|
|
|
-
|
|
|
-def create_gzh_path(video_id, shared_uid):
|
|
|
- """
|
|
|
- :param video_id: 视频 id
|
|
|
- :param shared_uid: 分享 id
|
|
|
- """
|
|
|
- root_share_id = str(uuid.uuid4())
|
|
|
- url = f"pages/user-videos?id={video_id}&su={shared_uid}&fromGzh=1&rootShareId={root_share_id}&shareId={root_share_id}"
|
|
|
- # 自动把 root_share_id 加入到白名单
|
|
|
- auto_white(root_share_id)
|
|
|
- return root_share_id, f"pages/category?jumpPage={urllib.parse.quote(url, safe='')}"
|
|
|
-
|
|
|
-
|
|
|
-def request_for_info(video_id):
|
|
|
- """
|
|
|
- 请求数据
|
|
|
- :param video_id:
|
|
|
- :return:
|
|
|
- """
|
|
|
- url = "https://longvideoapi.piaoquantv.com/longvideoapi/openapi/video/batchSelectVideoInfo"
|
|
|
- data = {
|
|
|
- "videoIdList": [video_id]
|
|
|
- }
|
|
|
- header = {
|
|
|
- "Content-Type": "application/json",
|
|
|
- }
|
|
|
- response = requests.post(url, headers=header, data=json.dumps(data))
|
|
|
- return response.json()
|
|
|
-
|
|
|
-
|
|
|
-def choose_video(result):
|
|
|
- """
|
|
|
- :param result: 计算出来的结果
|
|
|
- :return: uid, video_id
|
|
|
- """
|
|
|
- # 判断 score
|
|
|
- # score1, score2 = result['s1_score'], result['s2_score']
|
|
|
- score1 = result['s1_score']
|
|
|
- if score1 > 0:
|
|
|
- return result['s1_uid'], result['s1_vid']
|
|
|
- else:
|
|
|
- return None, None
|
|
|
- # if score1 == 0 and score2 == 0:
|
|
|
- # return None, None
|
|
|
- # elif score1 == 0 and score2 > 0:
|
|
|
- # return result['s2_uid'], result['s2_vid']
|
|
|
- # elif score1 > 0 and score2 == 0:
|
|
|
- # return result['s1_uid'], result['s1_vid']
|
|
|
- # elif score1 > 0 and score2 > 0:
|
|
|
- # return result['s1_uid'], result['s1_vid']
|
|
|
+from applications.match_alg import best_choice
|
|
|
+from applications.functions.common import *
|
|
|
|
|
|
|
|
|
class ProcessParams(object):
|
|
@@ -124,20 +68,13 @@ class ProcessParams(object):
|
|
|
with open(save_path, "w", encoding="utf-8") as f:
|
|
|
f.write(json.dumps(result, ensure_ascii=False))
|
|
|
|
|
|
- def process(self, data):
|
|
|
+ def deal(self, data):
|
|
|
"""执行代码"""
|
|
|
- today = datetime.today()
|
|
|
- yesterday = today - timedelta(days=1)
|
|
|
- yesterday_str = yesterday.strftime("%Y%m%d")
|
|
|
- logging(
|
|
|
- code="1002",
|
|
|
- info="昨日的时间戳是---{}".format(yesterday_str),
|
|
|
- function="process",
|
|
|
- trace_id=self.trace_id,
|
|
|
- )
|
|
|
params = self.get_params(data)
|
|
|
title = params['title']
|
|
|
- account_name = params['accountName']
|
|
|
+ # account_name = params['accountName']
|
|
|
+ # ghId = params['ghId']
|
|
|
+
|
|
|
title_p = os.path.join(os.getcwd(), 'applications', 'static', "titles", "{}.json".format(title))
|
|
|
if os.path.exists(title_p):
|
|
|
logging(
|
|
@@ -146,33 +83,42 @@ class ProcessParams(object):
|
|
|
function="process",
|
|
|
trace_id=self.trace_id
|
|
|
)
|
|
|
- result = title_mix(title_p=title_p, dt=yesterday_str, trace_id=self.trace_id)
|
|
|
else:
|
|
|
self.ask_kimi_and_save_to_local(title)
|
|
|
- result = title_mix(title_p=title_p, dt=yesterday_str, trace_id=self.trace_id)
|
|
|
- uid, video_id = choose_video(result)
|
|
|
+
|
|
|
+ with open(title_p, encoding="utf-8") as f:
|
|
|
+ params_obj = json.loads(f.read())
|
|
|
+
|
|
|
+ best_video_id = best_choice(
|
|
|
+ params_obj=params_obj,
|
|
|
+ trace_id=self.trace_id,
|
|
|
+ request_param=params
|
|
|
+ )
|
|
|
logging(
|
|
|
code="1002",
|
|
|
- info="best video_id --{}".format(video_id),
|
|
|
+ info="best video_id --{}".format(best_video_id),
|
|
|
function="process",
|
|
|
trace_id=self.trace_id
|
|
|
)
|
|
|
- if video_id and uid:
|
|
|
- root_share_id, productionPath = create_gzh_path(video_id=video_id, shared_uid=uid)
|
|
|
- logging(
|
|
|
- code="1002",
|
|
|
- info="root_share_id --{}, productionPath -- {}".format(root_share_id, productionPath),
|
|
|
- function="process",
|
|
|
- trace_id=self.trace_id
|
|
|
- )
|
|
|
- response = request_for_info(video_id)
|
|
|
+
|
|
|
+ if best_video_id:
|
|
|
+ print(best_video_id)
|
|
|
+ response = request_for_info(best_video_id)
|
|
|
productionCover = response['data'][0]['shareImgPath']
|
|
|
productionName = response["data"][0]['title']
|
|
|
videoUrl = response['data'][0]['videoPath']
|
|
|
+ user_id = response['data'][0]['user']['uid']
|
|
|
programAvatar = "/static/logo.png"
|
|
|
programId = "wx69c36def517d687a"
|
|
|
programName = "票圈最惊奇"
|
|
|
source = "Web"
|
|
|
+ root_share_id, productionPath = create_gzh_path(video_id=best_video_id, shared_uid=user_id)
|
|
|
+ logging(
|
|
|
+ code="1002",
|
|
|
+ info="root_share_id --{}, productionPath -- {}".format(root_share_id, productionPath),
|
|
|
+ function="process",
|
|
|
+ trace_id=self.trace_id
|
|
|
+ )
|
|
|
result = {
|
|
|
"productionCover": productionCover,
|
|
|
"productionName": productionName,
|
|
@@ -191,7 +137,7 @@ class ProcessParams(object):
|
|
|
trace_id=self.trace_id,
|
|
|
data={
|
|
|
"rootShareId": root_share_id,
|
|
|
- "videoId": video_id
|
|
|
+ "videoId": best_video_id
|
|
|
}
|
|
|
)
|
|
|
else:
|