forked from geekcomputers/Python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sensors_information.py
52 lines (35 loc) · 1.16 KB
/
sensors_information.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
import argparse
import sys
import socket
import psutil
def python_version():
return sys.version_info
def ip_addresses():
hostname = socket.gethostname()
addresses = socket.getaddrinfo(hostname, None)
address_info = []
for address in addresses:
address_info.append((address[0].name, address[4][0]))
return address_info
def cpu_load():
return psutil.cpu_percent(interval=0.1)
def ram_available():
return psutil.virtual_memory().available
def ac_connected():
return psutil.sensors_battery().power_plugged
def show_sensors():
print("Python Version:{0.major}.{0.minor}".format(python_version()))
for address in ip_addresses():
print("IP Addresses: {0[1]} ({0[0]})".format(address))
print("CPU Load: {:.1f}".format(cpu_load()))
print("RAM Available: {} MiB".format(ram_available() / 1024 ** 2))
print("AC Connected: {}".format(ac_connected()))
def command_line(argv):
parser = argparse.ArgumentParser(
description="Display the values of the sensors",
add_help=True,
)
arguments = parser.parse_args()
show_sensors()
if __name__ == "__main__":
command_line(sys.argv)