Skip to content

Instantly share code, notes, and snippets.

@ViniciusFM
Created October 29, 2024 14:11
Show Gist options
  • Save ViniciusFM/2bc68331145f93d94ac7f244621da3b5 to your computer and use it in GitHub Desktop.
Save ViniciusFM/2bc68331145f93d94ac7f244621da3b5 to your computer and use it in GitHub Desktop.
Show battery status every 5 seconds in text mode. Just run the script and press CTRL+C to leave.
#!/usr/bin/env python3
import subprocess
import time
SLEEPTIME = 5
def format(output):
out = output.decode('utf-8').split('\n')
return out[0].split(': ', 1)[1]
def call_acpi():
process = subprocess.Popen(['acpi', '-V'], stdout=subprocess.PIPE)
output, error = process.communicate()
return format(output)
if __name__ == '__main__':
try:
while True:
print(call_acpi()[:50], end=f'{" "*30}\r')
time.sleep(SLEEPTIME)
except KeyboardInterrupt:
print(' '*80, end='\r')
print('bye bye ;)')
@ViniciusFM
Copy link
Author

ViniciusFM commented Oct 29, 2024

Battery Check

Show battery status every 5 seconds in text mode using a Linux distro equiped with "acpi" program.

Configuring the fisrt time

  1. Change file to executable:
$ chmod +x ./battery.py

Usage

  1. Execute the script:
$ ./battery.py
  1. Press CTRL+C to exit the script

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment