diff --git a/file_read_write.py b/file_read_write.py index dd0a63f..80674fb 100644 --- a/file_read_write.py +++ b/file_read_write.py @@ -1,4 +1,5 @@ import json +from json import JSONDecodeError import os def write_command(com, inp, out) -> None: @@ -41,4 +42,16 @@ def delete() -> bool: os.remove("history.json") return True except: - return False \ No newline at end of file + return False + +def read_history(): + filename = "history.json" + try: + with open(filename, "r") as file: + number_dict = json.load(file) + for line, data in number_dict.items(): + print(f" ({line}) Command: {data['command']} | Input: {data['input']} | Output: {data['output']}") + except FileNotFoundError: + raise FileNotFoundError("History file not found! Maybe program hasn't been saved yet.") + except JSONDecodeError: + print("History is empty.") \ No newline at end of file