-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyolowLinux.py
79 lines (56 loc) · 2.05 KB
/
yolowLinux.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env python
import ctypes
import commands
import requests
import sys
import time
def yo(api_token, username):
return requests.post("http://api.justyo.co/yo/", data={'api_token': api_token, 'username': username})
def batteryPercent():
fullBatt = 0
currBatt = 0
battPercent = 0
fullBatt = open('/sys/class/power_supply/BAT0/energy_full','r')
for keep in fullBatt:
full = float(keep)
currBatt = open('/sys/class/power_supply/BAT0/energy_now','r')
for current in currBatt:
curr = float(current)
battPercent = ("%.1f" % ((curr/full)*100))
stringPercent = str(battPercent)
finalPercent = (stringPercent + "%")
return finalPercent
def getBattery():
person = raw_input("Enter your username: ")
print person
battlvl = 31978000
choose = True
status = None
output = None
setLimit = input("Battery % to get warnings at (1-100) ")
compare = str(setLimit) + ".0%"
print "You have set your battery warning percentage to " + compare
while True:
time.sleep(3)
charge = open('/sys/class/power_supply/BAT0/status','r')
for search in charge:
status = search
##print status
choose = (status[:-1] == 'Charging')
break
if not choose:
batt = open('/sys/class/power_supply/BAT0/energy_now','r') ##opens the directory containing pi serial
for line in batt: ##in the file
num = int(line)
output = batteryPercent()
sys.stdout.write(status)
print ' '
print "Current battery level: " + output
if output == compare:
print "Yo!"
yo("32e37dc1-3b51-13c1-13ab-e64da3a8dade",person)
break
batt.close()
charge.close()
batteryPercent()
getBattery()