LOL服务器状态查询

import requests
import json
from rich.console import Console
from rich.table import Column, Table


ServerStatus = {
    'G': '正常',
    'Y': '拥挤',
    'R': '满载',
    'S': '维护',
    ' ': ' '
}
ServerInfo = {
    '1': '艾欧尼亚',
    '2': '比尔吉沃特',
    '14': '黑色玫瑰',
    '4': '诺克萨斯',
    '5': '班德尔城',
    '6': '德玛西亚',
    '7': '皮尔特沃夫',
    '8': '战争学院',
    '9': '弗雷尔卓德',
    '10': '巨神峰',
    '11': '雷瑟守备',
    '12': '无畏先锋',
    '13': '裁决之地',
    '3': '祖安',
    '15': '暗影岛',
    '16': '恕瑞玛',
    '17': '钢铁烈阳',
    '18': '水晶之痕',
    '19': '均衡教派',
    '20': '扭曲丛林',
    '21': '教育网专区',
    '22': '影流',
    '23': '守望之海',
    '24': '征服之海',
    '25': '卡拉曼达',
    '26': '巨龙之巢',
    '27': '皮城警备',
    '30': '男爵领域',
}


def get_s_s():
    url = 'https://serverstatus.native.qq.com/a20150326dqpd/a20150326dqpd/RetObj'
    result = requests.get(url).text
    res = json.loads(result.split('[', 1)[1].split(']', 1)[0].split('}', 1)[0] + '}')
    return res


def poc(res):
    console = Console()
    table = Table(show_header=True, header_style="bold magenta")
    table.add_column("服务器名称", style="dim", width=12, justify="center")
    table.add_column("状态", width=10, justify="center")

    for a in ServerInfo:
        if ServerStatus[res[a]] == '正常':
            table.add_row('[green]' + ServerInfo[a] + '[/green]', '[green]' + ServerStatus[res[a]] + '[/green]')
        if ServerStatus[res[a]] == '拥挤':
            table.add_row('[yellow]' + ServerInfo[a] + '[/yellow]', '[yellow]' + ServerStatus[res[a]] + '[/yellow]')
        if ServerStatus[res[a]] == '满载':
            table.add_row('[red]' + ServerInfo[a] + '[/red]', '[red]' + ServerStatus[res[a]] + '[/red]')
        if ServerStatus[res[a]] == '维护':
            table.add_row(ServerInfo[a], ServerStatus[res[a]])
    console.print(table)


if __name__ == '__main__':
    poc(get_s_s())
    input('             --Made By U')

标签: 莫得

文档最后编辑于3年前

评论

评论已关闭

小小英雄杜恩

子曰:“弟子入则孝,出则弟,谨而信,泛爱众,而亲仁。行有余力,则以学文。”


:D 获取中...