Skip to content

Commit

Permalink
增加搜索方式
Browse files Browse the repository at this point in the history
  • Loading branch information
付伟 committed Jul 31, 2024
1 parent 566584c commit feccd36
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions service/xhs/views/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@
from ..logic import request_search
import random

async def search(keyword: str, offset: int = 0, limit: int = 20):
async def search(keyword: str, sort: str, offset: int = 0, limit: int = 20):
"""
获取笔记搜索
"sort": "time_descending", # 排序,general:默认, popularity_descending:最热, time_descending:最新
"""
_accounts = await accounts.load()
random.shuffle(_accounts)
for account in _accounts:
if account.get('expired', 0) == 1:
continue
account_id = account.get('id', '')
res = await request_search(keyword, account.get('cookie', ''), offset, limit)
logger.info(f'search success, account: {account_id}, keyword: {keyword}, offset: {offset}, limit: {limit}, res: {res}')
res = await request_search(keyword, account.get('cookie', ''), sort, offset, limit)
logger.info(f'search success, account: {account_id}, keyword: {keyword}, sort: {sort}, offset: {offset}, limit: {limit}, res: {res}')
return reply(ErrorCode.OK, '成功' , res)
logger.warning(f'search failed. keyword: {keyword}, offset: {offset}, limit: {limit}')
logger.warning(f'search failed. keyword: {keyword}, sort: {sort}, offset: {offset}, limit: {limit}')
return reply(ErrorCode.NO_ACCOUNT, '请先添加账号')

0 comments on commit feccd36

Please sign in to comment.