Advertisement
Python253

batstats.go

May 6th, 2024
1,166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 2.37 KB | None | 0 0
  1. package main
  2.  
  3. import "fmt"
  4.  
  5. // Filename: batstats.go
  6. // Version: 1.0.0
  7. // Author: Jeoi Reqi
  8. // Tested on [GO v1.22] @ URL: https://go.dev/play/
  9.  
  10. // This script retrieves battery information.
  11. // It presents battery details like status and charge level clearly.
  12. // Users can quickly gauge battery health and make informed decisions about power usage.
  13.  
  14. // Requirements:
  15. //   - No external dependencies required.
  16.  
  17. // Usage:
  18. //   - Navigate to the directory containing this script in the terminal.
  19. //   - Run the script using the following command:
  20. //       './batstats'
  21.  
  22. // Example Output:
  23. //    --------------------------------------------------
  24. //            :: BATTERY STATS ::
  25. //    --------------------------------------------------
  26. //
  27. //    Internal Battery: [AP18E8M]    Status: OK
  28. //    Battery Status:                Connected to AC (2)
  29. //    Charge Remaining:              95%
  30. //
  31. //    --------------------------------------------------
  32.  
  33. func main() {
  34.     // Battery information
  35.     battery := map[string]interface{}{
  36.         "Caption":                 "Internal Battery",
  37.         "Name":                    "AP18E8M",
  38.         "Status":                  "OK",
  39.         "BatteryStatus":           2,
  40.         "EstimatedChargeRemaining": 95,
  41.     }
  42.  
  43.     // Dictionary to map battery status codes to their descriptions
  44.     batteryStatus := map[int]string{
  45.         1:  "Discharging",
  46.         2:  "Connected to AC",
  47.         3:  "Fully charged",
  48.         4:  "Low",
  49.         5:  "Critical",
  50.         6:  "Charging",
  51.         7:  "Charging/High",
  52.         8:  "Charging/Low",
  53.         9:  "Charging/Critical",
  54.         10: "Undefined",
  55.         11: "Partially Charged",
  56.     }
  57.  
  58.     // Get battery status description based on the status code
  59.     batteryStatusDescription := batteryStatus[battery["BatteryStatus"].(int)]
  60.  
  61.     // Print battery information header
  62.     fmt.Println(strings.Repeat("-", 50))
  63.     fmt.Println("\t\t:: BATTERY STATS ::")
  64.     fmt.Println(strings.Repeat("-", 50))
  65.  
  66.     // Print battery information
  67.     fmt.Printf("\n%s: [%s]\tStatus: %s\n", battery["Caption"], battery["Name"], battery["Status"])
  68.     fmt.Printf("Battery Status:                %s (%d)\n", batteryStatusDescription, battery["BatteryStatus"])
  69.     fmt.Printf("Charge Remaining:              %d%%\n", battery["EstimatedChargeRemaining"])
  70.     fmt.Println(strings.Repeat("-", 50))
  71. }
  72.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement