-3

I use a Lenovo Thinkpad and need a python program that can get me my laptop's charging percentage.

For Example: 74%, 98%, 16%

I've searched around but can't seem to find exactly what I need

Can anyone help?

Ultra
  • 51
  • 1
  • 9
  • [Does this answer your question?](https://stackoverflow.com/questions/16380394/getting-battery-capacity-windows-with-python) – Roland Deschain Jul 18 '20 at 09:46
  • Does this answer your question? [Getting Battery Capacity Windows with Python](https://stackoverflow.com/questions/16380394/getting-battery-capacity-windows-with-python) – Gino Mempin Jul 18 '20 at 11:20

2 Answers2

1

You can get remaining time as follows:

import psutil as ps
batterystats = dict(ps.sensors_battery()._asdict())
print(batterystats)
timeleft = batterystats.get('secsleft')
percent = batterystats.get('percent')

print('battery percent : '+str(percent)+'%')
print('time left (secs) : '+str(timeleft)+' secs')

The answer is in seconds you can convert it though.

Sashank
  • 557
  • 6
  • 20
0
import  psutil

print ("battery charge left: " + str(psutil.sensors_battery()[0]) + "%")

output

battery charge left: 95%
Thulfiqar
  • 393
  • 7
  • 14