mirror of
https://github.com/jayofelony/pwnagotchi.git
synced 2025-07-01 18:37:27 -04:00
misc: refactored code to work as a setup.py based package
Signed-off-by: Simone Margaritelli <evilsocket@gmail.com>
This commit is contained in:
48
pwnagotchi/__init__.py
Normal file
48
pwnagotchi/__init__.py
Normal file
@ -0,0 +1,48 @@
|
||||
import subprocess
|
||||
|
||||
version = '1.0.0plz4'
|
||||
|
||||
_name = None
|
||||
|
||||
|
||||
def name():
|
||||
global _name
|
||||
if _name is None:
|
||||
with open('/etc/hostname', 'rt') as fp:
|
||||
_name = fp.read().strip()
|
||||
return _name
|
||||
|
||||
|
||||
def mem_usage():
|
||||
out = subprocess.getoutput("free -m")
|
||||
for line in out.split("\n"):
|
||||
line = line.strip()
|
||||
if line.startswith("Mem:"):
|
||||
parts = list(map(int, line.split()[1:]))
|
||||
tot = parts[0]
|
||||
used = parts[1]
|
||||
free = parts[2]
|
||||
return used / tot
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
def cpu_load():
|
||||
with open('/proc/stat', 'rt') as fp:
|
||||
for line in fp:
|
||||
line = line.strip()
|
||||
if line.startswith('cpu '):
|
||||
parts = list(map(int, line.split()[1:]))
|
||||
user_n = parts[0]
|
||||
sys_n = parts[2]
|
||||
idle_n = parts[3]
|
||||
tot = user_n + sys_n + idle_n
|
||||
return (user_n + sys_n) / tot
|
||||
return 0
|
||||
|
||||
|
||||
def temperature(celsius=True):
|
||||
with open('/sys/class/thermal/thermal_zone0/temp', 'rt') as fp:
|
||||
temp = int(fp.read().strip())
|
||||
c = int(temp / 1000)
|
||||
return c if celsius else ((c * (9 / 5)) + 32)
|
Reference in New Issue
Block a user