search.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. """
  2. 搜索API
  3. """
  4. from flask import Blueprint
  5. from flask import request
  6. import api
  7. from huitun import HuiTunBrowser
  8. from util import lock_util
  9. from xhs import XhsBrowser
  10. from playwright.sync_api import Playwright, sync_playwright
  11. search_opt = Blueprint('search', __name__)
  12. @search_opt.route('/note', methods=["POST"])
  13. def search_note():
  14. """
  15. 根据关键字搜索抖音笔记
  16. :return:
  17. """
  18. request_body = request.json
  19. playwright = sync_playwright().start()
  20. browser = HuiTunBrowser(lock_util.get_idle_phone('huitun'), playwright)
  21. result = browser.search_note(request_body.get('tagName'), request_body.get('searchLimit'))
  22. xhs_browser = XhsBrowser(lock_util.get_idle_phone('xhs'), playwright)
  23. result = xhs_browser.polish_huitun_note(result)
  24. playwright.stop()
  25. return api.success(result)
  26. @search_opt.route('/hot-tag-note', methods=["POST"])
  27. def search_hot_tag_note():
  28. """
  29. 获取热门标签笔记
  30. :return:
  31. """
  32. request_body = request.json
  33. playwright = sync_playwright().start()
  34. browser = HuiTunBrowser(lock_util.get_idle_phone('huitun'), playwright)
  35. result = browser.search_note_by_hot_tag(int(request_body.get('searchLimit')))
  36. playwright.stop()
  37. return api.success(result)
  38. @search_opt.route('/note-info', methods=["POST"])
  39. def search_note_info():
  40. """
  41. 根据笔记id获取笔记详情
  42. :return:
  43. """
  44. with sync_playwright() as playwright:
  45. request_body = request.json
  46. xhs_browser = XhsBrowser(lock_util.get_idle_phone('xhs'), playwright=playwright)
  47. xhs_browser.__init_browser__()
  48. note = xhs_browser.get_note(request_body.get('noteId'))
  49. return api.success(note)