Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance: Make the 'directory making feature' dynamic #2

Open
2 tasks
anonfaded opened this issue Jun 22, 2024 · 2 comments
Open
2 tasks

Enhance: Make the 'directory making feature' dynamic #2

anonfaded opened this issue Jun 22, 2024 · 2 comments
Labels
bug Something isn't working enhancement New feature or request good first issue Good for newcomers

Comments

@anonfaded
Copy link
Owner

Right now the tool has a hardcoded feature where the saving of audio and history 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:

  • Use os module's feature of getting the working directory's path and use that to make directories.
  • Test it by copying the script out of folder and directly open it in terminal and see if it makes the directories of Audios and history.
@anonfaded anonfaded added bug Something isn't working enhancement New feature or request good first issue Good for newcomers labels Jun 22, 2024
@muddi900
Copy link

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")

@anonfaded
Copy link
Owner Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants