#Julian Oliver 2005
#script to let you know when you're lappy battery is down and out.

import os, string, time
start = os.popen("date +%H%M").read()
b = open('/home/delire/dacpi.log', 'w')
b.write(str("start: ") +str(start))
b.close()

while 1:
		
	time.sleep(10)
	
	state = open('/proc/acpi/battery/BAT0/state').readlines()
	info = open('/proc/acpi/battery/BAT0/info').readlines()
	remaining = int((str((str(state[4:5]).split())[2:3]))[2:-2])
	lastFull = int((str((str(info[2:3]).split())[3:4]))[2:-2])
	used = int(remaining/float(lastFull)*100)
	
	if used <=10:
		os.popen('play /path/to/a/sound.wav')
		#if you're lucky enough to have a beepable speaker
		# os.popen('beep -f 300.7 -r 2 -d 100 -l 400')
	if used <=1:
		end = os.popen("date +%H%M").read()
		total = [int(str(end)[:2])-int(str(start)[:2]), int(str(end)[2:])-int(str(start)[2:])]
		b = open('~/dacpi.log', 'w')
		b.write(str("total time was: " +str(total[0]) +" hours and " +str(total[1]) +" minutes"))
		b.close()
