diff --git a/app.py b/app.py index 21609b8a362f12af5f8ecbb3adaa67cc23aa6954..f39fbca6039b04ce3d7e3c643ef95b874bca9a69 100644 --- a/app.py +++ b/app.py @@ -147,7 +147,23 @@ async def forum_view(): @app.route('/home/main') async def user_view(): - return 'UNDER CONSTRUCTION' + pn = int(request.args.get('pn') or 1) + i = request.args.get('id') + try: # try converting it to user_id, otherwise using the string. + i = int(i) + except: + pass + + async with aiotieba.Client() as tieba: + try: + hp = await tieba.get_homepage(i, pn) + except ValueError: + return await render_template('error.html', msg='您已超过最后页') + + if len(hp[1]) == 0 and pn > 1: + return await render_template('error.html', msg='您已超过最后页') + + return await render_template('user.html', hp=hp, pn=pn) @app.route('/') async def main_view(): @@ -157,7 +173,7 @@ async def main_view(): @app.errorhandler(RuntimeError) async def runtime_error_view(e): - if e.msg: + if hasattr(e, 'msg'): return await render_template('error.html', msg=e.msg) return await render_template('error.html', msg='错误信息不可用') diff --git a/templates/bar.html b/templates/bar.html index df0d6c55b518af48648a7c2574b701c681165053..a9991451773f16b69d0ca1649800b6612d4dfd9a 100644 --- a/templates/bar.html +++ b/templates/bar.html @@ -85,7 +85,7 @@ </div> </div> <footer> - <div><a href="https://0xacab.org/johnxina/rat">RAT Ain't Tieba</a></div> + <div><a href="/">RAT Ain't Tieba</a></div> <div><a href="https://0xacab.org/johnxina/rat/-/blob/no-masters/LICENSE">自豪地以 AGPLv3 释出</a></div> <div><a href="https://0xacab.org/johnxina/rat">源代码</a></div> </footer> diff --git a/templates/error.html b/templates/error.html index 127e2ccbd9242948e8a494ff814376d3b0ee636d..12c461ddcee2d528acb58d4e027f9246e7453ecd 100644 --- a/templates/error.html +++ b/templates/error.html @@ -18,7 +18,7 @@ <h1>{{ msg }}</h1> </div> <footer> - <div><a href="https://0xacab.org/johnxina/rat">RAT Ain't Tieba</a></div> + <div><a href="/">RAT Ain't Tieba</a></div> <div><a href="https://0xacab.org/johnxina/rat/-/blob/no-masters/LICENSE">自豪地以 AGPLv3 释出</a></div> <div><a href="https://0xacab.org/johnxina/rat">源代码</a></div> </footer> diff --git a/templates/index.html b/templates/index.html index 4c028d905dbb412c525b045f5677eae23473b60c..54d7ccd23b4b5d756cda5fcb31e5451cb5e90a36 100644 --- a/templates/index.html +++ b/templates/index.html @@ -50,7 +50,7 @@ </form> </div> <footer> - <div><a href="https://0xacab.org/johnxina/rat">RAT Ain't Tieba</a></div> + <div><a href="/">RAT Ain't Tieba</a></div> <div><a href="https://0xacab.org/johnxina/rat/-/blob/no-masters/LICENSE">自豪地以 AGPLv3 释出</a></div> <div><a href="https://0xacab.org/johnxina/rat">源代码</a></div> </footer> diff --git a/templates/user.html b/templates/user.html new file mode 100644 index 0000000000000000000000000000000000000000..31ca312aa896b95eff9a0a1d5e5a3d8e43055a41 --- /dev/null +++ b/templates/user.html @@ -0,0 +1,64 @@ +<!DOCTYPE html> +<head> + <title>{{ hp[0].show_name }}的个人资料 - RAT</title> + + <meta charset="utf-8"> + <meta name="viewport" content="width=device-width, initial-scale=1"> + + <link href="/static/css/main.css" rel="stylesheet"> + + <style> + .thread { + border: solid; + border-color: var(--bg-color); + border-width: 0; + border-top-width: 5px; + border-bottom-width: 5px; + } + </style> +</head> + +<body> + <header class="bar-nav"> + <img src="/proxy/avatar/{{ hp[0].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="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> + </div> +</div> +</header> +<div class="list"> + {% for t in hp[1] %} + <div class="thread"> + <div class="summary"> + <a href="/p/{{ t.tid }}">{{ t.text }} </a> + </div> + </div> + {% endfor %} +</div> + <div class="paginator"> + {% if pn > 1 %} + <a href="/home/main?id={{ hp[0].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> + {% endif %} + {% endfor %} + + <a>{{ pn }}</a> + <a href="/home/main?id={{ hp[0].user_id }}&pn={{ pn+1 }}">下一页</a> + </div> +<footer> + <div><a href="/">RAT Ain't Tieba</a></div> + <div><a href="https://0xacab.org/johnxina/rat/-/blob/no-masters/LICENSE">自豪地以 AGPLv3 释出</a></div> + <div><a href="https://0xacab.org/johnxina/rat">源代码</a></div> +</footer> +</body>