my net house

WAHEGURU….!

Python battery saver pack?

I was not aware that sometimes a good suggestion can also lead to good work. It just happened with me. As I posted on GD(a group of people who never want to grow up in terms of limited thinking I mean free thinkers 😉 ). I am able to write a python script which uses acpi to check battery status and tells the user how to keep battery last long. This is not my personal feeling ;). Here is the article about it.http://www.wired.com/2013/09/laptop-battery/

This is just a small try to improve battery life cycle. As I said this script uses acpi module so to run the script properly you need to install acpi-python module first from here https://github.com/ltworf/python-acpi

The script is following:


import os
import sys
import time
import acpi
import re
import webbrowser
def restart():
	a=str(acpi.acpi());
	print a;
	val=40;
	val2=90;
	match=re.search(r'(,)?40(,)?',a);
	match2=re.search(r'(,)?80(,)?',a);

	if match:
		print "You need Charging";
		webbrowser.open('https://arshpreetsingh.wordpress.com/');	
		time.sleep(30);
		checkcharging();
			
	if match2:
		print "You need to remove AC Adapter. Your battery is more than 80%";
		webbrowser.open('https://arshpreetsingh.wordpress.com/');	
		time.sleep(30);
		checkdischarging();
		
	else:
		time.sleep(20);
		print "safe";
		reset();
		
def checkcharging():
	a=str(acpi.acpi());
	match3=re.search('Charging',a);
	if match3:
		time.sleep(500);
		reset();
	else:
		print "You need Charging";
		webbrowser.open('https://arshpreetsingh.wordpress.com/');	
		time.sleep(30);
		checkcharging();

		
def checkdischarging():
	a=str(acpi.acpi());
	match4=re.search('Discharging',a);
	if match4:
		time.sleep(500);
		reset();
	else:
		print "You need to remove AC Adapter. Your battery is more than 80%";
		webbrowser.open('https://arshpreetsingh.wordpress.com/');	
		time.sleep(30);
		checkdischarging();

		
def reset():
	
	restart();
restart();

The script can also be download from here: https://www.dropbox.com/s/1n6bx9ahaugme4s/battery.py

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: