""" 搜索API """ from flask import Blueprint from flask import request import api from huitun import HuiTunBrowser from util import lock_util from xhs import XhsBrowser from playwright.sync_api import Playwright, sync_playwright search_opt = Blueprint('search', __name__) @search_opt.route('/note', methods=["POST"]) def search_note(): """ 根据关键字搜索抖音笔记 :return: """ request_body = request.json playwright = sync_playwright().start() browser = HuiTunBrowser(lock_util.get_idle_phone('huitun'), playwright) result = browser.search_note(request_body.get('tagName'), request_body.get('searchLimit')) xhs_browser = XhsBrowser(lock_util.get_idle_phone('xhs'), playwright) result = xhs_browser.polish_huitun_note(result) playwright.stop() return api.success(result) @search_opt.route('/hot-tag-note', methods=["POST"]) def search_hot_tag_note(): """ 获取热门标签笔记 :return: """ request_body = request.json playwright = sync_playwright().start() browser = HuiTunBrowser(lock_util.get_idle_phone('huitun'), playwright) result = browser.search_note_by_hot_tag(int(request_body.get('searchLimit'))) xhs_browser = XhsBrowser(lock_util.get_idle_phone('xhs'), playwright) note_list = [item for sublist in result.get('tagNotes').values() for item in sublist] xhs_browser.polish_huitun_note(note_list) playwright.stop() return api.success(result) @search_opt.route('/note-info', methods=["POST"]) def search_note_info(): """ 根据笔记id获取笔记详情 :return: """ with sync_playwright() as playwright: request_body = request.json xhs_browser = XhsBrowser(lock_util.get_idle_phone('xhs'), playwright=playwright) xhs_browser.__init_browser__() note = xhs_browser.get_note(request_body.get('noteId')) return api.success(note)