update.py working but doesn't rewrite lines instead adds more, need to fix
This commit is contained in:
parent
d061158cfc
commit
c79b3df1a2
0
Database/createtables.py
Normal file
0
Database/createtables.py
Normal file
14
Database/data/ammo.csv
Normal file
14
Database/data/ammo.csv
Normal file
@ -0,0 +1,14 @@
|
||||
id,type,name,rarity,weight,width,height,stack,value,gunpowder
|
||||
NULL,rifle_ammo,5.56x45 AP,4,0.02646,1,1,7500,30,15
|
||||
NULL,rifle_ammo,5.56x45 FMJ,1,0.02646,1,1,2500,30,10
|
||||
NULL,rifle_ammo,5.56x45 HP,2,0.02646,1,1,5000,30,10
|
||||
NULL,pistol_ammo,9mm AP,3,0.01984,1,1,5000,45,12
|
||||
NULL,pistol_ammo,9mm FMJ,1,0.01984,1,1,2000,45,6
|
||||
NULL,pistol_ammo,9mm HP,2,0.01984,1,1,4000,45,6
|
||||
NULL,pistol_ammo,.40 S&W AP,3,0.01984,1,1,5500,45,13
|
||||
NULL,pistol_ammo,.40 S&W FMJ,1,0.01984,1,1,3000,45,7
|
||||
NULL,pistol_ammo,.40 S&W HP,2,0.01984,1,1,4500,45,7
|
||||
NULL,rifle_ammo,7.62x39 AP,4,0.02646,1,1,5200,30,15
|
||||
NULL,rifle_ammo,7.62x39 FMJ,1,0.02646,1,1,1800,30,10
|
||||
NULL,rifle_ammo,7.62x39 HP,2,0.02646,1,1,3600,30,10
|
||||
NULL,rifle_ammo,27.62x39 HP,2,0.02646,1,1,3600,30,10
|
|
15
Database/data/reloading.csv
Normal file
15
Database/data/reloading.csv
Normal file
@ -0,0 +1,15 @@
|
||||
id,type,name,rarity,weight,width,height,stack,value
|
||||
NULL,misc,Primer,1,0.00496,1,1,100,300
|
||||
NULL,misc,Gunpowder,1,0.00044,1,2,500,50
|
||||
NULL,bullet,5.56 AP Bullet,4,0.00992,1,1,60,5000
|
||||
NULL,bullet,5.56 FMJ Bullet,1,0.00992,1,1,60,750
|
||||
NULL,bullet,5.56 HP Bullet,2,0.00992,1,1,60,1800
|
||||
NULL,casing,5.56 Casing,1,0.00469,1,1,30,1000
|
||||
NULL,bullet,9mm AP Bullet,3,0.00992,1,1,60,4000
|
||||
NULL,bullet,9mm FMJ Bullet,1,0.00992,1,1,60,400
|
||||
NULL,bullet,9mm HP Bullet,2,0.00992,1,1,60,1500
|
||||
NULL,casing,9mm Casing,1,0.00469,1,1,30,750
|
||||
NULL,bullet,7.62x39 AP Bullet,4,0.00992,1,1,60,3500
|
||||
NULL,bullet,7.62x39 FMJ Bullet,1,0.00992,1,1,60,525
|
||||
NULL,bullet,7.62x39 HP Bullet,2,0.00992,1,1,60,1260
|
||||
NULL,casing,7.62x39 Casing,1,0.00469,1,1,30,500
|
|
Binary file not shown.
@ -1,4 +1,6 @@
|
||||
import sqlite3
|
||||
import csv
|
||||
import os
|
||||
|
||||
# Connect to the SQLite database
|
||||
conn = sqlite3.connect("items.db")
|
||||
@ -24,30 +26,24 @@ cursor.execute(
|
||||
"""
|
||||
)
|
||||
|
||||
# Define your data to insert
|
||||
data_to_insert = [
|
||||
("misc", "Primer", 1, 0.00496, 1, 1, 100, 300),
|
||||
("misc", "Gunpowder", 1, 0.00044, 1, 2, 500, 50),
|
||||
("bullet", "5.56 AP Bullet", 4, 0.00992, 1, 1, 60, 5000),
|
||||
("bullet", "5.56 FMJ Bullet", 1, 0.00992, 1, 1, 60, 750),
|
||||
("bullet", "5.56 HP Bullet", 2, 0.00992, 1, 1, 60, 1800),
|
||||
("casing", "5.56 Casing", 1, 0.00469, 1, 1, 30, 1000),
|
||||
("bullet", "9mm AP Bullet", 3, 0.00992, 1, 1, 60, 4000),
|
||||
("bullet", "9mm FMJ Bullet", 1, 0.00992, 1, 1, 60, 400),
|
||||
("bullet", "9mm HP Bullet", 2, 0.00992, 1, 1, 60, 1500),
|
||||
("casing", "9mm Casing", 1, 0.00469, 1, 1, 30, 750),
|
||||
("bullet", "7.62x39 AP Bullet", 4, 0.00992, 1, 1, 60, 3500),
|
||||
("bullet", "7.62x39 FMJ Bullet", 1, 0.00992, 1, 1, 60, 525),
|
||||
("bullet", "7.62x39 HP Bullet", 2, 0.00992, 1, 1, 60, 1260),
|
||||
("casing", "7.62x39 Casing", 1, 0.00469, 1, 1, 30, 500),
|
||||
]
|
||||
# Define the directory where the CSV file is located
|
||||
csv_directory = "data" # Change this to your directory path
|
||||
|
||||
# Insert data into the table without specifying the 'id' column
|
||||
for row in data_to_insert:
|
||||
cursor.execute(
|
||||
"INSERT INTO reloading (type, name, rarity, weight, width, height, stack, value) VALUES (?, ?, ?, ?, ?, ?, ?, ?)",
|
||||
row,
|
||||
)
|
||||
# Define the CSV file name
|
||||
csv_file = "reloading.csv" # Change this to your CSV file name
|
||||
|
||||
# Build the full path to the CSV file
|
||||
csv_path = os.path.join(csv_directory, csv_file)
|
||||
|
||||
# Read data from the CSV file and insert it into the table
|
||||
with open(csv_path, newline="") as csvfile:
|
||||
csv_reader = csv.reader(csvfile)
|
||||
next(csv_reader) # Skip the header row if it exists in the CSV
|
||||
for row in csv_reader:
|
||||
cursor.execute(
|
||||
"INSERT INTO reloading (type, name, rarity, weight, width, height, stack, value) VALUES (?, ?, ?, ?, ?, ?, ?, ?)",
|
||||
row,
|
||||
)
|
||||
|
||||
# Commit the changes and close the connection
|
||||
conn.commit()
|
||||
|
77
Database/update.py
Normal file
77
Database/update.py
Normal file
@ -0,0 +1,77 @@
|
||||
import sqlite3
|
||||
import csv
|
||||
import os
|
||||
|
||||
# Connect to the SQLite database
|
||||
conn = sqlite3.connect("items.db")
|
||||
cursor = conn.cursor()
|
||||
|
||||
# Define the directory where the CSV files are located
|
||||
csv_directory = "data" # Change this to your directory path
|
||||
|
||||
# Define the CSV file names
|
||||
csv_file_reloading = "reloading.csv" # Change this to your reloading CSV file name
|
||||
csv_file_ammo = "ammo.csv" # Change this to your new_table CSV file name
|
||||
|
||||
# Build the full paths to the CSV files
|
||||
csv_path_reloading = os.path.join(csv_directory, csv_file_reloading)
|
||||
csv_path_ammo = os.path.join(csv_directory, csv_file_ammo)
|
||||
|
||||
# Define the table schema for reloading
|
||||
cursor.execute(
|
||||
"""
|
||||
CREATE TABLE IF NOT EXISTS reloading (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
type TEXT,
|
||||
name TEXT,
|
||||
rarity INTEGER,
|
||||
weight REAL,
|
||||
width INTEGER,
|
||||
height INTEGER,
|
||||
stack INTEGER,
|
||||
value INTEGER
|
||||
)
|
||||
"""
|
||||
)
|
||||
|
||||
# Define the table schema for new_table
|
||||
cursor.execute(
|
||||
"""
|
||||
CREATE TABLE IF NOT EXISTS ammo (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
type TEXT,
|
||||
name TEXT,
|
||||
rarity INTEGER,
|
||||
weight REAL,
|
||||
width INTEGER,
|
||||
height INTEGER,
|
||||
stack INTEGER,
|
||||
value INTEGER,
|
||||
gunpowder INTEGER
|
||||
)
|
||||
"""
|
||||
)
|
||||
|
||||
|
||||
# Function to load data from a CSV file into a table
|
||||
def load_csv_data(csv_path, table_name, cursor):
|
||||
with open(csv_path, newline="") as csvfile:
|
||||
csv_reader = csv.reader(csvfile)
|
||||
next(csv_reader) # Skip the header row if it exists in the CSV
|
||||
for row in csv_reader:
|
||||
# Exclude the first column (id) from the row
|
||||
values = row[1:]
|
||||
placeholders = ", ".join(["?"] * len(values))
|
||||
insert_query = f"INSERT INTO {table_name} VALUES (NULL, {placeholders})"
|
||||
cursor.execute(insert_query, values)
|
||||
|
||||
|
||||
# Load data from the reloading CSV file into the reloading table
|
||||
load_csv_data(csv_path_reloading, "reloading", cursor)
|
||||
|
||||
# Load data from the new_table CSV file into the new_table table
|
||||
load_csv_data(csv_path_ammo, "ammo", cursor)
|
||||
|
||||
# Commit the changes and close the connection
|
||||
conn.commit()
|
||||
conn.close()
|
Loading…
Reference in New Issue
Block a user