diff --git a/src/new_test_database.db b/src/new_test_database.db new file mode 100644 index 0000000..8361806 Binary files /dev/null and b/src/new_test_database.db differ diff --git a/src/update_database.py b/src/update_database.py new file mode 100644 index 0000000..54272c6 --- /dev/null +++ b/src/update_database.py @@ -0,0 +1,55 @@ +import sqlite3 +import pandas as pd + +# Connect to your SQLite database +db_path = 'new_test_database.db' # Change this to your actual database path +conn = sqlite3.connect(db_path) +cursor = conn.cursor() + +# Drop existing tables if they exist +cursor.execute("DROP TABLE IF EXISTS breed_requirements") +cursor.execute("DROP TABLE IF EXISTS breeds") + +# Recreate 'breeds' table +cursor.execute(""" + CREATE TABLE breeds ( + id INTEGER PRIMARY KEY, + target TEXT + ) +""") + +# Recreate 'breed_requirements' table +cursor.execute(""" + CREATE TABLE breed_requirements ( + id INTEGER PRIMARY KEY, + breed_id INTEGER, + requirement_type TEXT, + requirement_value TEXT, + FOREIGN KEY (breed_id) REFERENCES breeds (id) + ) +""") + +# Read CSV data into a pandas DataFrame +csv_path = 'updated_breeding_pairs.csv' # Change this to your actual CSV file path +df = pd.read_csv(csv_path, header=None, names=['base', 'mate', 'offspring']) + +# Function to insert new breeds and requirements into the database +def insert_breed_and_requirements(base, mate, offspring): + # Insert breed into 'breeds' table + cursor.execute("INSERT INTO breeds (target) VALUES (?)", (offspring,)) + conn.commit() + + # Get the newly inserted breed_id + breed_id = cursor.lastrowid + + # Insert requirements into 'breed_requirements' table + cursor.execute("INSERT INTO breed_requirements (breed_id, requirement_type, requirement_value) VALUES (?, 'base', ?)", (breed_id, base)) + cursor.execute("INSERT INTO breed_requirements (breed_id, requirement_type, requirement_value) VALUES (?, 'mate', ?)", (breed_id, mate)) + conn.commit() + +# Iterate through each row in the DataFrame and insert data into the database +for index, row in df.iterrows(): + insert_breed_and_requirements(row['base'], row['mate'], row['offspring']) + +# Close the database connection +conn.close() diff --git a/src/updated_breeding_pairs.csv b/src/updated_breeding_pairs.csv index cdc69ef..32d431b 100644 --- a/src/updated_breeding_pairs.csv +++ b/src/updated_breeding_pairs.csv @@ -1,4 +1,3 @@ -#1,#2,Offspring beast,dragon,Almiraj Saccer,dragon,Antbear beast,PutrePup,Arrowdog