Friday, March 3, 2017

Programme That Cheak Your Battery Source Code [PYTHON]

This   Code   Cheak   Your   Battery       Status.............

1. #!/usr/bin/env python
2. # -*- coding: utf-8 -*-
3. # Dependecy: notify2
4. # sudo pip install notify2
5.
6. import notify2
7. import shlex
8. from subprocess import Popen, PIPE
9.
10. upower = shlex .split( 'upower -i /org/freedesktop/UPower/devices/battery_BAT0' )
11. grp = shlex.split ('grep percentage' )
12. ak = shlex .split( "awk -F '[^0-9]*' '$0=$2'" )
13.
14. proc1 = Popen ( upower, stdout=PIPE )
15. proc2 = Popen ( grp , stdin=proc1.stdout, stdout=PIPE )
16. proc3 = Popen ( ak, stdin=proc2.stdout, stdout=PIPE )
17. proc1.stdout.close ()
18. out = int (proc3.communicate ()[ 0 ].decode ( 'ascii' ).rstrip ())
19. # print(out)
20.
21. notify2.init ('bat_check' )
22.
23. # edit this
24. # if battery is less than 15%
25. if out < 15 :
26. note = notify2.Notification ('Battery Check' , 'CHARGE CHARGE CHARGE CHARGE CHARGE' )
27. note.set_category ( 'device' )
28. note.set_timeout ( 5000)
29. note.show ()

No comments:

Post a Comment