Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- # Filename: batstats.py
- # Version: 1.0.0
- # Author: Jeoi Reqi
- """
- This script retrieves battery information using the wmi module.
- It's designed for Windows, requiring Python 3.x and wmi.
- The script presents battery details like status and charge level clearly.
- Users can quickly gauge battery health and make informed decisions about power usage.
- Requirements:
- - Python 3.x
- - wmi module
- Usage:
- - Before running the script, ensure you have Python installed on your system.
- - Make sure the `wmi` module is installed. You can install it using pip:
- 'pip install wmi'
- - Navigate to the directory containing this script in the terminal.
- - Run the script using the following command:
- 'python batstats.py'
- Example Output:
- --------------------------------------------------
- :: BATTERY STATS ::
- --------------------------------------------------
- Internal Battery: [AP18E8M] Status: OK
- Battery Status: Connected to AC (2)
- Charge Remaining: 95%
- --------------------------------------------------
- """
- import wmi
- # Initialize WMI interface
- c = wmi.WMI()
- # Get battery information
- battery = c.Win32_Battery()[0]
- # Dictionary to map battery status codes to their descriptions
- battery_status = {
- 1: 'Discharging',
- 2: 'Connected to AC',
- 3: 'Fully charged',
- 4: 'Low',
- 5: 'Critical',
- 6: 'Charging',
- 7: 'Charging/High',
- 8: 'Charging/Low',
- 9: 'Charging/Critical',
- 10: 'Undefined',
- 11: 'Partially Charged'
- }
- # Get battery status description based on the status code
- battery_status_description = battery_status.get(battery.BatteryStatus, 'Unknown')
- # Print battery information header
- print("-" * 50)
- print("\t\t:: BATTERY STATS ::")
- print("-" * 50)
- # Print battery information
- print(f"\n{battery.Caption}: [{battery.Name}] Status: {battery.Status}")
- print(f"Battery Status: {battery_status_description} ({battery.BatteryStatus})")
- print(f"Charge Remaining: {battery.EstimatedChargeRemaining}%\n")
- print("-" * 50)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement