mirror of
https://github.com/metafy-social/python-scripts.git
synced 2024-11-23 20:11:10 +00:00
First Commit
This commit is contained in:
parent
f0c04833b8
commit
2a3fc819d6
55
scripts/Computer_Stats/README.md
Normal file
55
scripts/Computer_Stats/README.md
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
## Computer Stats Checker
|
||||||
|
|
||||||
|
It is a python program that shows about user's computer stats. Such as cpu, memory, disk, ip_adress etc.
|
||||||
|
|
||||||
|
The response of the program is in json fromat and if say yes it will be automatically saved to log.js so it is easier to reach those stats in the future.
|
||||||
|
|
||||||
|
### Modules Used
|
||||||
|
|
||||||
|
- psutil==5.8.0
|
||||||
|
|
||||||
|
### How to Use
|
||||||
|
|
||||||
|
* Clone the repo
|
||||||
|
* Make sure you are at the same folder as the main file in. (1)
|
||||||
|
* run `python main.py`
|
||||||
|
* Congrats!!
|
||||||
|
|
||||||
|
|
||||||
|
(1) = if not program creates new file named log.js instead of the one we want it to save to
|
||||||
|
|
||||||
|
|
||||||
|
#### Example Output
|
||||||
|
|
||||||
|
./daily-python-scripts/scripts/Computer_Stats/main.py
|
||||||
|
|
||||||
|
======================================== System Information ========================================
|
||||||
|
System: Windows
|
||||||
|
Nodes:
|
||||||
|
Release:
|
||||||
|
Version:
|
||||||
|
Machine:
|
||||||
|
Processor:
|
||||||
|
Ip adress:
|
||||||
|
Mac adress:
|
||||||
|
Ram:
|
||||||
|
======================================== CPU Info ========================================
|
||||||
|
Physical cores:
|
||||||
|
Total cores:
|
||||||
|
Max frequency:
|
||||||
|
Min frequency:
|
||||||
|
Current frequency:
|
||||||
|
Total cpu usage:
|
||||||
|
======================================== Memory Info ========================================
|
||||||
|
Total:
|
||||||
|
Available:
|
||||||
|
Used:
|
||||||
|
Percentage:
|
||||||
|
======================================== Disk Info ========================================
|
||||||
|
Total:
|
||||||
|
Used:
|
||||||
|
Free:
|
||||||
|
======================================== Boot Time ========================================
|
||||||
|
Time: 2022/9/24 8:35:45
|
||||||
|
Save the stats [y, n]: y
|
||||||
|
Stats saved successfully. You can find the logs at logs.json
|
0
scripts/Computer_Stats/log.json
Normal file
0
scripts/Computer_Stats/log.json
Normal file
155
scripts/Computer_Stats/main.py
Normal file
155
scripts/Computer_Stats/main.py
Normal file
|
@ -0,0 +1,155 @@
|
||||||
|
import psutil
|
||||||
|
import platform
|
||||||
|
import uuid
|
||||||
|
import re
|
||||||
|
import json
|
||||||
|
import socket
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
### COMPUTER STATS CHECKER ###
|
||||||
|
|
||||||
|
uname = platform.uname()
|
||||||
|
|
||||||
|
boot_time_timestamp = psutil.boot_time() # Boot time timestamp
|
||||||
|
bt = datetime.fromtimestamp(boot_time_timestamp) # Boot time
|
||||||
|
cpufreq = psutil.cpu_freq() # Cpu
|
||||||
|
svmem = psutil.virtual_memory() # Memory
|
||||||
|
disk = psutil.disk_usage("/") # Disk
|
||||||
|
|
||||||
|
def get_size(bytes, suffix="B"):
|
||||||
|
"""
|
||||||
|
Scale bytes to its proper format
|
||||||
|
e.g:
|
||||||
|
1253656 => '1.20MB'
|
||||||
|
1253656678 => '1.17GB'
|
||||||
|
"""
|
||||||
|
factor = 1024
|
||||||
|
for unit in ["", "K", "M", "G", "T", "P"]:
|
||||||
|
if bytes < factor:
|
||||||
|
return f"{bytes:.2f}{unit}{suffix}"
|
||||||
|
bytes /= factor
|
||||||
|
|
||||||
|
data = { # Json object to store all of the data. Values can be added and removed.
|
||||||
|
"system": {
|
||||||
|
"system": uname.system,
|
||||||
|
"nodes": uname.node,
|
||||||
|
"release": uname.release,
|
||||||
|
"version": uname.version,
|
||||||
|
"machine": uname.machine,
|
||||||
|
"processor": uname.processor,
|
||||||
|
"ip adress": socket.gethostbyname(socket.gethostname()),
|
||||||
|
"mac adress": ':'.join(re.findall('..', '%012x' % uuid.getnode())),
|
||||||
|
"ram": str(round(psutil.virtual_memory().total / (1024.0 **3)))+" GB",
|
||||||
|
},
|
||||||
|
"boot_time": {
|
||||||
|
"time": f"{bt.year}/{bt.month}/{bt.day} {bt.hour}:{bt.minute}:{bt.second}"
|
||||||
|
},
|
||||||
|
"cpu_info": {
|
||||||
|
"physical cores": psutil.cpu_count(logical=False),
|
||||||
|
"total cores": psutil.cpu_count(logical=True),
|
||||||
|
"max frequency": f"{cpufreq.max:.2f}Mhz",
|
||||||
|
"min frequency": f"{cpufreq.min:.2f}Mhz",
|
||||||
|
"current frequency": f"{cpufreq.current:.2f}Mhz",
|
||||||
|
"total cpu usage": f"{psutil.cpu_percent()}%"
|
||||||
|
},
|
||||||
|
"memory_info": {
|
||||||
|
"total": f"{get_size(svmem.total)}",
|
||||||
|
"available": f"{get_size(svmem.available)}",
|
||||||
|
"used": f"{get_size(svmem.used)}",
|
||||||
|
"percentage": f"{svmem.percent}%"
|
||||||
|
},
|
||||||
|
"disk_info": {
|
||||||
|
"total": f"{int(disk.total / (1024.0 ** 3))} GB",
|
||||||
|
"used": f"{int(disk.used / (1024.0 ** 3))} GB",
|
||||||
|
"free": f"{int(disk.free / (1024.0 ** 3))} GB",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# All functions below do get every key and value from data object at the top and logs it to console.
|
||||||
|
|
||||||
|
def system_info(): # System Info
|
||||||
|
system = data["system"]
|
||||||
|
length = len(list(system.keys()))
|
||||||
|
|
||||||
|
keys = list(system.keys())
|
||||||
|
values = list(system.values())
|
||||||
|
|
||||||
|
print("="*40, "System Information", "="*40)
|
||||||
|
|
||||||
|
for i in range(length):
|
||||||
|
print(f"{keys[i].capitalize()}: {values[i]}")
|
||||||
|
|
||||||
|
|
||||||
|
def boot_time(): # Boot Time
|
||||||
|
time = data["boot_time"]
|
||||||
|
length = len(list(time.keys()))
|
||||||
|
|
||||||
|
keys = list(time.keys())
|
||||||
|
values = list(time.values())
|
||||||
|
|
||||||
|
print("="*40, "Boot Time", "="*40)
|
||||||
|
|
||||||
|
for i in range(length):
|
||||||
|
print(f"{keys[i].capitalize()}: {values[i]}")
|
||||||
|
|
||||||
|
|
||||||
|
def cpu_info(): # CPU Info
|
||||||
|
cpu = data["cpu_info"]
|
||||||
|
length = len(list(cpu.keys()))
|
||||||
|
|
||||||
|
keys = list(cpu.keys())
|
||||||
|
values = list(cpu.values())
|
||||||
|
|
||||||
|
print("="*40, "CPU Info", "="*40)
|
||||||
|
|
||||||
|
for i in range(length):
|
||||||
|
print(f"{keys[i].capitalize()}: {values[i]}")
|
||||||
|
|
||||||
|
|
||||||
|
def memory_info(): # Memory Info
|
||||||
|
memory = data["memory_info"]
|
||||||
|
length = len(list(memory.keys()))
|
||||||
|
|
||||||
|
keys = list(memory.keys())
|
||||||
|
values = list(memory.values())
|
||||||
|
|
||||||
|
print("="*40, "Memory Info", "="*40)
|
||||||
|
|
||||||
|
for i in range(length):
|
||||||
|
print(f"{keys[i].capitalize()}: {values[i]}")
|
||||||
|
|
||||||
|
|
||||||
|
def disk_info(): # Disk Info
|
||||||
|
disk = data["disk_info"]
|
||||||
|
length = len(list(disk.keys()))
|
||||||
|
|
||||||
|
keys = list(disk.keys())
|
||||||
|
values = list(disk.values())
|
||||||
|
|
||||||
|
print("="*40, "Disk Info", "="*40)
|
||||||
|
|
||||||
|
for i in range(length):
|
||||||
|
print(f"{keys[i].capitalize()}: {values[i]}")
|
||||||
|
|
||||||
|
|
||||||
|
def print_all(): # Calling all the functions
|
||||||
|
system_info()
|
||||||
|
cpu_info()
|
||||||
|
memory_info()
|
||||||
|
disk_info()
|
||||||
|
boot_time()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
print_all()
|
||||||
|
|
||||||
|
save = input("Save the stats [y, n]: ")
|
||||||
|
|
||||||
|
if save == "y":
|
||||||
|
now = datetime.now()
|
||||||
|
data["save_date"] = str(now) # Adding save date to data
|
||||||
|
with open("./log.json","w") as file:
|
||||||
|
json.dump(data, file, ensure_ascii=False, indent=2)
|
||||||
|
print("Stats saved successfully. You can find the logs at logs.json")
|
||||||
|
else:
|
||||||
|
pass
|
1
scripts/Computer_Stats/requirements.txt
Normal file
1
scripts/Computer_Stats/requirements.txt
Normal file
|
@ -0,0 +1 @@
|
||||||
|
psutil==5.8.0
|
Loading…
Reference in New Issue
Block a user