From bcc8a7fb00966209bdbb61625e0111bc90da5329 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Mon, 25 Dec 2023 23:36:21 +0100 Subject: [PATCH] Solved header bug --- database_entry_seeder.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/database_entry_seeder.py b/database_entry_seeder.py index 8d17672..7199101 100644 --- a/database_entry_seeder.py +++ b/database_entry_seeder.py @@ -1,11 +1,14 @@ import pandas as pd import argparse +import os def check_and_add_entry(file_path, host, database, username, password): - # Read the existing CSV file - try: - df = pd.read_csv(file_path, sep=';', header=None, names=['host', 'database', 'username', 'password']) - except FileNotFoundError: + # Check if the file exists and is not empty + if os.path.exists(file_path) and os.path.getsize(file_path) > 0: + # Read the existing CSV file with header + df = pd.read_csv(file_path, sep=';') + else: + # Create a new DataFrame with columns if file does not exist df = pd.DataFrame(columns=['host', 'database', 'username', 'password']) # Check if the entry exists and remove it