Question: using this instructions : write a Python program using Flask module and create an API to read each of the parameters values below and display

using this instructions :
write a Python program using Flask module and create an API to read each of the parameters values below and display them through a browser.
FreePhysicalMemory
NumberOfProcesses
TotalVirtualMemorySize
TotalVisibleMemorySize
and store these values in a Python dictionary
complete this code and please check that it works :
if __name__=="__main__":
cmd = 'wmic os get '
targets =['FreePhysicalMemory', 'NumberOfProcesses', 'TotalVirtualMemorySize', 'TotalVisibleMemorySize']
system_stat ={}
for target in targets:
new_cmd = cmd + target +'/value'
result = subprocess.run(new_cmd, capture_output = True, text = True, shell = False)
lines = result.stdout.strip().split('
')
for line in lines:
if '=' in line:
key, value = line.split('=')
value = value.strip()
system_stat[target]= value
print(system_stat)
the output should look something like this {
"FreePhysicalMemory": "8639860",
"NumberOfProcesses": "267",
"TotalVirtualMemorySize": "17531308",
"TotalVisibleMemorySize": "16482732"
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!