降低python版本依赖

This commit is contained in:
远野千束 2024-10-03 11:43:23 +08:00
parent b6f6eba1cf
commit eb6a57d5a7
2 changed files with 42 additions and 38 deletions

39
main.py
View File

@ -1,41 +1,4 @@
import sys
from server_status.api import *
from server_status.cmd_parser import server_status_alc
def main():
raw_msg = "server_status " + " ".join(sys.argv[1:])
arp = server_status_alc.parse(raw_msg)
if arp.query("run"):
sub_opts = arp.subcommands["run"].options
client = Client(
addr=arp["server"],
token=arp["token"],
client_id=arp["id"],
name=sub_opts["name"].args["name"],
location=sub_opts["location"].args["location"],
labels=sub_opts["labels"].args["labels"],
interval=sub_opts["interval"].args["interval"],
)
client.start()
elif arp.query("rm"):
client = Client(
addr=arp["server"],
token=arp["token"],
client_id=arp["id"],
)
resp = client.remove(arp["id"])
if resp.status_code == 200:
log("Host removed successfully")
else:
log(f"Failed to remove host: {resp.text}")
else:
log("Unknown command, use 'server_status --help' for help/未知命令或参数错误,请使用 'server_status --help' 获取帮助")
from server_status.__main__ import main
if __name__ == "__main__":
main()

41
server_status/__main__.py Normal file
View File

@ -0,0 +1,41 @@
import sys
from server_status.api import *
from server_status.cmd_parser import server_status_alc
def main():
raw_msg = "server_status " + " ".join(sys.argv[1:])
arp = server_status_alc.parse(raw_msg)
if arp.query("run"):
sub_opts = arp.subcommands["run"].options
client = Client(
addr=arp["server"],
token=arp["token"],
client_id=arp["id"],
name=sub_opts["name"].args["name"],
location=sub_opts["location"].args["location"],
labels=sub_opts["labels"].args["labels"],
interval=sub_opts["interval"].args["interval"],
)
client.start()
elif arp.query("rm"):
client = Client(
addr=arp["server"],
token=arp["token"],
client_id=arp["id"],
)
resp = client.remove(arp["id"])
if resp.status_code == 200:
log("Host removed successfully")
else:
log(f"Failed to remove host: {resp.text}")
else:
log("Unknown command, use 'server_status --help' for help/未知命令或参数错误,请使用 'server_status --help' 获取帮助")
if __name__ == "__main__":
main()