fix hinting rate limit when scaping: add an option to use native api only

This commit is contained in:
John Xina 2023-07-14 19:10:45 +08:00
parent d3972baf1e
commit e4cfcd84ed
2 changed files with 11 additions and 2 deletions

12
app.py
View File

@ -136,8 +136,16 @@ async def forum_view():
sort = int(request.args.get('sort') or 0)
async with aiotieba.Client() as tieba:
forum_info, threads = await asyncio.gather(awaitify(find_tieba_info)(fname),
tieba.get_threads(fname, pn=pn, sort=sort))
if only_use_native_api:
forum_info, threads = await asyncio.gather(tieba.get_forum_detail(fname),
tieba.get_threads(fname, pn=pn, sort=sort))
forum_info = { 'avatar': 'a6efce1b9d16fdfa6291460ab98f8c5495ee7b51.jpg',
'topic': forum_info.post_num, 'thread': forum_info.post_num,
'member': forum_info.member_num, 'desc': '贴吧描述暂不可用', 'name': forum_info.fname }
else:
forum_info, threads = await asyncio.gather(awaitify(find_tieba_info)(fname),
tieba.get_threads(fname, pn=pn, sort=sort))
if threads.page.current_page > threads.page.total_page or pn < 1:
return await render_template('error.html', msg = \
f'请求越界,本贴吧共有 { threads.page.total_page }'

View File

@ -17,6 +17,7 @@ app = Flask(__name__)
app.config['SERVER_NAME'] = '127.0.0.1:8886'
should_fetch_comments = True
only_use_native_api = True
######################################################################