|
@@ -1,14 +1,12 @@
|
|
"""
|
|
"""
|
|
@author: luojunhui
|
|
@author: luojunhui
|
|
"""
|
|
"""
|
|
-import time
|
|
|
|
-import uuid
|
|
|
|
import asyncio
|
|
import asyncio
|
|
from quart import Blueprint, jsonify, request
|
|
from quart import Blueprint, jsonify, request
|
|
|
|
|
|
from applications.functions.log import logging
|
|
from applications.functions.log import logging
|
|
-from applications.schedule import recall_videos, search_videos, re_search_videos
|
|
|
|
-from applications.static.config import db_article
|
|
|
|
|
|
+from applications.schedule import recall_videos
|
|
|
|
+from applications.deal import SearchDeal, ReSearchDeal
|
|
|
|
|
|
my_blueprint = Blueprint('LongArticles', __name__)
|
|
my_blueprint = Blueprint('LongArticles', __name__)
|
|
|
|
|
|
@@ -24,11 +22,6 @@ def Routes(mysql_client):
|
|
Hello World Test
|
|
Hello World Test
|
|
:return:
|
|
:return:
|
|
"""
|
|
"""
|
|
- logging(
|
|
|
|
- code="1001",
|
|
|
|
- info="请求接口成功",
|
|
|
|
- port="healthcheck"
|
|
|
|
- )
|
|
|
|
return jsonify({'message': 'Hello, World!'})
|
|
return jsonify({'message': 'Hello, World!'})
|
|
|
|
|
|
@my_blueprint.route('/search_videos', methods=['POST'])
|
|
@my_blueprint.route('/search_videos', methods=['POST'])
|
|
@@ -38,70 +31,9 @@ def Routes(mysql_client):
|
|
:return:
|
|
:return:
|
|
"""
|
|
"""
|
|
params = await request.get_json()
|
|
params = await request.get_json()
|
|
- try:
|
|
|
|
- gh_id = params['ghId']
|
|
|
|
- trace_id = "search-{}-{}".format(str(uuid.uuid4()), str(int(time.time())))
|
|
|
|
- params['trace_id'] = trace_id
|
|
|
|
- title = params['title'].split("@@")[-1].replace("'", "")
|
|
|
|
- contents = params['content'].replace("'", "")
|
|
|
|
- account_name = params['accountName'].replace("'", "")
|
|
|
|
- logging(
|
|
|
|
- code="2000",
|
|
|
|
- info="搜索视频内容接口请求成功",
|
|
|
|
- port="title_to_search",
|
|
|
|
- function="search_videos_from_the_web",
|
|
|
|
- trace_id=trace_id
|
|
|
|
- )
|
|
|
|
- except Exception as e:
|
|
|
|
- result = {
|
|
|
|
- "status": "fail",
|
|
|
|
- "code": 1,
|
|
|
|
- "message": str(e),
|
|
|
|
- "info": "params check error"
|
|
|
|
- }
|
|
|
|
- return jsonify(result)
|
|
|
|
- if "video_id=" in title:
|
|
|
|
- video_id = title.split("video_id=")[-1]
|
|
|
|
- insert_sql = f"""
|
|
|
|
- INSERT INTO {db_article}
|
|
|
|
- (trace_id, gh_id, article_title, article_text, account_name, recall_video_id1)
|
|
|
|
- VALUES
|
|
|
|
- ('{trace_id}', '{gh_id}', '{title}', '{contents}', '{account_name}', '{video_id}');"""
|
|
|
|
- await mysql_client.async_insert(insert_sql)
|
|
|
|
- res = {
|
|
|
|
- "status": "success",
|
|
|
|
- "code": 0,
|
|
|
|
- "traceId": trace_id
|
|
|
|
- }
|
|
|
|
- return jsonify(res)
|
|
|
|
- else:
|
|
|
|
- insert_sql = f"""
|
|
|
|
- INSERT INTO {db_article}
|
|
|
|
- (trace_id, gh_id, article_title, article_text, account_name)
|
|
|
|
- VALUES
|
|
|
|
- ('{trace_id}', '{gh_id}', '{title}', '{contents}', '{account_name}');"""
|
|
|
|
- await mysql_client.async_insert(insert_sql)
|
|
|
|
- try:
|
|
|
|
- asyncio.ensure_future(
|
|
|
|
- search_videos(
|
|
|
|
- params=params,
|
|
|
|
- trace_id=trace_id,
|
|
|
|
- gh_id=gh_id,
|
|
|
|
- mysql_client=mysql_client
|
|
|
|
- )
|
|
|
|
- )
|
|
|
|
- res = {
|
|
|
|
- "status": "success",
|
|
|
|
- "code": 0,
|
|
|
|
- "traceId": trace_id
|
|
|
|
- }
|
|
|
|
- except Exception as e:
|
|
|
|
- res = {
|
|
|
|
- "status": "fail",
|
|
|
|
- "code": 1,
|
|
|
|
- "message": str(e)
|
|
|
|
- }
|
|
|
|
- return jsonify(res)
|
|
|
|
|
|
+ SD = SearchDeal(params=params, mysql_client=mysql_client)
|
|
|
|
+ result = await SD.deal()
|
|
|
|
+ return jsonify(result)
|
|
|
|
|
|
@my_blueprint.route('/recall_videos', methods=['POST'])
|
|
@my_blueprint.route('/recall_videos', methods=['POST'])
|
|
async def find_videos():
|
|
async def find_videos():
|
|
@@ -138,30 +70,8 @@ def Routes(mysql_client):
|
|
:return:
|
|
:return:
|
|
"""
|
|
"""
|
|
params = await request.get_json()
|
|
params = await request.get_json()
|
|
- gh_id = params['ghId']
|
|
|
|
- trace_id = params['trace_id']
|
|
|
|
- logging(
|
|
|
|
- code="2000",
|
|
|
|
- info="重新搜索视频内容接口请求成功",
|
|
|
|
- port="title_to_search",
|
|
|
|
- function="re_search_videos_from_the_web",
|
|
|
|
- trace_id=trace_id
|
|
|
|
- )
|
|
|
|
-
|
|
|
|
- try:
|
|
|
|
- asyncio.ensure_future(re_search_videos(params, trace_id, gh_id))
|
|
|
|
- res = {
|
|
|
|
- "status": "success",
|
|
|
|
- "code": 0,
|
|
|
|
- "traceId": trace_id
|
|
|
|
- }
|
|
|
|
- return jsonify(res)
|
|
|
|
- except Exception as e:
|
|
|
|
- res = {
|
|
|
|
- "status": "fail",
|
|
|
|
- "code": 1,
|
|
|
|
- "message": str(e)
|
|
|
|
- }
|
|
|
|
|
|
+ RSD = ReSearchDeal(params=params)
|
|
|
|
+ res = await RSD.deal()
|
|
return jsonify(res)
|
|
return jsonify(res)
|
|
|
|
|
|
return my_blueprint
|
|
return my_blueprint
|