Using Python to access battery status in Ubuntu

I am trying to exit with a small python script to monitor the battery status of my ubuntu laptop and sound alerts if it is not charging, as well as do other things (e.g. pause, etc.). I really don't know where to start, and would like to know if there is any python library that I can use. Any help would be greatly appreciated. Thanks

+4
source share
4 answers

I believe that you can find the information you are looking for in

/sys/class/power_supply/BAT0 
+12
source
+2
source

The "powerful" pypi library is a good bet, it is also a cross-platform.

0
source

You do not need to use any module for this.

You can just go to

/ Sys / class / power_supply / bat0.

Here you will find many files with information about your battery. You will receive the current charge in the charge_now file and the total charge in the charge_full file. Then you can calculate the percentage of battery using math.

Note: - You may need root access for this. You can use the sudo nautilus command to open directories in root mode.

0
source

Source: https://habr.com/ru/post/1482235/


All Articles