CrunchBang Linux Pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

CrunchBang Linux Pastebin

Posted by iggykoopa on Tue 20th Jan 03:26 (modification of post by view diff)
View followups from iggykoopa and Anonymous | diff | download | new post

  1. #!/usr/bin/env python
  2.  
  3. import os
  4.  
  5. rate = 0.0
  6. batteries = os.listdir("/proc/acpi/battery")
  7. if batteries:
  8.     batInfo = open("/proc/acpi/battery/%s/state" % (batteries[0],))
  9.     voltage = 0.0
  10.     watts_drawn = 0.0
  11.     amperes_drawn = 0.0
  12.     available = True
  13.     for line in batInfo:
  14.         if "charging state" in line:
  15.             if not "discharging" in line:
  16.                 available = False
  17.         if "present voltage" in line:
  18.             voltage = float(line.split()[2]) / 1000.0
  19.         if "present rate" in line and "mW" in line:
  20.             watts_drawn = float(line.split()[2]) / 1000.0
  21.         if "present rate" in line and "mA" in line:
  22.             amperes_drawn = float(line.split()[2]) / 1000.0
  23.     rate = watts_drawn + voltage * amperes_drawn
  24.     if available:
  25.         print rate
  26.     else:
  27.         print "No Data"
  28. else:
  29.     print "No Data"

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with @@


Remember me