dwmstat.py

#!/usr/bin/python

###
### dwmstat.py - Rick Rein 
### 2 April 2008
### Let me know if you read these silly things
###
### Gets ACPI battery status for display in DWM (or stdout) and 
### displays a clock
###     Display:
###        a100% - AC power fully charged
###        01:20b70% - 1 hour 20 min left on 70% battery power
###        00:30r85% - 0 hours and 35 min to recharge a 85% battery
###

import commands, string, time
### sets the seperator between bat and clock
decer = '] ::'

charge = commands.getstatusoutput('acpi -ba')
c= charge[1].split()
test = c[2]
perc = c[3].replace(",", "")

### Yes this is inefficient, but it makes the 
### printed text look prettier below. 

if ( c[4] == 'remaining' ):
	t = ' '
elif ( c[2] == "discharging," ): 
	tm = c[4].split(':')
	t = tm[0] + ":" + tm[1]
else:
	t = ' '

###
### Begin the output tests
###

if ( test == "charged," ):
	print "[ a" + perc,
if ( test == "discharging,"):
	if (t == 'remaining' ):
		print '[ bat.' + perc,
	else:
		print "[ " + t + "b" + perc,
if ( test == "charging,"):
	if ( c[6] == "zero" ):
		print "[ a" + perc,
	else:
		tm = c[4].split(':')
		t = tm[0] + ":" + tm[1]
		print "[ " + t + "r" + perc,
print decer, 
print time.strftime("[ %a %b.%d ][ %I:%M %p ]")