From b688062ca42b0991ab9b3ff5221633db0735cc01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=9F=E5=85=89-k?= <36470587+kxgx@users.noreply.github.com> Date: Mon, 13 Jan 2025 02:30:00 +0800 Subject: [PATCH] Update main.py --- bin/main.py | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/bin/main.py b/bin/main.py index 375bd30..7358946 100644 --- a/bin/main.py +++ b/bin/main.py @@ -66,25 +66,8 @@ def Memory_footprint():#显示内存占用百分比 return(subprocess.check_output(u"free -m | awk -F '[ :]+' 'NR==2{printf \"%d\", ($3)/$2*100}'", shell = True ).decode('gbk')) def CPU_usage(): #显示CPU占用百分比 return(str(int(float(os.popen("top -b -n1 | awk '/Cpu\(s\):/ {print $2}'").readline().strip())))) -def power_battery(): - try: - # 获取电池电量 - battery_percentage = subprocess.check_output( - "echo \"get battery\" | nc -q 0 127.0.0.1 8423 | awk -F':' '{print $2}'", - shell=True, - text=True - ).strip() - - # 检查电量信息 - if not battery_percentage: - return "无效" - - # 返回电量百分比 - return f"{int(battery_percentage)}%" - except Exception as e: - # 返回错误信息 - return "失败" - +def power_battery():#获取当前电池电量 + return(str(int(subprocess.check_output(u"echo \"get battery\" | nc -q 0 127.0.0.1 8423|awk -F':' '{print int($2)}'", shell = True ).decode('gbk')))+u'%') # 打印电量信息 print(power_battery()) def Bottom_edge(): #在图片中添加底边内容