From e4cfcd84edeaa432019058bc9330d56fea307437 Mon Sep 17 00:00:00 2001 From: John Xina Date: Fri, 14 Jul 2023 19:10:45 +0800 Subject: [PATCH] fix hinting rate limit when scaping: add an option to use native api only --- app.py | 12 ++++++++++-- shared.py | 1 + 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app.py b/app.py index f39fbca..0e5d252 100644 --- a/app.py +++ b/app.py @@ -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 } 页' diff --git a/shared.py b/shared.py index f0b0f98..f954354 100644 --- a/shared.py +++ b/shared.py @@ -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 ######################################################################