diff --git a/Lesson_4/.gitignore b/Lesson_4/.gitignore new file mode 100644 index 0000000..b881d2f --- /dev/null +++ b/Lesson_4/.gitignore @@ -0,0 +1 @@ +data.txt diff --git a/Lesson_4/task1.py b/Lesson_4/task1.py new file mode 100644 index 0000000..7bccbd2 --- /dev/null +++ b/Lesson_4/task1.py @@ -0,0 +1,38 @@ +# Lesson 4 Task 1: write system info to a file +# Author: Stanislav Mykhailenko +# License: Unlicense + +# Return codes: +# 0 - OK + +import platform, psutil + +data = [False,False,False,False] +selection = None +while True: + selection = input("a) CPU [" + str(data[0]) + "]\nb) RAM [" + str(data[1]) + "]\nc) Architecture [" + str(data[2]) + "]\nd) CPU Family [" + str(data[3]) + "]\ny) Proceed\n") + if selection == "y": + break + if not len(selection) == 1 or ord(selection) < ord("a") or ord(selection) > ord("d"): + print("Invalid selection.") + continue + number = ord(selection) - ord("a") + data[number] = not data[number] + +anythingTrue = False +if data[0] or data[1] or data[2] or data[3]: + anythingTrue = True + +if anythingTrue: + file_out = open("data.txt", "w") + + if data[0]: + file_out.write("CPU: " + platform.processor() + "\n") + if data[1]: + file_out.write("RAM: " + str(psutil.virtual_memory()) + "\n") + if data[2]: + file_out.write("Architecture: " + str(platform.architecture()) + "\n") + if data[3]: + file_out.write("CPU family: " + platform.machine() + "\n") + + file_out.close()