Explorar o código

v0.8
服务上线

罗俊辉 hai 10 meses
pai
achega
6cbb455e16

+ 18 - 2
applications/ai.py

@@ -3,9 +3,9 @@
 """
 import json
 
-
 import requests
 from openai import OpenAI
+from tavily import TavilyClient
 from tencentcloud.common import credential
 from tencentcloud.common.profile.client_profile import ClientProfile
 from tencentcloud.common.profile.http_profile import HttpProfile
@@ -88,4 +88,20 @@ def tencent_ai(prompt):
         resp_json = json.loads(str(resp))
         return resp_json['Choices'][0]['Message']['Content']
     except TencentCloudSDKException as err:
-        return {"error": str(err)}
+        return {"error": str(err)}
+
+
+def tly_ai(prompt):
+    """
+    :param prompt:
+    :return
+    """
+    TLY = TavilyClient(api_key="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")
+    response = TLY.search(
+        query=prompt,
+        search_depth="advanced",
+        include_images=True,
+        include_answer=True,
+        include_raw_content=True
+    )
+    return response

+ 360 - 0
applications/config.py

@@ -0,0 +1,360 @@
+"""
+@author: luojunhui
+"""
+gh_id_dict = {
+    "gh_01f8afd03366": {
+        "uid": 69637520,
+        "nick_name": "非亲非故"
+    },
+    "gh_058e41145a0c": {
+        "uid": 69637476,
+        "nick_name": "甜腻梦话"
+    },
+    "gh_080bb43aa0dc": {
+        "uid": 70731106,
+        "nick_name": "那一树的嫣红"
+    },
+    "gh_084a485e859a": {
+        "uid": 69637472,
+        "nick_name": "梦星月"
+    },
+    "gh_0921c03402cd": {
+        "uid": 69637531,
+        "nick_name": "你的女友"
+    },
+    "gh_0c89e11f8bf3": {
+        "uid": 69637508,
+        "nick_name": "粟米"
+    },
+    "gh_171cec079b2a": {
+        "uid": 69637501,
+        "nick_name": "海上"
+    },
+    "gh_183d80deffb8": {
+        "uid": 69637491,
+        "nick_name": "论趣"
+    },
+    "gh_192c9cf58b13": {
+        "uid": 70731102,
+        "nick_name": "久亿"
+    },
+    "gh_1ee2e1b39ccf": {
+        "uid": 69637473,
+        "nick_name": "纵有疾风起"
+    },
+    "gh_234ef02cdee5": {
+        "uid": 69637513,
+        "nick_name": "夹逼"
+    },
+    "gh_26a307578776": {
+        "uid": 69637490,
+        "nick_name": "最宝贝的宝贝"
+    },
+    "gh_29074b51f2b7": {
+        "uid": 69637530,
+        "nick_name": "沉舸"
+    },
+    "gh_2abee512312a": {
+        "uid": 70731103,
+        "nick_name": "舍我"
+    },
+    "gh_2b8c6aa035ae": {
+        "uid": 69637470,
+        "nick_name": "懶得取名"
+    },
+    "gh_34318194fd0e": {
+        "uid": 69637517,
+        "nick_name": "徒四壁"
+    },
+    "gh_3845af6945d0": {
+        "uid": 69637545,
+        "nick_name": "秋水娉婷"
+    },
+    "gh_3ac6d7208961": {
+        "uid": 69637497,
+        "nick_name": "小熊的少女梦"
+    },
+    "gh_3c7d38636846": {
+        "uid": 69637519,
+        "nick_name": "油腻腻"
+    },
+    "gh_3df10391639c": {
+        "uid": 69637541,
+        "nick_name": "六郎娇面"
+    },
+    "gh_40a0ad154478": {
+        "uid": 69637516,
+        "nick_name": "禁止"
+    },
+    "gh_424c8eeabced": {
+        "uid": 69637522,
+        "nick_name": "认命"
+    },
+    "gh_4568b5a7e2fe": {
+        "uid": 69637482,
+        "nick_name": "香腮"
+    },
+    "gh_45beb952dc74": {
+        "uid": 69637488,
+        "nick_name": "毋庸"
+    },
+    "gh_484de412b0ef": {
+        "uid": 69637481,
+        "nick_name": "婪"
+    },
+    "gh_4c058673c07e": {
+        "uid": 69637474,
+        "nick_name": "影帝"
+    },
+    "gh_538f78f9d3aa": {
+        "uid": 69637478,
+        "nick_name": "伤痕"
+    },
+    "gh_56a6765df869": {
+        "uid": 69637514,
+        "nick_name": "风月"
+    },
+    "gh_56ca3dae948c": {
+        "uid": 69637538,
+        "nick_name": "留下太多回忆"
+    },
+    "gh_5ae65db96cb7": {
+        "uid": 70731108,
+        "nick_name": "喘声娇息"
+    },
+    "gh_5e543853d8f0": {
+        "uid": 69637543,
+        "nick_name": "不知春秋"
+    },
+    "gh_5ff48e9fb9ef": {
+        "uid": 69637494,
+        "nick_name": "寻她找他"
+    },
+    "gh_671f460c856c": {
+        "uid": 69637523,
+        "nick_name": "绝不改悔"
+    },
+    "gh_6b7c2a257263": {
+        "uid": 69637528,
+        "nick_name": "奶牙"
+    },
+    "gh_6cfd1132df94": {
+        "uid": 70731104,
+        "nick_name": "中指灵活"
+    },
+    "gh_6d205db62f04": {
+        "uid": 69637509,
+        "nick_name": "怕羞"
+    },
+    "gh_6d9f36e3a7be": {
+        "uid": 69637498,
+        "nick_name": "望长安"
+    },
+    "gh_72bace6b3059": {
+        "uid": 70731109,
+        "nick_name": "万物生息"
+    },
+    "gh_73be0287bb94": {
+        "uid": 69637537,
+        "nick_name": "戏剧"
+    },
+    "gh_744cb16f6e16": {
+        "uid": 69637505,
+        "nick_name": "反駁"
+    },
+    "gh_7b4a5f86d68c": {
+        "uid": 69637477,
+        "nick_name": "我很想你"
+    },
+    "gh_7bca1c99aea0": {
+        "uid": 69637511,
+        "nick_name": "从小就很傲"
+    },
+    "gh_7e5818b2dd83": {
+        "uid": 69637532,
+        "nick_name": "二八佳人"
+    },
+    "gh_7f5075624a50": {
+        "uid": 70731113,
+        "nick_name": "浮現"
+    },
+    "gh_89ef4798d3ea": {
+        "uid": 69637533,
+        "nick_name": "彼岸花"
+    },
+    "gh_901b0d722749": {
+        "uid": 69637518,
+        "nick_name": "深情不为我"
+    },
+    "gh_9161517e5676": {
+        "uid": 69637495,
+        "nick_name": "折磨"
+    },
+    "gh_93e00e187787": {
+        "uid": 69637504,
+        "nick_name": "理会"
+    },
+    "gh_9877c8541764": {
+        "uid": 69637506,
+        "nick_name": "我沿着悲伤"
+    },
+    "gh_9cf3b7ff486b": {
+        "uid": 69637492,
+        "nick_name": "hoit"
+    },
+    "gh_9e559b3b94ca": {
+        "uid": 69637471,
+        "nick_name": "我与你相遇"
+    },
+    "gh_9eef14ad6c16": {
+        "uid": 70731110,
+        "nick_name": "抱一抱"
+    },
+    "gh_9f8dc5b0c74e": {
+        "uid": 69637496,
+        "nick_name": "港口"
+    },
+    "gh_a182cfc94dad": {
+        "uid": 69637539,
+        "nick_name": "四海八荒"
+    },
+    "gh_a2901d34f75b": {
+        "uid": 69637535,
+        "nick_name": "听腻了谎话"
+    },
+    "gh_a307072c04b9": {
+        "uid": 69637521,
+        "nick_name": "踏步"
+    },
+    "gh_a6351b447819": {
+        "uid": 69637540,
+        "nick_name": "七猫酒馆"
+    },
+    "gh_ac43e43b253b": {
+        "uid": 69637499,
+        "nick_name": "一厢情愿"
+    },
+    "gh_adca24a8f429": {
+        "uid": 69637483,
+        "nick_name": "对你何止一句喜欢"
+    },
+    "gh_b15de7c99912": {
+        "uid": 69637536,
+        "nick_name": "糖炒板栗"
+    },
+    "gh_b32125c73861": {
+        "uid": 69637493,
+        "nick_name": "发尾"
+    },
+    "gh_b3ffc1ca3a04": {
+        "uid": 69637546,
+        "nick_name": "主宰你心"
+    },
+    "gh_b8baac4296cb": {
+        "uid": 69637489,
+        "nick_name": "生性"
+    },
+    "gh_b9b99173ff8a": {
+        "uid": 69637524,
+        "nick_name": "养一只月亮"
+    },
+    "gh_bd57b6978e06": {
+        "uid": 69637527,
+        "nick_name": "厌遇"
+    },
+    "gh_be8c29139989": {
+        "uid": 69637502,
+        "nick_name": "不负"
+    },
+    "gh_bfe5b705324a": {
+        "uid": 69637529,
+        "nick_name": "乐极"
+    },
+    "gh_bff0bcb0694a": {
+        "uid": 69637534,
+        "nick_name": "简迷离"
+    },
+    "gh_c5cdf60d9ab4": {
+        "uid": 70731111,
+        "nick_name": "定酌"
+    },
+    "gh_c69776baf2cd": {
+        "uid": 69637512,
+        "nick_name": "骄纵"
+    },
+    "gh_c91b42649690": {
+        "uid": 69637503,
+        "nick_name": "荟萃"
+    },
+    "gh_d2cc901deca7": {
+        "uid": 69637487,
+        "nick_name": "恶意调笑"
+    },
+    "gh_d49df5e974ca": {
+        "uid": 70731107,
+        "nick_name": "没你"
+    },
+    "gh_d4dffc34ac39": {
+        "uid": 70744072,
+        "nick_name": "驯课"
+    },
+    "gh_d5f935d0d1f2": {
+        "uid": 69637500,
+        "nick_name": "青少年哪吒"
+    },
+    "gh_da76772d8d15": {
+        "uid": 69637526,
+        "nick_name": "独揽风月"
+    },
+    "gh_de9f9ebc976b": {
+        "uid": 69637475,
+        "nick_name": "剑出鞘恩怨了"
+    },
+    "gh_e0eb490115f5": {
+        "uid": 69637486,
+        "nick_name": "赋别"
+    },
+    "gh_e24da99dc899": {
+        "uid": 69637484,
+        "nick_name": "恋雨夏季"
+    },
+    "gh_e2576b7181c6": {
+        "uid": 69637515,
+        "nick_name": "满天星"
+    },
+    "gh_e75dbdc73d80": {
+        "uid": 69637542,
+        "nick_name": "情战"
+    },
+    "gh_e9d819f9e147": {
+        "uid": 69637525,
+        "nick_name": "与卿"
+    },
+    "gh_efaf7da157f5": {
+        "uid": 69637547,
+        "nick_name": "心野性子浪"
+    },
+    "gh_f25b5fb01977": {
+        "uid": 70731105,
+        "nick_name": "山色空濛"
+    },
+    "gh_f4594783f5b8": {
+        "uid": 69637544,
+        "nick_name": "自缚"
+    },
+    "gh_fe6ef3a65a48": {
+        "uid": 69637480,
+        "nick_name": "风间"
+    },
+    "gh_ff487cb5dab3": {
+        "uid": 70744071,
+        "nick_name": "决然"
+    }
+}
+
+# 配置的小程序config
+minigram_info = {
+    "avatar_url": "https://rescdn.yishihui.com/0temp/lehuo.png",
+    "mid": "wxe8f8f0e23cecad0f",
+    "name": "票圈乐活"
+}

+ 47 - 1
applications/functions.py

@@ -1,10 +1,32 @@
 """
 @author: luojunhui
 """
+import time
+import json
+import random
 import hashlib
 from datetime import datetime, timedelta
 
+import uuid
 import requests
+import urllib.parse
+
+
+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 generate_daily_strings(start_date, end_date):
@@ -84,4 +106,28 @@ def hash_title(title):
     # 获取十六进制形式的哈希值
     hash_hex = hash_object.hexdigest()
 
-    return hash_hex
+    return hash_hex
+
+
+def create_gzh_path(video_id, shared_uid):
+    """
+    :param video_id: 视频 id
+    :param shared_uid: 分享 id
+    """
+
+    def generate_source_id():
+        """
+        generate_source_id
+        :return:
+        """
+        timestamp = str(int(time.time() * 1000))
+        random_str = str(random.randint(1000, 9999))
+        hash_input = f"{timestamp}-{random_str}"
+        return hashlib.md5(hash_input.encode()).hexdigest()
+
+    root_share_id = str(uuid.uuid4())
+    source_id = "video_to_articles" + generate_source_id()
+    url = f"pages/user-videos?id={video_id}&su={shared_uid}&fromGzh=1&rootShareId={root_share_id}&shareId={root_share_id}&rootSourceId={source_id}"
+    # 自动把 root_share_id 加入到白名单
+    # auto_white(root_share_id)
+    return root_share_id, source_id, f"pages/category?jumpPage={urllib.parse.quote(url, safe='')}"

+ 3 - 2
applications/migrate.py

@@ -29,5 +29,6 @@ def migrate_daily(dt):
     print("{} successfully insert {} rows, totally cost {} seconds".format(dt, len(data), b - a))
 
 
-dt_list = generate_daily_strings("20240528", "20240528")
-migrate_daily(dt_list[0])
+dt_list = generate_daily_strings("20240613", "20240617")
+for dt in dt_list:
+    migrate_daily(dt)

+ 4 - 1
deal/__init__.py

@@ -5,4 +5,7 @@ from .videos_deal import RequestDeal
 from .publish_deal import PublishDeal
 from .db_deal import insert_text_mysql, get_text_by_id
 from .articles_deal import ArticleGeneral
-from .algorithm_deal import ArticleMatchAccount
+from .algorithm_deal import ArticleMatchAccount
+from .shareCard_deal import ShareCard
+from .single_video_deal import SingleVideo
+from .matchArticle_deal import MatchArticles

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 67 - 0
deal/matchArticle_deal.py


+ 72 - 0
deal/shareCard_deal.py

@@ -0,0 +1,72 @@
+"""
+@author: luojunhui
+"""
+from applications.functions import request_for_info, create_gzh_path
+from applications.config import minigram_info
+
+
+class ShareCard(object):
+    """
+    生成分享卡片
+    """
+    def __init__(self, params):
+        self.gh_id = None
+        self.video_id = None
+        self.params = params
+
+    def check_params(self):
+        """
+        params check
+        """
+        try:
+            self.video_id = self.params['videoId']
+            self.gh_id = self.params['ghId']
+            return None
+        except AttributeError as e:
+            response = {
+                "code": 0,
+                "error": "Params Error",
+                "msg": "Params: {} is not correct".format(e)
+            }
+            return response
+
+    def generateCards(self):
+        """
+        生成生成卡片的结果
+        :return:
+        """
+        response = request_for_info(video_id=self.video_id)['data'][0]
+        cover = response['coverImg']['coverImgPath']
+        title = response['title']
+        video_url = response['videoPath']
+        user_id = response['user']['uid']
+        root_share_id, source_id, card_path = create_gzh_path(self.video_id, user_id)
+        cardResponse = {
+            "productionCover": cover,
+            "productionName": title,
+            "productionPath": card_path,
+            "programAvatar": minigram_info['avatar_url'],
+            "programId": minigram_info['mid'],
+            "programName": minigram_info['name'],
+            "rootShareId": root_share_id,
+            "sourceId": source_id,
+            "Source": "PQ",
+            "videoUrl": video_url
+        }
+        return cardResponse
+
+    def deal(self):
+        """
+        Deal function
+        :return:
+        """
+        params_error = self.check_params()
+        if params_error:
+            return params_error
+        else:
+            result = {
+                "videoId": self.video_id,
+                "ghId": self.gh_id,
+                "shareCard": self.generateCards()
+            }
+            return result

+ 52 - 0
deal/single_video_deal.py

@@ -0,0 +1,52 @@
+"""
+@author: luojunhui
+"""
+from applications.functions import request_for_info
+
+
+class SingleVideo(object):
+    """
+    返回单个视频信息
+    """
+    def __init__(self, params):
+        self.video_id = None
+        self.params = params
+
+    def check_params(self):
+        """
+        check params
+        :return:
+        """
+        try:
+            self.video_id = self.params['videoId']
+            return None
+        except AttributeError as e:
+            response = {
+                "code": 0,
+                "error": "Params Error",
+                "msg": "Params: {} is not correct".format(e)
+            }
+            return response
+
+    def deal(self):
+        """
+        deal function
+        :return:
+        """
+        params_error = self.check_params()
+        if params_error:
+            return params_error
+        else:
+            response = request_for_info(video_id=self.video_id)['data'][0]
+            title = response['title']
+            video_url = response['videoPath']
+            publish_time = response['gmtCreateTimestamp']
+            # user_id = response['user']['uid']
+            # cover = response['coverImg']['coverImgPath']
+            result = {
+                "videoId": self.video_id,
+                "title": title,
+                "videoUrl": video_url,
+                "publishTime": publish_time
+            }
+            return result

+ 5 - 2
deal/videos_deal.py

@@ -1,7 +1,8 @@
 """
 @author: luojunhui
 """
-from applications.functions import get_text
+from applications.functions import get_text, request_for_info
+from applications.config import minigram_info
 
 
 class RequestDeal(object):
@@ -30,7 +31,9 @@ class RequestDeal(object):
                 "return": obj[3],
                 "video_url": obj[4],
                 "rov": obj[5],
-                "video_text": get_text(video_id=obj[0])['text']
+                "video_text": get_text(video_id=obj[0])['text'],
+                "cover": request_for_info(video_id=obj[0])['data'][0]['coverImg']['coverImgPath'],
+                "minigram_info": minigram_info
             } for obj in data_list
         ]
         response = {

+ 52 - 0
routes/vta_routes.py

@@ -8,6 +8,9 @@ from deal import ArticleMatchAccount
 from deal import ArticleGeneral
 from deal import PublishDeal
 from deal import insert_text_mysql, get_text_by_id
+from deal import ShareCard
+from deal import SingleVideo
+from deal import MatchArticles
 from applications.functions import whisper
 
 
@@ -20,6 +23,18 @@ def VTARoutes(mysql_client):
     :param mysql_client:
     :return:
     """
+    @bp.route("/healthcheck")
+    def hello_world():
+        """
+        Health Check Port
+        :return:
+        """
+        result = {
+            "status": "success",
+            "msg": "Hello Future"
+        }
+        return jsonify(result)
+
     @bp.route('/videos', methods=["POST"])
     async def find_videos():
         """
@@ -95,6 +110,43 @@ def VTARoutes(mysql_client):
         res = MA.deal()
         return jsonify(res)
 
+    @bp.route("/getShareCard", methods=["POST"])
+    async def get_share_cards():
+        """
+        获取分享卡片
+        :return:
+        """
+        params = await request.get_json()
+        SC = ShareCard(params=params)
+        response = SC.deal()
+        return jsonify(response)
+
+    @bp.route("/singleVideo", methods=["POST"])
+    async def find_video_info():
+        """
+        获取单个视频的信息
+        :return:
+        """
+        params = await request.get_json()
+        SV = SingleVideo(params=params)
+        response = SV.deal()
+        return jsonify(response)
+
+    @bp.route("/matchArticle", methods=["POST"])
+    async def match_article():
+        """
+        匹配视频
+        :return:
+        """
+        params = await request.get_json()
+        MA = MatchArticles(params=params)
+        result = MA.deal()
+        response = {
+            "status": "success",
+            "article": result
+        }
+        return jsonify(response)
+
     return bp
 
 

+ 1 - 1
test/ai_dev.py

@@ -4,7 +4,7 @@
 from applications.ai import tencent_ai
 
 
-prompt = "帮我找一下最近的热点新闻链接"
+prompt = "易中天对退休人的忠告,看了才没白活, 通过这个标题搜索相关文章"
 
 res = tencent_ai(prompt)
 

+ 10 - 1
test/dev.py

@@ -4,8 +4,11 @@ from tavily import TavilyClient
 
 
 def tavily_ai(prompt):
+    """
+    :param prompt:
+    :return:
+    """
     tavily = TavilyClient(api_key="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")
-    # For advanced search:
     response = tavily.search(
         query="{}, 通过这个标题生成一遍文章".format(prompt),
         search_depth="advanced",
@@ -15,3 +18,9 @@ def tavily_ai(prompt):
 
     )
     return response
+
+
+title = "易中天对退休人的忠告,看了才没白活"
+
+res = tavily_ai(title)
+print(json.dumps(res, ensure_ascii=False, indent=4))

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 0 - 21
test/dev_0606.py


+ 23 - 0
test/matchArticle_dev.py

@@ -0,0 +1,23 @@
+"""
+@author: luojunhui
+"""
+import json
+import time
+import requests
+
+url = "http://localhost:8888/matchArticle"
+
+body = {
+    "videoId": "21006075",
+    "title": "各位退休的同学,请听!"
+}
+
+a = time.time()
+header = {
+    "Content-Type": "application/json",
+}
+
+response = requests.post(url, json=body, headers=header, timeout=600)
+b = time.time()
+print(b - a)
+print(json.dumps(response.json(), ensure_ascii=False, indent=4))

+ 26 - 0
test/shareCard_dev.py

@@ -0,0 +1,26 @@
+"""
+@author: luojunhui
+"""
+import json
+import time
+import requests
+
+"""
+cate: video_return, video_view, video_rov
+"""
+
+url = "http://localhost:8888/getShareCard"
+
+body = {
+    "videoId": 21059419,
+    "ghId": "testId"
+}
+a = time.time()
+header = {
+    "Content-Type": "application/json",
+}
+
+response = requests.post(url, json=body, headers=header, timeout=600)
+b = time.time()
+print(b - a)
+print(json.dumps(response.json(), ensure_ascii=False, indent=4))

+ 22 - 0
test/single_video_dev.py

@@ -0,0 +1,22 @@
+"""
+@author: luojunhui
+"""
+import json
+import time
+import requests
+
+
+url = "http://localhost:8888/singleVideo"
+
+body = {
+    "videoId": 21059419
+}
+a = time.time()
+header = {
+    "Content-Type": "application/json",
+}
+
+response = requests.post(url, json=body, headers=header, timeout=600)
+b = time.time()
+print(b - a)
+print(json.dumps(response.json(), ensure_ascii=False, indent=4))

+ 20 - 0
test/spider_api.py

@@ -0,0 +1,20 @@
+"""
+@author: luojunhui
+"""
+import requests
+
+url = "https://api.weixin.qq.com/cgi-bin/token"
+
+params = {
+    "grant_type": "client_credential",
+    "appid": "wxe8f8f0e23cecad0f",
+    "secret": "ff5af41ec78bdefed9e283bf1edef3b1"
+}
+
+
+result = requests.get(
+    url=url,
+    params=params
+)
+
+print(result.json())

+ 5 - 8
test/videos_dev.py

@@ -9,13 +9,13 @@ import requests
 cate: video_return, video_view, video_rov
 """
 
-url = "http://47.99.132.47:8888/videos"
+url = "http://localhost:8888/videos"
 
 body = {
     "cate": "video_return",
-    "start_date": "2024-05-28",
-    "end_date": "2024-05-29",
-    "topN": 5
+    "start_date": "2024-06-05",
+    "end_date": "2024-06-06",
+    "topN": 10
 }
 a = time.time()
 header = {
@@ -25,7 +25,4 @@ header = {
 response = requests.post(url, json=body, headers=header, timeout=600)
 b = time.time()
 print(b - a)
-print(json.dumps(response.json(), ensure_ascii=False, indent=4))
-
-# with open("test_return.json", "w", encoding="utf-8") as f:
-#     f.write(json.dumps(response.json(), ensure_ascii=False, indent=4))
+print(json.dumps(response.json(), ensure_ascii=False, indent=4))

Algúns arquivos non se mostraron porque demasiados arquivos cambiaron neste cambio