Add 'client.py'
This commit is contained in:
parent
ef1e88d80c
commit
d01acda8f5
1 changed files with 27 additions and 0 deletions
27
client.py
Normal file
27
client.py
Normal file
|
@ -0,0 +1,27 @@
|
|||
import socket
|
||||
from os.path import exists
|
||||
from re import match
|
||||
|
||||
server_ip = "127.0.0.1"
|
||||
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
try:
|
||||
sock.connect((server_ip,12894))
|
||||
except:
|
||||
exit()
|
||||
|
||||
if exists("/sys/class/power_supply/BAT1/energy_now"):
|
||||
now,full = None,None
|
||||
with open("/sys/class/power_supply/BAT1/energy_now","r") as f:
|
||||
now = eval(f.read())
|
||||
with open("/sys/class/power_supply/BAT1/energy_full","r") as f:
|
||||
full = eval(f.read())
|
||||
percentage = str(int(now/full*100))
|
||||
else:
|
||||
# Not a laptop, assume debugging
|
||||
percentage = ""
|
||||
while not match(r"\d{1,3}",percentage):
|
||||
percentage = input("Enter the fake percentage to send: ")
|
||||
|
||||
sock.sendall(bytes(percentage, 'utf-8'))
|
||||
sock.close()
|
Loading…
Reference in a new issue