routes.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. """
  2. @author: luojunhui
  3. """
  4. from quart import Blueprint, jsonify, request
  5. from applications.functions.log import logging
  6. from applications.schedule import recall_videos
  7. from applications.deal import SearchDeal2, ProcessDeal, RecallDeal
  8. my_blueprint = Blueprint('LongArticles', __name__)
  9. def Routes(mysql_client):
  10. """
  11. 路由代码
  12. """
  13. @my_blueprint.route('/healthcheck')
  14. def healthcheck():
  15. """
  16. Hello World Test
  17. :return:
  18. """
  19. return jsonify({'message': 'Hello, World!'})
  20. @my_blueprint.route('/search_videos', methods=['POST'])
  21. async def search_videos_from_the_web():
  22. """
  23. 从web 搜索视频并且存储到票圈的视频库中
  24. :return:
  25. """
  26. params = await request.get_json()
  27. SD = SearchDeal2(params=params, mysql_client=mysql_client)
  28. result = await SD.deal()
  29. return jsonify(result)
  30. @my_blueprint.route('/recall_videos', methods=['POST'])
  31. async def recall_results():
  32. """
  33. 获取视频分享卡片
  34. :return:
  35. """
  36. data = await request.get_json()
  37. trace_id = data['traceId']
  38. minigram_type = data['miniprogramUseType']
  39. RD = RecallDeal(trace_id=trace_id, mini_program_type=minigram_type, mysql_client=mysql_client)
  40. response = await RD.deal()
  41. return jsonify(response)
  42. # async def find_videos():
  43. # """
  44. # 请求接口代码
  45. # :return:
  46. # """
  47. # data = await request.get_json()
  48. # trace_id = data['traceId']
  49. # logging(
  50. # code="1001",
  51. # info="请求接口成功",
  52. # port="recall_videos",
  53. # trace_id=trace_id
  54. # )
  55. # try:
  56. # result = await recall_videos(
  57. # trace_id=trace_id,
  58. # mysql_client=mysql_client
  59. # )
  60. # print(result)
  61. # except Exception as e:
  62. # result = {
  63. # "traceId": trace_id,
  64. # "error": str(e)
  65. # }
  66. # print(result)
  67. # return jsonify(result)
  68. @my_blueprint.route("/task")
  69. async def schedule_task():
  70. """
  71. 执行代码
  72. :return:
  73. """
  74. PD = ProcessDeal(mysql_client=mysql_client)
  75. await PD.deal()
  76. return jsonify({"success": "true"})
  77. return my_blueprint