Open anonfaded opened 4 months ago
Would something like this work?
- def save_to_history(text):
+ def save_to_history(text, dir_path=None):
# Get current date
current_date = datetime.now().strftime("%Y-%m-%d")
# Create history folder if it doesn't exist
- history_folder = "history"
+ history_folder = dir_path or "history"
os.makedirs(history_folder, exist_ok=True)
# Create subfolder for current date if it doesn't exist
date_folder = os.path.join(history_folder, current_date)
os.makedirs(date_folder, exist_ok=True)
# Create markdown file for current date if it doesn't exist
markdown_file = os.path.join(date_folder, "history.md")
# Write text to markdown file with a timestamp
with open(markdown_file, "a") as file:
file.write(f"\n\n---\n\n{datetime.now().strftime('%H:%M:%S')}\n{text}\n")
Thanks for the suggestion! To ensure directories are created correctly regardless of where the script is run, we should use os.getcwd() to get the current working directory. Here's an example:
import os
cwd = os.getcwd()
history_folder = os.path.join(cwd, 'history')
os.makedirs(history_folder, exist_ok=True)
This ensures the directories are always created in the correct location. Test after that locally to make sure it works accordingly.
Right now the tool has a hardcoded feature where the saving of
audio
andhistory
feature makes two folders in the location where the tool is present, but if we open the tool and its not in a directory then it doesn't make the directories.Task to do:
os
module's feature of getting the working directory's path and use that to make directories.Audios
andhistory
.