diff --git a/app.py b/app.py index 21609b8..f39fbca 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 df0d6c5..a999145 100644 --- a/templates/bar.html +++ b/templates/bar.html @@ -85,7 +85,7 @@ diff --git a/templates/error.html b/templates/error.html index 127e2cc..12c461d 100644 --- a/templates/error.html +++ b/templates/error.html @@ -18,7 +18,7 @@

{{ msg }}

diff --git a/templates/index.html b/templates/index.html index 4c028d9..54d7ccd 100644 --- a/templates/index.html +++ b/templates/index.html @@ -50,7 +50,7 @@ diff --git a/templates/user.html b/templates/user.html new file mode 100644 index 0000000..31ca312 --- /dev/null +++ b/templates/user.html @@ -0,0 +1,64 @@ + + + {{ hp[0].show_name }}的个人资料 - RAT + + + + + + + + + + +
+ +
+
{{ hp[0].show_name }} {{ hp[0].user_name }}
+
{{ hp[0].sign }}
+
+ 关注数: {{ hp[0].follow_num|intsep }} + 粉丝数: {{ hp[0].fan_num|intsep }} + 发帖数: {{ hp[0].post_num|intsep }} + 关注贴吧数: {{ hp[0].forum_num|intsep }} +
+
+
+
+ {% for t in hp[1] %} +
+ +
+ {% endfor %} +
+
+ {% if pn > 1 %} + 首页 + {% endif %} + + {% for i in range(5) %} + {% set np = pn - 5 + i %} + {% if np > 0 %} + {{ np }} + {% endif %} + {% endfor %} + + {{ pn }} + 下一页 +
+ +