routes.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. """
  2. @author: luojunhui
  3. """
  4. import asyncio
  5. from quart import Blueprint, jsonify, request
  6. from applications.functions.log import logging
  7. from applications.schedule import recall_videos
  8. from applications.deal import SearchDeal, ReSearchDeal
  9. my_blueprint = Blueprint('LongArticles', __name__)
  10. def Routes(mysql_client):
  11. """
  12. 路由代码
  13. """
  14. @my_blueprint.route('/healthcheck')
  15. def healthcheck():
  16. """
  17. Hello World Test
  18. :return:
  19. """
  20. return jsonify({'message': 'Hello, World!'})
  21. @my_blueprint.route('/search_videos', methods=['POST'])
  22. async def search_videos_from_the_web():
  23. """
  24. 从web 搜索视频并且存储到票圈的视频库中
  25. :return:
  26. """
  27. params = await request.get_json()
  28. SD = SearchDeal(params=params, mysql_client=mysql_client)
  29. result = await SD.deal()
  30. return jsonify(result)
  31. @my_blueprint.route('/recall_videos', methods=['POST'])
  32. async def find_videos():
  33. """
  34. 请求接口代码
  35. :return:
  36. """
  37. data = await request.get_json()
  38. trace_id = data['traceId']
  39. logging(
  40. code="1001",
  41. info="请求接口成功",
  42. port="recall_videos",
  43. trace_id=trace_id
  44. )
  45. try:
  46. result = await recall_videos(
  47. trace_id=trace_id,
  48. mysql_client=mysql_client
  49. )
  50. print(result)
  51. except Exception as e:
  52. result = {
  53. "traceId": trace_id,
  54. "error": str(e)
  55. }
  56. print(result)
  57. return jsonify(result)
  58. @my_blueprint.route('/re_search_videos', methods=['POST'])
  59. async def ree_search_videos():
  60. """
  61. 重新搜索
  62. :return:
  63. """
  64. params = await request.get_json()
  65. RSD = ReSearchDeal(params=params)
  66. res = await RSD.deal()
  67. return jsonify(res)
  68. return my_blueprint