mirror of
https://0xacab.org/johnxina/rat.git
synced 2024-12-23 13:09:08 +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 .
|
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 port 8886
|
||||||
EXPOSE 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:
|
if frag.is_external:
|
||||||
markup += 'style="text-color: #ff0000;" '
|
markup += 'style="text-color: #ff0000;" '
|
||||||
else:
|
else:
|
||||||
url = frag.raw_url.lstrip('https://tieba.baidu.com')
|
url = frag.raw_url.path
|
||||||
markup += f'href="{ url }">{ frag.title }</a>'
|
markup += f'href="{ url }">{ frag.title }</a>'
|
||||||
htmlfmt = append_with_leading_clean(htmlfmt, markup)
|
htmlfmt = append_with_leading_clean(htmlfmt, markup)
|
||||||
elif isinstance(frag, FragAt):
|
elif isinstance(frag, FragAt):
|
||||||
@ -162,6 +162,9 @@ async def thread_view(tid):
|
|||||||
with_comments=should_fetch_comments,
|
with_comments=should_fetch_comments,
|
||||||
only_thread_author=ao)
|
only_thread_author=ao)
|
||||||
|
|
||||||
|
if thread_info.err:
|
||||||
|
return await runtime_error_view(thread_info.err)
|
||||||
|
|
||||||
available_users = []
|
available_users = []
|
||||||
for floor in thread_info:
|
for floor in thread_info:
|
||||||
for comment in floor.comments:
|
for comment in floor.comments:
|
||||||
@ -188,6 +191,12 @@ async def forum_view():
|
|||||||
async with aiotieba.Client() as tieba:
|
async with aiotieba.Client() as tieba:
|
||||||
forum_info, threads = await asyncio.gather(tieba.get_forum_detail(fname),
|
forum_info, threads = await asyncio.gather(tieba.get_forum_detail(fname),
|
||||||
tieba.get_threads(fname, pn=pn, sort=sort))
|
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'):
|
if hasattr(forum_info, 'slogan'):
|
||||||
forum_info = { 'avatar': extract_image_name(forum_info.origin_avatar),
|
forum_info = { 'avatar': extract_image_name(forum_info.origin_avatar),
|
||||||
'topic': forum_info.post_num, 'thread': forum_info.post_num,
|
'topic': forum_info.post_num, 'thread': forum_info.post_num,
|
||||||
@ -217,10 +226,12 @@ async def user_view():
|
|||||||
async with aiotieba.Client() as tieba:
|
async with aiotieba.Client() as tieba:
|
||||||
try:
|
try:
|
||||||
hp = await tieba.get_homepage(i, pn)
|
hp = await tieba.get_homepage(i, pn)
|
||||||
|
if hp.err:
|
||||||
|
return await runtime_error_view(hp.err)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
return await render_template_c('error.html', msg='您已超过最后页')
|
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('error.html', msg='您已超过最后页')
|
||||||
|
|
||||||
return await render_template_c('user.html', hp=hp, pn=pn)
|
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):
|
async def runtime_error_view(e):
|
||||||
if hasattr(e, 'msg'):
|
if hasattr(e, 'msg'):
|
||||||
return await render_template_c('error.html', msg=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)
|
@app.errorhandler(Exception)
|
||||||
async def general_error_view(e):
|
async def general_error_view(e):
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
aioflask
|
aioflask
|
||||||
flask==2.1.3
|
flask==2.1.3
|
||||||
Werkzeug==2.2.2
|
Werkzeug==2.2.2
|
||||||
aiotieba
|
aiotieba>=4.0.0,<5.0.0
|
||||||
aiohttp
|
aiohttp
|
||||||
uvicorn[standard]
|
uvicorn[standard]
|
||||||
gunicorn
|
gunicorn
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<head>
|
<head>
|
||||||
<title>{{ hp[0].show_name }}的个人资料 - RAT</title>
|
<title>{{ hp.user.show_name }}的个人资料 - RAT</title>
|
||||||
|
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
@ -20,20 +20,20 @@
|
|||||||
|
|
||||||
<body>
|
<body>
|
||||||
<header class="bar-nav">
|
<header class="bar-nav">
|
||||||
<img src="/proxy/avatar/{{ hp[0].portrait }}"></nav>
|
<img src="/proxy/avatar/{{ hp.user.portrait }}"></nav>
|
||||||
<div>
|
<div>
|
||||||
<div class="title">{{ hp[0].show_name }} <small>{{ hp[0].user_name }}</small></div>
|
<div class="title">{{ hp.user.show_name }} <small>{{ hp.user.user_name }}</small></div>
|
||||||
<div class="description">{{ hp[0].sign }}</div>
|
<div class="description">{{ hp.user.sign }}</div>
|
||||||
<div class="stats">
|
<div class="stats">
|
||||||
<small>关注数: {{ hp[0].follow_num|intsep }}</small>
|
<small>关注数: {{ hp.user.follow_num|intsep }}</small>
|
||||||
<small>粉丝数: {{ hp[0].fan_num|intsep }}</small>
|
<small>粉丝数: {{ hp.user.fan_num|intsep }}</small>
|
||||||
<small>发帖数: {{ hp[0].post_num|intsep }}</small>
|
<small>发帖数: {{ hp.user.post_num|intsep }}</small>
|
||||||
<small>关注贴吧数: {{ hp[0].forum_num|intsep }}</small>
|
<small>关注贴吧数: {{ hp.user.forum_num|intsep }}</small>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
<div class="list">
|
<div class="list">
|
||||||
{% for t in hp[1] %}
|
{% for t in hp.objs %}
|
||||||
<div class="thread">
|
<div class="thread">
|
||||||
<div class="summary">
|
<div class="summary">
|
||||||
<a href="/p/{{ t.tid }}">{{ t.text }} </a>
|
<a href="/p/{{ t.tid }}">{{ t.text }} </a>
|
||||||
@ -43,18 +43,18 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="paginator">
|
<div class="paginator">
|
||||||
{% if pn > 1 %}
|
{% 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 %}
|
{% endif %}
|
||||||
|
|
||||||
{% for i in range(5) %}
|
{% for i in range(5) %}
|
||||||
{% set np = pn - 5 + i %}
|
{% set np = pn - 5 + i %}
|
||||||
{% if np > 0 %}
|
{% 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 %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
<a>{{ pn }}</a>
|
<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>
|
</div>
|
||||||
<footer>
|
<footer>
|
||||||
<div><a href="/">RAT Ain't Tieba</a></div>
|
<div><a href="/">RAT Ain't Tieba</a></div>
|
||||||
|
Loading…
Reference in New Issue
Block a user