Last active
July 29, 2017 16:54
-
-
Save mvrpl/4cba8b272653960395a7 to your computer and use it in GitHub Desktop.
This code provides hardware information, only Mac OS X.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__author__ = 'Marcos Vinicius Rodrigues - https://mvrpl.com.br' | |
__doc__ = ''' | |
This code provides hardware information, only Mac OS X. | |
''' | |
import commands, json, os | |
data = [] | |
gpus = {} | |
data_info = commands.getstatusoutput('{ system_profiler SPDisplaysDataType ; sw_vers ; system_profiler SPHardwareDataType ; }')[1].splitlines() | |
nome = os.environ['USER'] | |
owner = filter(None, [line.split(':')[1].strip() if 'Model Name' in line else None for line in data_info])[0]+' de '+nome | |
for i in range(len(data_info)): | |
if 'Model Name' in data_info[i]: | |
data.append({'Model':data_info[i].split(':')[1].strip()}) | |
if 'ProductVersion' in data_info[i]: | |
data.append({'OSXVersion':data_info[i].split(':')[1].strip()}) | |
if 'Processor Name' in data_info[i]: | |
data.append({'ProcessorName':data_info[i].split(':')[1].strip()}) | |
if 'Processor Speed' in data_info[i]: | |
data.append({'ProcessorSpeed':data_info[i].split(':')[1].strip()}) | |
if 'Number of Processors' in data_info[i]: | |
data.append({'NumberOfProcessors':int(data_info[i].split(':')[1].strip())}) | |
if 'Total Number of Cores' in data_info[i]: | |
data.append({'TotalNumberOfCores':int(data_info[i].split(':')[1].strip())}) | |
if 'L3 Cache' in data_info[i]: | |
data.append({'L3Cache':data_info[i].split(':')[1].strip()}) | |
if 'Memory' in data_info[i]: | |
data.append({'Memory':data_info[i].split(':')[1].strip()}) | |
if 'Chipset Model' in data_info[i]: | |
line_id = i | |
if 'VRAM' in data_info[i]: | |
gpus[data_info[line_id].split(':')[1].strip()] = data_info[i].split(':')[1].strip() | |
data.append({'GPUS':gpus}) | |
json.dump({owner:data}, open('my_mac_info.json', 'w'), ensure_ascii=False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment