import os import datetime def main(): # Get the current date and time now = datetime.datetime.now() # Format the date and time as per your requirement: 010124319pm date_time = now.strftime("%m%d%Y%I%p") # Format the date as per your requirement for directory name: 010124319pm date = now.strftime("%m%d%Y") # Create directory if it doesn't exist directory_name = f"./{date}" if not os.path.exists(directory_name): os.makedirs(directory_name) print("Press Enter to start typing. Ctrl+C to exit. Type .notes for todays notes \n or .notesa for all the saved notes or type .notes month/day/year for a specific days notes.") try: first_entry = True while True: if first_entry: # Check if the directory for the current date exists if not os.path.exists(directory_name): os.makedirs(directory_name) first_entry = False user_input = input() if user_input.strip() == ".notes": display_notes(directory_name) elif user_input.strip() == ".notesa": display_all_notes() elif user_input.startswith(".notes "): date_requested = user_input.strip().split(".notes ")[1] display_specific_date_notes(date_requested) else: file_name = f"{directory_name}/{date_time}.txt" with open(file_name, "a") as file: file.write(user_input + "\n") except KeyboardInterrupt: print("Exiting...") def display_notes(directory_name): print("Displaying todays notes:") for filename in os.listdir(directory_name): if filename.endswith(".txt"): file_path = os.path.join(directory_name, filename) with open(file_path, "r") as file: print(f"\n--- {filename} ---\n") print(file.read()) print("End of todays notes.") def display_all_notes(): print("Displaying all notes:") for root, dirs, files in os.walk("."): for dir_name in dirs: if dir_name.isdigit() and len(dir_name) == 8: # Checking if directory name is in date format dir_path = os.path.join(root, dir_name) print(f"\n--- Notes in {dir_path} ---") for filename in os.listdir(dir_path): if filename.endswith(".txt"): file_path = os.path.join(dir_path, filename) with open(file_path, "r") as file: print(f"\n--- {filename} ---\n") print(file.read()) print("End of all notes.") def display_specific_date_notes(date_requested): date_requested = datetime.datetime.strptime(date_requested, "%m/%d/%Y").strftime("%m%d%Y") directory_name = f"./{date_requested}" if os.path.exists(directory_name): print(f"Displaying notes for {date_requested}:") for filename in os.listdir(directory_name): if filename.endswith(".txt"): file_path = os.path.join(directory_name, filename) with open(file_path, "r") as file: print(f"\n--- {filename} ---\n") print(file.read()) else: print(f"No notes found for {date_requested}.") if __name__ == "__main__": main()