Skip to content

Instantly share code, notes, and snippets.

@annaleighsmith
Last active October 22, 2021 17:06
Show Gist options
  • Save annaleighsmith/23cbf9afe5a6a006e9dec9736cdf0845 to your computer and use it in GitHub Desktop.
Save annaleighsmith/23cbf9afe5a6a006e9dec9736cdf0845 to your computer and use it in GitHub Desktop.
system_specs
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"id": "bafdcc29",
"metadata": {},
"source": [
"\n",
"## Purpose: Analyze computer specs with python modules\n",
"\n",
"## Modules:\n",
"\n",
"> the **os** module provides a portable way of using operating system dependent functionality. If you just want to read or write a file see open(), if you want to manipulate paths, see the os.path module, and if you want to read all the lines in all the files on the command line see the fileinput module. For creating temporary files and directories see the tempfile module, and for high-level file and directory handling see the shutil module.\n",
"\n",
"> the **sys** module provides access to some variables used or maintained by the interpreter and to functions that interact strongly with the interpreter. It is always available.\n",
"\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "885d6af2",
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"import sys\n",
"import platform\n",
"import psutil\n",
"from screeninfo import get_monitors\n",
"from tabulate import tabulate\n"
]
},
{
"cell_type": "code",
"execution_count": 29,
"id": "83cb3b19",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"+_________________________________________________________________________________+\n",
"|SYSTEM SPECS REPORT |\n",
"+‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾+\n",
"| Type | Result |\n",
"|---------------------------+-----------------------------------------------------|\n",
"| OS | Windows |\n",
"| OS Name | nt |\n",
"| OS Release | 10 |\n",
"| OS version | 10.0.19042 |\n",
"| Platform Type | Windows-10-10.0.19042-SP0 |\n",
"| Computer Network Name | DESKTOP-6QBOVQ2 |\n",
"| File System Encoding | utf-8 |\n",
"| Recursion Limit | 3000 |\n",
"| Current Working Directory | C:\\Users\\Administrator\\Documents\\jupyterLab |\n",
"| Python Version | 3.9 |\n",
"| Machine Type | AMD64 |\n",
"| Processor Type | Intel64 Family 6 Model 126 Stepping 5, GenuineIntel |\n",
"| Number of physical cores | 4 |\n",
"| Number of logical cores | 8 |\n",
"| System CPU Utilization | 9.3 |\n",
"| Per-CPU Utilization | [4.7, 6.2, 15.6, 7.8, 9.2, 3.1, 7.8, 6.2] |\n",
"| Total RAM installed | 8.16 |\n",
"| Available RAM | 3.46 |\n",
"| Used RAM | 4.69 |\n",
"| RAM Usage Percentage | 58 |\n",
"| Monitor Name | \\\\.\\DISPLAY1 |\n",
"| Monitor Width | 2256 |\n",
"| Monitor Height | 1504 |\n",
"| Monitor is Primary | True |\n",
"| Monitor Ratio | 1.5 |\n",
"+_________________________________________________________________________________+\n",
"| |\n",
"+‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾+\n"
]
}
],
"source": [
"width = 80\n",
" \n",
"def boxText(label):\n",
" label_length = len(label)\n",
" spaces = int(((width) - label_length)+1)* \" \"\n",
" print('+'+(\"_\"*(width+1))+'+')\n",
" print(f\"|{label}{spaces}|\")\n",
" print('+'+(\"‾\"*(width+1))+'+')\n",
" \n",
"boxText('SYSTEM SPECS REPORT')\n",
"\n",
"# calcs\n",
"python_version = str(sys.version_info.major) + \".\" + str(sys.version_info.minor)\n",
"\n",
"os_info = [\n",
" [\"OS\",platform.system()],\n",
" [\"OS Name\",os.name], \n",
" [\"OS Release\",platform.release()], \n",
" [\"OS version\", platform.version()],\n",
" [\"Platform Type\",platform.platform()],\n",
" [\"Computer Network Name\", platform.node()],\n",
" [\"File System Encoding\", sys.getfilesystemencoding()],\n",
" [\"Recursion Limit\", sys.getrecursionlimit()],\n",
" [\"Current Working Directory\", os.getcwd()],\n",
" [\"Python Version\", python_version],\n",
" [\"Machine Type\", platform.machine()],\n",
" [\"Processor Type\", platform.processor()],\n",
" [\"Number of physical cores\", psutil.cpu_count(logical=False)],\n",
" [\"Number of logical cores\", psutil.cpu_count(logical=True)],\n",
" [\"System CPU Utilization\", psutil.cpu_percent(interval=1)],\n",
" [\"Per-CPU Utilization\", psutil.cpu_percent(interval=1, percpu=True)],\n",
" [\"Total RAM installed\",round(psutil.virtual_memory().total/1000000000, 2)],\n",
" [\"Available RAM\",round(psutil.virtual_memory().available/1000000000, 2),\"GB\"],\n",
" [\"Used RAM\",round(psutil.virtual_memory().used/1000000000, 2),\"GB\"],\n",
" [\"RAM Usage Percentage\",round(psutil.virtual_memory().percent),\"%\"],\n",
"]\n",
"for m in get_monitors():\n",
" os_info.append([\"Monitor Name\", str(m.name)])\n",
" os_info.append([\"Monitor Width\", str(m.width)])\n",
" os_info.append([\"Monitor Height\", str(m.height)])\n",
" os_info.append([\"Monitor is Primary\", str(m.is_primary)])\n",
" os_info.append([\"Monitor Ratio\", str(m.width/m.height)])\n",
"\n",
"print(tabulate(os_info, headers=['Type','Result'],tablefmt=\"orgtbl\"))\n",
"\n",
"boxText('')\n",
"\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.7"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment