123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- """
- @author: luojunhui
- """
- import os
- import time
- import uuid
- import asyncio
- from quart import Blueprint, jsonify, request
- from applications.log import logging
- from applications.process import ProcessParams
- from applications.mq import MQ
- from applications.functions.common import find_videos_in_mysql, ask_kimi_and_save_to_local
- my_blueprint = Blueprint('kimi', __name__)
- @my_blueprint.route('/healthcheck')
- async def hello():
- """
- Hello World Test
- :return:
- """
- logging(
- code="1001",
- info="请求接口成功",
- port="healthcheck"
- )
- await asyncio.sleep(30)
- return jsonify({'message': 'Hello, World!'})
- @my_blueprint.route('/title_to_search', methods=['POST'])
- async def search_videos_from_the_web():
- """
- 从web 搜索视频并且存储到票圈的视频库中
- :return:
- """
- mq = MQ(topic_name="search_spider_prod")
- trace_id = "search-{}-{}".format(str(uuid.uuid4()), str(int(time.time())))
- logging(
- code="1001",
- info="搜索视频内容接口请求成功",
- port="title_to_search",
- trace_id=trace_id
- )
- params = await request.get_json()
- params['trace_id'] = trace_id
- title = params['title']
- title_p = os.path.join(os.getcwd(), 'applications', 'static', "titles", "{}.json".format(title))
- if os.path.exists(title_p):
- logging(
- code="1002",
- info="该标题已经被 kimi 处理过,跳过请求 kimi 操作--- {}".format(title),
- function="process",
- trace_id=trace_id
- )
- else:
- ask_kimi_and_save_to_local((title, trace_id, title_p))
- mq.send_msg(params=params)
- res = {
- "trace_id": trace_id,
- "code": 0
- }
- return jsonify(res)
- @my_blueprint.route('/out_videos', methods=['POST'])
- async def find_in_mysql():
- """
- 搜索是否存在外站视频 video_list, 如果存在,则返回成功
- :return:
- """
- data = await request.get_json()
- trace_id = data['traceId']
- logging(
- code="1001",
- info="请求接口成功",
- port="title_to_video",
- trace_id=data['traceId']
- )
- res = find_videos_in_mysql(trace_id=trace_id)
- return jsonify(res)
- @my_blueprint.route('/title_to_video', methods=['POST'])
- async def post_data():
- """
- 请求接口代码
- :return:
- """
- data = await request.get_json()
- trace_id = data['traceId']
- logging(
- code="1001",
- info="请求接口成功",
- port="title_to_video",
- trace_id=trace_id
- )
- p = ProcessParams(t_id=trace_id)
- processed_data = await p.deal(data)
- return jsonify(processed_data)
|