""" @author: luojunhui """ import asyncio from quart import Blueprint, jsonify, request from applications.functions.log import logging from applications.schedule import recall_videos from applications.deal import SearchDeal, ReSearchDeal my_blueprint = Blueprint('LongArticles', __name__) def Routes(mysql_client): """ 路由代码 """ @my_blueprint.route('/healthcheck') def healthcheck(): """ Hello World Test :return: """ return jsonify({'message': 'Hello, World!'}) @my_blueprint.route('/search_videos', methods=['POST']) async def search_videos_from_the_web(): """ 从web 搜索视频并且存储到票圈的视频库中 :return: """ params = await request.get_json() SD = SearchDeal(params=params, mysql_client=mysql_client) result = await SD.deal() return jsonify(result) @my_blueprint.route('/recall_videos', methods=['POST']) async def find_videos(): """ 请求接口代码 :return: """ data = await request.get_json() trace_id = data['traceId'] logging( code="1001", info="请求接口成功", port="recall_videos", trace_id=trace_id ) try: result = await recall_videos( trace_id=trace_id, mysql_client=mysql_client ) print(result) except Exception as e: result = { "traceId": trace_id, "error": str(e) } print(result) return jsonify(result) @my_blueprint.route('/re_search_videos', methods=['POST']) async def ree_search_videos(): """ 重新搜索 :return: """ params = await request.get_json() RSD = ReSearchDeal(params=params) res = await RSD.deal() return jsonify(res) return my_blueprint