Переглянути джерело

增加
功能 1: root_share_id 自动加入白名单
功能 2: 若得分为 0,则返回 None

罗俊辉 1 рік тому
батько
коміт
e07d2cac87
3 змінених файлів з 111 додано та 22 видалено
  1. 55 0
      applications/functions/auto_white.py
  2. 51 19
      applications/process.py
  3. 5 3
      test.py

+ 55 - 0
applications/functions/auto_white.py

@@ -0,0 +1,55 @@
+"""
+@author: luojunhui
+"""
+import json
+import requests
+
+
+def get_cookie():
+    """
+    获取 cookie
+    :return:
+    """
+    url = "https://admin.piaoquantv.com/manager/login?account=luojunhui&passWd=e10adc3949ba59abbe56e057f20f883e&muid=7"
+    payload = {}
+    headers = {
+        'accept': 'application/json, text/plain, */*',
+        'accept-language': 'en',
+        'priority': 'u=1, i',
+        'sec-ch-ua': '"Chromium";v="124", "Google Chrome";v="124", "Not-A.Brand";v="99"',
+        'sec-ch-ua-mobile': '?0',
+        'sec-ch-ua-platform': '"macOS"',
+        'sec-fetch-dest': 'empty',
+        'sec-fetch-mode': 'cors',
+        'sec-fetch-site': 'same-origin',
+        'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36'
+    }
+    response = requests.request("GET", url, headers=headers, data=payload)
+    return response.cookies.values()[0]
+
+
+def auto_white(root_share_id):
+    """
+    自动加入白名单, 保证公众号百分百出广告
+    :param root_share_id:
+    :return:
+    """
+    url = "https://admin.piaoquantv.com/manager/ad/own/white/rootShare/save"
+    dd = {
+        "rootShareId": root_share_id,
+        "commit": "算法自动加入白名单--"
+    }
+    payload = json.dumps(dd)
+    cookie = get_cookie()
+    print(cookie)
+    headers = {
+        'accept': 'application/json',
+        'accept-language': 'en',
+        'content-type': 'application/json;',
+        'cookie': "SESSION=" + cookie,
+        'origin': 'https://admin.piaoquantv.com',
+        'priority': 'u=1, i',
+        'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36'
+    }
+    response = requests.request("POST", url, headers=headers, data=payload)
+    return response.json()['content']

+ 51 - 19
applications/process.py

@@ -12,6 +12,7 @@ from datetime import datetime, timedelta
 
 
 from applications.functions.ask_kimi import ask_kimi
 from applications.functions.ask_kimi import ask_kimi
 from applications.functions.calculate import title_mix
 from applications.functions.calculate import title_mix
+from applications.functions.auto_white import auto_white
 
 
 
 
 class ProcessParams(object):
 class ProcessParams(object):
@@ -58,6 +59,8 @@ class ProcessParams(object):
         """
         """
         root_share_id = str(uuid.uuid4())
         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}"
         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)}"
         return root_share_id, f"pages/category?jumpPage={urllib.parse.quote(url)}"
 
 
     @classmethod
     @classmethod
@@ -77,6 +80,23 @@ class ProcessParams(object):
         response = requests.post(url, headers=header, data=json.dumps(data))
         response = requests.post(url, headers=header, data=json.dumps(data))
         return response.json()
         return response.json()
 
 
+    @classmethod
+    def choose_video(cls, result):
+        """
+        :param result: 计算出来的结果
+        :return: uid, video_id
+        """
+        # 判断 score
+        score1, score2 = result['s1_score'], result['s2_score']
+        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']
+
     @classmethod
     @classmethod
     def process(cls, data):
     def process(cls, data):
         """执行代码"""
         """执行代码"""
@@ -90,23 +110,35 @@ class ProcessParams(object):
         else:
         else:
             cls.ask_kimi_and_save_to_local(title)
             cls.ask_kimi_and_save_to_local(title)
             result = title_mix(title_p=title_p, dt=yesterday_str)
             result = title_mix(title_p=title_p, dt=yesterday_str)
-        uid, video_id = result['s1_uid'], result['s1_vid']
-        root_share_id, productionPath = cls.create_gzh_path(uid, video_id)
-        response = cls.request_for_info(video_id)
-        productionCover = response['data'][0]['shareImgPath']
-        productionName = response["data"][0]['title']
-        programAvatar = "/static/logo.png"
-        programId = "wx89e7eb06478361d7"
-        programName = "票圈vlog"
-        source = "Web"
-        result = {
-            "productionCover": productionCover,
-            "productionName": productionName,
-            "programAvatar": programAvatar,
-            "programId": programId,
-            "programName": programName,
-            "source": source,
-            "rootShareId": root_share_id,
-            "productionPath": productionPath
-        }
+        uid, video_id = cls.choose_video(result)
+        if video_id and uid:
+            root_share_id, productionPath = cls.create_gzh_path(uid, video_id)
+            response = cls.request_for_info(video_id)
+            productionCover = response['data'][0]['shareImgPath']
+            productionName = response["data"][0]['title']
+            programAvatar = "/static/logo.png"
+            programId = "wx89e7eb06478361d7"
+            programName = "票圈vlog"
+            source = "Web"
+            result = {
+                "productionCover": productionCover,
+                "productionName": productionName,
+                "programAvatar": programAvatar,
+                "programId": programId,
+                "programName": programName,
+                "source": source,
+                "rootShareId": root_share_id,
+                "productionPath": productionPath
+            }
+        else:
+            result = {
+                "productionCover": None,
+                "productionName": None,
+                "programAvatar": None,
+                "programId": None,
+                "programName": None,
+                "source": None,
+                "rootShareId": None,
+                "productionPath": None
+            }
         return result
         return result

+ 5 - 3
test.py

@@ -8,10 +8,13 @@ from concurrent.futures import ThreadPoolExecutor
 
 
 
 
 def request_data(url):
 def request_data(url):
+
     # index = _url.split("#")[0]
     # index = _url.split("#")[0]
     # url = _url.split("#")[1]
     # url = _url.split("#")[1]
     body = {
     body = {
-        "title": "中华人民共和国"
+        "accountName": "魔法美学馆",
+        "content": "8月20日,最高人民法院举行新闻发布会,发布新修订的《最高人民法院关于审理民间借贷案件适用法律若干问题的规定》(以下简称《规定》)并回答记者提问。",
+        "title": "最高法发布新修订的《关于审理民间借贷案件适用法律若干问题的规定》(附全文)"
     }
     }
     t = time.time()
     t = time.time()
     res = requests.post(url, json=body)
     res = requests.post(url, json=body)
@@ -21,13 +24,12 @@ def request_data(url):
     # print(res.text)
     # print(res.text)
     print(res.json())
     print(res.json())
 
 
-
 if __name__ == "__main__":
 if __name__ == "__main__":
     # parser = argparse.ArgumentParser()  # 新建参数解释器对象
     # parser = argparse.ArgumentParser()  # 新建参数解释器对象
     # parser.add_argument("--thread")
     # parser.add_argument("--thread")
     # args = parser.parse_args()
     # args = parser.parse_args()
     # thread = int(args.thread)
     # thread = int(args.thread)
-    dt = ["http://192.168.100.31:8111/title_to_video"]
+    dt = ["http://61.48.133.26:8111/title_to_video"]
     # total_s = time.time()
     # total_s = time.time()
     request_data(dt[0])
     request_data(dt[0])
     # with ThreadPoolExecutor(max_workers=thread) as pool:
     # with ThreadPoolExecutor(max_workers=thread) as pool: