Solved header bug

This commit is contained in:
Kevin Veen-Birkenbach 2023-12-25 23:36:21 +01:00
parent 8c4785dfe6
commit bcc8a7fb00

View File

@ -1,11 +1,14 @@
import pandas as pd import pandas as pd
import argparse import argparse
import os
def check_and_add_entry(file_path, host, database, username, password): def check_and_add_entry(file_path, host, database, username, password):
# Read the existing CSV file # Check if the file exists and is not empty
try: if os.path.exists(file_path) and os.path.getsize(file_path) > 0:
df = pd.read_csv(file_path, sep=';', header=None, names=['host', 'database', 'username', 'password']) # Read the existing CSV file with header
except FileNotFoundError: 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']) df = pd.DataFrame(columns=['host', 'database', 'username', 'password'])
# Check if the entry exists and remove it # Check if the entry exists and remove it