Add 'client.py'

This commit is contained in:
kiichan 2019-08-15 23:38:08 -05:00
parent ef1e88d80c
commit d01acda8f5
1 changed files with 27 additions and 0 deletions

27
client.py Normal file
View 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()