做了一个极其简陋网页版查询Linuxdo等级等信息(附上源码)

在线查询:https://linuxdo.1124.eu.org/


源码

from flask import Flask, request, render_template
import requests
from datetime import datetime
import pytz

app = Flask(__name__)

def get_info(username):
    url = f"https://linux.do/u/{username}.json"
    response = requests.get(url)
    if response.status_code == 200:
        data = response.json()
        if "user" in data:
            return data["user"]
    return None

def convert_to_shanghai_time(utc_time_str):
    utc_time = datetime.strptime(utc_time_str, "%Y-%m-%dT%H:%M:%S.%fZ")
    utc_time = pytz.utc.localize(utc_time)
    shanghai_time = utc_time.astimezone(pytz.timezone("Asia/Shanghai"))
    return shanghai_time.strftime("%Y-%m-%d %H:%M:%S")

@app.route('/', methods=['GET', 'POST'])
def index():
    if request.method == 'POST':
        username = request.form.get('username')
        user = get_info(username)
        if user is not None:
            keys_to_print = ["username", "last_posted_at", "last_seen_at", "created_at", "time_read", "groups", "trust_level"]
            chinese_keys = ["用户名", "最后发帖时间", "最后在线时间", "创建时间", "阅读时间", "组", "信任等级"]
            result = {}
            for key, chinese_key in zip(keys_to_print, chinese_keys):
                if key in user:
                    if key in ["last_posted_at", "last_seen_at", "created_at"]:
                        result[chinese_key] = convert_to_shanghai_time(user[key])
                    else:
                        result[chinese_key] = user[key]
            return render_template('result.html', result=result)
        else:
            return "获取信息失败"
    return render_template('index.html')

if __name__ == '__main__':
    app.run(debug=True)

templates:

#######index.html

<!DOCTYPE html>
<html>
<head>
    <title>用户信息查询</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 0;
            padding: 0;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            background-color: #f0f0f0;
        }
        form {
            background-color: #fff;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);
        }
        input[type="text"] {
            width: 90%;
            padding: 10px;
            margin-bottom: 10px;
            border-radius: 4px;
            border: 1px solid #ddd;
        }
        input[type="submit"] {
            padding: 10px 20px;
            border: none;
            border-radius: 4px;
            background-color: #007BFF;
            color: #fff;
            cursor: pointer;
        }
        input[type="submit"]:hover {
            background-color: #0056b3;
        }
    </style>
</head>
<body>
    <form method="POST">
        <label for="username">请输入要查询的用户名:</label>
        <input type="text" id="username" name="username">
        <input type="submit" value="查询">
    </form>
</body>
</html>
######result.html
<!DOCTYPE html>
<html>
<head>
    <title>查询结果</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 0;
            padding: 0;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            background-color: #f0f0f0;
        }
        table {
            border-collapse: collapse;
            width: 50%;
        }
        th, td {
            border: 1px solid #ddd;
            padding: 8px;
            text-align: left;
        }
        th {
            background-color: #4CAF50;
            color: white;
        }
    </style>
</head>
<body>
    <table>
        <tr>
            <th>信息</th>
            <th>值</th>
        </tr>
        {% for key, value in result.items() %}
        <tr>
            <td>{{ key }}</td>
            <td>{{ value }}</td>
        </tr>
        {% endfor %}
    </table>
</body>
</html>
13 个赞

辛苦了

1 个赞

大佬,手下我的膝盖,做个tg的机器人吧,还有怎么能看,我还有多久可以升到3级呢?除了用管理账号查看,能把这个功能也做出来就666了

1 个赞

赞,不过查询速度有点慢

5 个赞

可以使用,赞

1 个赞

脚本方便些

1 个赞

厉害

1 个赞

辛苦

1 个赞

膜拜大佬

2 个赞

虽然用了油猴,但是也感谢分享

1 个赞

把查询功能应用到tg bot中 简单写了一个

1 个赞

查询 500 了

1 个赞