Created
October 29, 2024 14:11
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 ;)') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Battery Check
Show battery status every 5 seconds in text mode using a Linux distro equiped with "acpi" program.
Configuring the fisrt time
Usage
CTRL+C
to exit the script