Question
I AM TRYING TO LOG THE def getSystemInfo() DATA INTO A FILE NAMED, logs.txt. I CAN'T SEEM TO FIGURE OUT HOW TO APPEND ALL OF
I AM TRYING TO LOG THE "def getSystemInfo()" DATA INTO A FILE NAMED, "logs.txt." I CAN'T SEEM TO FIGURE OUT HOW TO APPEND ALL OF THAT DATA INTO "logs.txt!" CAN SOMEONE PLEASE HELP ME? HERE IS MY CODE SO FAR:
# Python Standard Libaries
import os
import re
import logging
import platform
import socket
import uuid
import psutil # pip install psutil
# This Define Function Can Explain Itself.... A Series of Functions to Gather MY System's Information, Which I Will Then Use to Append to "logs.txt."
def getSystemInfo():
try:
info={}
info['platform']=platform.system()
info['platform-release']=platform.release()
info['platform-version']=platform.version()
info['architecture']=platform.machine()
info['hostname']=socket.gethostname()
info['ip-address']=socket.gethostbyname(socket.gethostname())
info['mac-address']=':'.join(re.findall('..', "%012x" % uuid.getnode()))
info['processor']=platform.processor()
info['ram']=str(round(psutil.virtual_memory().total / (1024.0 **3))) + " GB"
return info
except SystemExit as exception:
logging.exception(exception)
return False
def main():
investigate = input("Investigator's Name: ") # I Enter My Name at this prompt, as to Highlight Who Ran the Script.
__SYS_INFO__ = getSystemInfo()
if __SYS_INFO__:
for (sys_keys, sys_values) in __SYS_INFO__.items():
print(f"{sys_keys}: {sys_values}")
# Remove any old logging script
if os.path.isfile('logs.txt'):
os.remove('logs.txt')
# "logging.basicConfig()" Is How I Want the "logs.txt" File Format.
logging.basicConfig(filename='logs.txt', filemode='w', level=logging.INFO, format='%(process)d-%(levelname)s-%(asctime)s %(message)s')
# Where the First Line in "logs.txt" Begins.
logging.info("Script Start ")
# The Next Line IS SUPPOSED TO Contain ALL of the SysInfo KEYs/VALUEs, BUT I Only Get, "ram: 24 GB."
logging.info(f"{sys_keys}: {sys_values}")
if __name__ == '__main__':
main()
print("Data Was Added to the File 'logs.txt.'")
print(" Script End")
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started