""" @author: luojunhui """ import json import time import uuid from quart import Blueprint, jsonify, request from applications.functions.log import logging from applications.schedule import ProcessParams, search_videos from applications.functions.common import MySQLServer from applications.functions.kimi import KimiServer from applications.schedule.main_schedule import AskForInfo my_blueprint = Blueprint('kimi', __name__) @my_blueprint.route('/healthcheck') def hello(): """ Hello World Test :return: """ logging( code="1001", info="请求接口成功", port="healthcheck" ) return jsonify({'message': 'Hello, World!'}) @my_blueprint.route('/title_to_search', methods=['POST']) async def search_videos_from_the_web(): """ 从web 搜索视频并且存储到票圈的视频库中 :return: """ params = await request.get_json() K = KimiServer() gh_id = params['ghId'] trace_id = "search-{}-{}".format(str(uuid.uuid4()), str(int(time.time()))) params['trace_id'] = trace_id logging( code="2000", info="搜索视频内容接口请求成功", port="title_to_search", function="search_videos_from_the_web", trace_id=trace_id ) try: kimi_info = await K.search_kimi_schedule(params=params) video_id, video_url = await search_videos( kimi_info=kimi_info, trace_id=trace_id, gh_id=gh_id ) print(json.dumps(kimi_info, ensure_ascii=False, indent=4)) res = { "trace_id": trace_id, "code": 0, "kimi_title": kimi_info['k_title'], "search_video_id": video_id, "video_url": video_url } except Exception as e: res = { "trace_id": trace_id, "code": 1, "message": str(e) } 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="2000", info="请求接口成功", port="title_to_video", trace_id=trace_id, function="find_in_mysql" ) res = MySQLServer().select_download_videos(trace_id=trace_id) return jsonify(res) @my_blueprint.route('/find_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) @my_blueprint.route('/title_to_video', methods=['POST']) async def delay_response(): """ main :return: """ # 从请求体中解析 JSON 数据 data = await request.get_json() A = AskForInfo(data) res = await A.schedule() return jsonify(res)