update.py script working, pulls in data from csv in data folder
This commit is contained in:
parent
c79b3df1a2
commit
fea143f2de
Binary file not shown.
@ -1,6 +1,6 @@
|
|||||||
import sqlite3
|
|
||||||
import csv
|
import csv
|
||||||
import os
|
import os
|
||||||
|
import sqlite3
|
||||||
|
|
||||||
# Connect to the SQLite database
|
# Connect to the SQLite database
|
||||||
conn = sqlite3.connect("items.db")
|
conn = sqlite3.connect("items.db")
|
||||||
@ -17,6 +17,10 @@ csv_file_ammo = "ammo.csv" # Change this to your new_table CSV file name
|
|||||||
csv_path_reloading = os.path.join(csv_directory, csv_file_reloading)
|
csv_path_reloading = os.path.join(csv_directory, csv_file_reloading)
|
||||||
csv_path_ammo = os.path.join(csv_directory, csv_file_ammo)
|
csv_path_ammo = os.path.join(csv_directory, csv_file_ammo)
|
||||||
|
|
||||||
|
# Define the starting ID values for each table
|
||||||
|
starting_id_reloading = 20000 # Replace with your desired starting value
|
||||||
|
starting_id_ammo = 10000 # Replace with your desired starting value
|
||||||
|
|
||||||
# Define the table schema for reloading
|
# Define the table schema for reloading
|
||||||
cursor.execute(
|
cursor.execute(
|
||||||
"""
|
"""
|
||||||
@ -52,9 +56,22 @@ cursor.execute(
|
|||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Set the starting ID values for each table using INSERT statements
|
||||||
|
cursor.execute(f"INSERT INTO reloading (id) VALUES ({starting_id_reloading})")
|
||||||
|
|
||||||
|
# Reset the ammo table's id sequence
|
||||||
|
cursor.execute(f"DELETE FROM SQLITE_SEQUENCE WHERE name='ammo'")
|
||||||
|
cursor.execute(
|
||||||
|
f"INSERT INTO SQLITE_SEQUENCE (name, seq) VALUES ('ammo', {starting_id_ammo})"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
# Function to load data from a CSV file into a table
|
# Function to load data from a CSV file into a table
|
||||||
def load_csv_data(csv_path, table_name, cursor):
|
def load_csv_data(csv_path, table_name, cursor):
|
||||||
|
# Delete existing data in the table
|
||||||
|
delete_query = f"DELETE FROM {table_name}"
|
||||||
|
cursor.execute(delete_query)
|
||||||
|
|
||||||
with open(csv_path, newline="") as csvfile:
|
with open(csv_path, newline="") as csvfile:
|
||||||
csv_reader = csv.reader(csvfile)
|
csv_reader = csv.reader(csvfile)
|
||||||
next(csv_reader) # Skip the header row if it exists in the CSV
|
next(csv_reader) # Skip the header row if it exists in the CSV
|
||||||
|
Loading…
Reference in New Issue
Block a user