tidy-finance / website

This repository hosts the source code for the website tidy-finance.org
https://tidy-finance.org
Other
85 stars 53 forks source link

Automatically Create Data Directory for SQLite File #142

Open lrwilke opened 3 hours ago

lrwilke commented 3 hours ago

The current code in Accessing and Managing Financial Data assumes in the section "Setting up a Database" that the data directory already exists. When running the command tidy_finance = sqlite3.connect(database="data/tidy_finance_python.sqlite") without previously creating the data directory, SQLite will throw an OperationalError: unable to open database file.

This can be avoided by explicitly checking whether the directory exists and creating it if it doesn't:

# Define the path to the database
database_path = "data/tidy_finance_python.sqlite"
directory = os.path.dirname(database_path)

# Create the directory if it doesn't exist
if not os.path.exists(directory):
    os.makedirs(directory)

Alternatively of course, you could just mention in the text that the data-directory has to be created beforehands.

If I missed that part - sorry and please disregard this issue! :)

christophscheuch commented 2 hours ago

Great suggestion, thank you! We definitely missed this and will update the text accordingly :)