监控设备电池电量并发送通知 - Python
一个小程序,监控设备的电池电量并发送通知。
# 需要用到三个库psutil, py-notifier和win10toast,都用pip安装 # pip install psutil # pip install py-notifier # pip install win10toast import psutil from pynotifier import Notification battery = psutil.sensors_battery() # 获取电池笔记本电池的参数,一般是percent=70, secsleft=9465, power_plugged=False # print(battery) plugged = battery.power_plugged # 查看是否有外接电源 # print(plugged) # False percent = battery.percent # 查看电池剩余量 # print(percent) if percent >= 30: Notification( title="Battery Low", description=str(percent) + " Battery remains!", duration=5, # urgency='normal', # 正常提示,windows一般在右下角 urgency='URGENCY_CRITICAL', ).send()
做完这个程序,终于找到国内某知名卫士啊,某宝啊,某东啊,某讯等的右下角恶意弹窗是怎么来的了,其实就是调用了windows的通知模块儿。一万只草泥马加两根中指送给这些万恶的资本主义。