diff --git a/Dockerfile b/Dockerfile index 33820b7..1e00a69 100644 --- a/Dockerfile +++ b/Dockerfile @@ -21,14 +21,6 @@ RUN pip install -r requirements.txt COPY aiotieba-handle-exception-expose.patch . -# Replace paths in the patch file to reflect the correct paths within the container -RUN sed -i 's|venv/lib/python3.11/site-packages/|/usr/local/lib/python3.11/site-packages/|g' aiotieba-handle-exception-expose.patch - - -# Apply the patch using the 'patch' command -RUN patch -d/ -p0 < aiotieba-handle-exception-expose.patch - - # Expose port 8886 EXPOSE 8886 diff --git a/aiotieba-handle-exception-expose.patch b/aiotieba-handle-exception-expose.patch deleted file mode 100644 index fccda4b..0000000 --- a/aiotieba-handle-exception-expose.patch +++ /dev/null @@ -1,40 +0,0 @@ ---- venv/lib/python3.11/site-packages/aiotieba/helper/utils.py -+++ venv/lib/python3.11/site-packages/aiotieba/helper/utils.py -@@ -141,35 +141,6 @@ - - def wrapper(func): - async def awrapper(*args, **kwargs): -- try: -- ret = await func(*args, **kwargs) -- -- except Exception as err: -- meth_name = func.__name__ -- tb = err.__traceback__ -- while tb := tb.tb_next: -- frame = tb.tb_frame -- if frame.f_code.co_name == meth_name: -- break -- frame = tb.tb_next.tb_frame -- -- log_str: str = frame.f_locals.get('__log__', '') -- if not no_format: # need format -- log_str = log_str.format(**frame.f_locals) -- log_str = f"{err}. {log_str}" -- -- logger = get_logger() -- if logger.isEnabledFor(log_level): -- record = logger.makeRecord(logger.name, log_level, None, 0, log_str, None, None, meth_name) -- logger.handle(record) -- -- exc_handlers._handle(meth_name, err) -- -- return null_ret_factory() -- -- else: -- return ret -- -+ return await func(*args, **kwargs) - return awrapper -- - return wrapper - diff --git a/app.py b/app.py index 02b09c0..6fee98f 100644 --- a/app.py +++ b/app.py @@ -132,7 +132,7 @@ async def _jinja2_filter_translate(frags, reply_id=0): if frag.is_external: markup += 'style="text-color: #ff0000;" ' else: - url = frag.raw_url.lstrip('https://tieba.baidu.com') + url = frag.raw_url.path markup += f'href="{ url }">{ frag.title }' htmlfmt = append_with_leading_clean(htmlfmt, markup) elif isinstance(frag, FragAt): @@ -162,6 +162,9 @@ async def thread_view(tid): with_comments=should_fetch_comments, only_thread_author=ao) + if thread_info.err: + return await runtime_error_view(thread_info.err) + available_users = [] for floor in thread_info: for comment in floor.comments: @@ -188,6 +191,12 @@ async def forum_view(): async with aiotieba.Client() as tieba: forum_info, threads = await asyncio.gather(tieba.get_forum_detail(fname), tieba.get_threads(fname, pn=pn, sort=sort)) + if threads.err: + return await runtime_error_view(threads.err) + elif forum_info.err: + return await runtime_error_view(forum_info.err) + + if hasattr(forum_info, 'slogan'): forum_info = { 'avatar': extract_image_name(forum_info.origin_avatar), 'topic': forum_info.post_num, 'thread': forum_info.post_num, @@ -217,10 +226,12 @@ async def user_view(): async with aiotieba.Client() as tieba: try: hp = await tieba.get_homepage(i, pn) + if hp.err: + return await runtime_error_view(hp.err) except ValueError: return await render_template_c('error.html', msg='您已超过最后页') - if len(hp[1]) == 0 and pn > 1: + if not hp.objs and pn > 1: return await render_template_c('error.html', msg='您已超过最后页') return await render_template_c('user.html', hp=hp, pn=pn) @@ -235,7 +246,7 @@ async def main_view(): async def runtime_error_view(e): if hasattr(e, 'msg'): return await render_template_c('error.html', msg=e.msg) - return await render_template_c('error.html', msg='错误信息不可用') + return await render_template_c('error.html', msg=str(e) or '错误信息不可用') @app.errorhandler(Exception) async def general_error_view(e): diff --git a/requirements.txt b/requirements.txt index cd37921..405d31d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,7 @@ aioflask flask==2.1.3 Werkzeug==2.2.2 -aiotieba +aiotieba>=4.0.0,<5.0.0 aiohttp uvicorn[standard] gunicorn diff --git a/templates/user.html b/templates/user.html index 31ca312..3663d11 100644 --- a/templates/user.html +++ b/templates/user.html @@ -1,6 +1,6 @@ - {{ hp[0].show_name }}的个人资料 - RAT + {{ hp.user.show_name }}的个人资料 - RAT @@ -20,20 +20,20 @@
- +
-
{{ hp[0].show_name }} {{ hp[0].user_name }}
-
{{ hp[0].sign }}
+
{{ hp.user.show_name }} {{ hp.user.user_name }}
+
{{ hp.user.sign }}
- 关注数: {{ hp[0].follow_num|intsep }} - 粉丝数: {{ hp[0].fan_num|intsep }} - 发帖数: {{ hp[0].post_num|intsep }} - 关注贴吧数: {{ hp[0].forum_num|intsep }} + 关注数: {{ hp.user.follow_num|intsep }} + 粉丝数: {{ hp.user.fan_num|intsep }} + 发帖数: {{ hp.user.post_num|intsep }} + 关注贴吧数: {{ hp.user.forum_num|intsep }}
- {% for t in hp[1] %} + {% for t in hp.objs %}
{{ t.text }} @@ -43,18 +43,18 @@
{% if pn > 1 %} - 首页 + 首页 {% endif %} {% for i in range(5) %} {% set np = pn - 5 + i %} {% if np > 0 %} - {{ np }} + {{ np }} {% endif %} {% endfor %} {{ pn }} - 下一页 + 下一页