mirror of
https://0xacab.org/johnxina/rat.git
synced 2024-12-23 04:59:09 +00:00
Bump up the version of aiotieba to v4
This commit is contained in:
parent
ad9a02c613
commit
d63dc1bad4
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
17
app.py
17
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 }</a>'
|
||||
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):
|
||||
|
@ -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
|
||||
|
@ -1,6 +1,6 @@
|
||||
<!DOCTYPE html>
|
||||
<head>
|
||||
<title>{{ hp[0].show_name }}的个人资料 - RAT</title>
|
||||
<title>{{ hp.user.show_name }}的个人资料 - RAT</title>
|
||||
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
@ -20,20 +20,20 @@
|
||||
|
||||
<body>
|
||||
<header class="bar-nav">
|
||||
<img src="/proxy/avatar/{{ hp[0].portrait }}"></nav>
|
||||
<img src="/proxy/avatar/{{ hp.user.portrait }}"></nav>
|
||||
<div>
|
||||
<div class="title">{{ hp[0].show_name }} <small>{{ hp[0].user_name }}</small></div>
|
||||
<div class="description">{{ hp[0].sign }}</div>
|
||||
<div class="title">{{ hp.user.show_name }} <small>{{ hp.user.user_name }}</small></div>
|
||||
<div class="description">{{ hp.user.sign }}</div>
|
||||
<div class="stats">
|
||||
<small>关注数: {{ hp[0].follow_num|intsep }}</small>
|
||||
<small>粉丝数: {{ hp[0].fan_num|intsep }}</small>
|
||||
<small>发帖数: {{ hp[0].post_num|intsep }}</small>
|
||||
<small>关注贴吧数: {{ hp[0].forum_num|intsep }}</small>
|
||||
<small>关注数: {{ hp.user.follow_num|intsep }}</small>
|
||||
<small>粉丝数: {{ hp.user.fan_num|intsep }}</small>
|
||||
<small>发帖数: {{ hp.user.post_num|intsep }}</small>
|
||||
<small>关注贴吧数: {{ hp.user.forum_num|intsep }}</small>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
<div class="list">
|
||||
{% for t in hp[1] %}
|
||||
{% for t in hp.objs %}
|
||||
<div class="thread">
|
||||
<div class="summary">
|
||||
<a href="/p/{{ t.tid }}">{{ t.text }} </a>
|
||||
@ -43,18 +43,18 @@
|
||||
</div>
|
||||
<div class="paginator">
|
||||
{% if pn > 1 %}
|
||||
<a href="/home/main?id={{ hp[0].user_id }}&pn={{ 1 }}">首页</a>
|
||||
<a href="/home/main?id={{ hp.user.user_id }}&pn={{ 1 }}">首页</a>
|
||||
{% endif %}
|
||||
|
||||
{% for i in range(5) %}
|
||||
{% set np = pn - 5 + i %}
|
||||
{% if np > 0 %}
|
||||
<a href="/home/main?id={{ hp[0].user_id }}&pn={{ np }}">{{ np }}</a>
|
||||
<a href="/home/main?id={{ hp.user.user_id }}&pn={{ np }}">{{ np }}</a>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
<a>{{ pn }}</a>
|
||||
<a href="/home/main?id={{ hp[0].user_id }}&pn={{ pn+1 }}">下一页</a>
|
||||
<a href="/home/main?id={{ hp.user.user_id }}&pn={{ pn+1 }}">下一页</a>
|
||||
</div>
|
||||
<footer>
|
||||
<div><a href="/">RAT Ain't Tieba</a></div>
|
||||
|
Loading…
Reference in New Issue
Block a user