ソースを参照

修改分享小程序从票圈 vlog 改为票圈最惊奇

罗俊辉 1 年間 前
コミット
8a8eef52f3

+ 0 - 58
applications/functions/search_video.py

@@ -1,58 +0,0 @@
-"""
-@author: luojunhui
-"""
-import requests
-import json
-import time
-
-from tqdm import tqdm
-
-
-def search_spider(params):
-    """
-    通过搜索爬虫 + search_keys 来获取视频信息,并且以 MQ 的方式发送给 ETL, 正常上传发布
-    :param params: []
-    :return:
-    """
-    search_keys = params['search_keys']
-    url = "http://8.217.190.241:8888/crawler/wei_xin/keyword"
-
-    payload = json.dumps({
-        "keyword": ",".join(search_keys),
-        "cursor": "0",
-        "content_type": "video"
-    })
-    headers = {
-        'Content-Type': 'application/json'
-    }
-    response = requests.request("POST", url, headers=headers, data=payload)
-    data_list = response.json()['data']['data']
-    for item in tqdm(data_list[:1]):
-        video_obj = item['items'][0]
-        print(json.dumps(video_obj, ensure_ascii=False, indent=4))
-        video_id = video_obj['hashDocID']
-        video_url = video_obj['videoUrl']
-        video_title = video_obj['title']
-        etl(vid=video_id, video_url=video_url, title=video_title)
-
-
-def etl(vid, title, video_url):
-    print(vid)
-    url = "http://lightgbm-internal-test.piaoquantv.com/etl"
-    payload = {
-        "video_title": title,
-        "video_url": video_url,
-        "video_id": vid,
-
-    }
-    t = time.time()
-    res = requests.post(url, json=payload)
-    e = time.time()
-    print(e - t)
-    print(res.json())
-
-
-# p = {
-#     "search_keys": ["王者荣耀", "李白", "五杀"]
-# }
-# search_spider(p)

+ 4 - 0
applications/match_alg/__init__.py

@@ -0,0 +1,4 @@
+"""
+@author: luojunhui
+匹配算法
+"""

+ 13 - 0
applications/match_alg/rank.py

@@ -0,0 +1,13 @@
+"""
+@author: luojunhui
+"""
+
+
+def best_choice():
+    """
+    计算,返回出最合适的 video_id
+    :return: video_id
+    """
+    best_video_id = 0
+    return best_video_id
+

+ 16 - 0
applications/match_alg/recall.py

@@ -0,0 +1,16 @@
+"""
+@author: luojunhui
+"""
+
+
+def recall_videos(params):
+    """
+    通过请求的数据来召回视频
+    :param params: 请求参数
+    :return:
+    """
+    title = params['title']
+    content = params['content']
+
+
+

+ 36 - 0
applications/mq.py

@@ -0,0 +1,36 @@
+"""
+@author: luojunhui
+"""
+import json
+from uuid import uuid4
+from mq_http_sdk.mq_exception import MQExceptionBase
+from mq_http_sdk.mq_producer import TopicMessage
+from mq_http_sdk.mq_client import MQClient
+
+
+class MQ(object):
+    """
+    MQ Class
+    """
+    instance_id = "MQ_INST_1894469520484605_BXhXuzkZ"
+
+    def __init__(self, topic_name) -> None:
+        self.mq_client = MQClient("http://1894469520484605.mqrest.cn-qingdao-public.aliyuncs.com",
+                                  "LTAI4G7puhXtLyHzHQpD6H7A",
+                                  "nEbq3xWNQd1qLpdy2u71qFweHkZjSG")
+        self.producer = self.mq_client.get_producer(self.instance_id, topic_name)
+
+    def send_msg(self, params):
+        """
+        发送 mq,并且记录 redis
+        """
+        account = params["ghId"]
+
+        try:
+            msg = TopicMessage(json.dumps(params))
+            message_key = account + str(uuid4())
+            msg.set_message_key(message_key)
+            re_msg = self.producer.publish_message(msg)
+            print(re_msg)
+        except MQExceptionBase as e:
+            print(e)

+ 2 - 2
applications/process.py

@@ -164,8 +164,8 @@ class ProcessParams(object):
             productionName = response["data"][0]['title']
             videoUrl = response['data'][0]['videoPath']
             programAvatar = "/static/logo.png"
-            programId = "wx89e7eb06478361d7"
-            programName = "票圈vlog"
+            programId = "wx69c36def517d687a"
+            programName = "票圈最惊奇"
             source = "Web"
             result = {
                 "productionCover": productionCover,

+ 6 - 3
applications/routes.py

@@ -7,7 +7,7 @@ from quart import Blueprint, jsonify, request
 
 from applications.log import logging
 from applications.process import ProcessParams
-from applications.functions.search_video import search_spider
+from applications.mq import MQ
 
 my_blueprint = Blueprint('kimi', __name__)
 
@@ -51,6 +51,7 @@ async def search_data():
     通过搜索词去搜索获取视频信息
     :return:
     """
+    mq = MQ(topic_name="search_spider_prod")
     trace_id = "search-{}-{}".format(str(uuid.uuid4()), str(int(time.time())))
     logging(
         code="1001",
@@ -59,5 +60,7 @@ async def search_data():
         trace_id=trace_id
     )
     data = await request.get_json()
-    result = await search_spider(data)
-    return jsonify(result)
+    mq.send_msg(params=data)
+    return jsonify({
+        "code": 0
+    })

+ 6 - 5
test.py

@@ -1,6 +1,7 @@
 """
 @author: luojunhui
 """
+import json
 import time
 import requests
 import argparse
@@ -11,16 +12,15 @@ def request_data(url):
     # index = _url.split("#")[0]
     # url = _url.split("#")[1]
     body = {
-        "accountName": "魔法美学馆",
-        "content": "8月20日,最高人民法院举行新闻发布会,发布新修订的《最高人民法院关于审理民间借贷案件适用法律若干问题的规定》(以下简称《规定》)并回答记者提问。",
-        "title": "邯郸杀人案件"
+        "search_keys": ["日本"],
+        "ghId": "gh_efaf7da157f5"
     }
     t = time.time()
     res = requests.post(url, json=body)
     e = time.time()
     # print(index)
     print(e - t)
-    print(res.text)
+    print(json.dumps(res.json(), ensure_ascii=False, indent=4))
     # print(res.json())
 
 
@@ -29,7 +29,8 @@ if __name__ == "__main__":
     # parser.add_argument("--thread")
     # args = parser.parse_args()
     # thread = int(args.thread)
-    dt = ["http://61.48.133.26:8111/title_to_video"]
+    # dt = ["http://61.48.133.26:8111/title_to_video"]
+    dt = ["http://127.0.0.1:5000/search_videos"]
     # total_s = time.time()
     request_data(dt[0])
     # with ThreadPoolExecutor(max_workers=thread) as pool: