Skip to content

Commit 0460ea1

Browse files
Merge pull request #1109 from hoseinfzad/master
pc information show with python
2 parents d8d0838 + b8b5048 commit 0460ea1

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

pc_information_show.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import argparse
2+
import sys
3+
import socket
4+
import psutil
5+
6+
def python_version():
7+
return sys.version_info
8+
9+
def ip_addresses():
10+
hostname = socket.gethostname()
11+
addresses = socket.getaddrinfo(hostname, None)
12+
13+
address_info = []
14+
for address in addresses:
15+
address_info.append((address[0].name, address[4][0]))
16+
return address_info
17+
18+
def cpu_load():
19+
return psutil.cpu_percent(interval=0.1)
20+
21+
def ram_available():
22+
return psutil.virtual_memory().available
23+
24+
def ac_connected():
25+
return psutil.sensors_battery().power_plugged
26+
27+
def show_sensors():
28+
print("Python Version:{0.major}.{0.minor}".format(python_version()))
29+
for address in ip_addresses():
30+
print("IP Addresses: {0[1]} ({0[0]})".format(address))
31+
print("CPU Load: {:.1f}".format(cpu_load()))
32+
print("RAM Available: {} MiB".format(ram_available() / 1024**2))
33+
print("AC Connected: {}".format(ac_connected()))
34+
35+
def command_line(argv):
36+
parser = argparse.ArgumentParser(
37+
description='Display the values of the sensors',add_help=True,
38+
)
39+
arguments = parser.parse_args()
40+
show_sensors()
41+
42+
if __name__ == '__main__':
43+
command_line(sys.argv)

0 commit comments

Comments
 (0)