added more to the database
This commit is contained in:
parent
ac1c9bd30e
commit
95c30fb875
3
.vscode/settings.json
vendored
Normal file
3
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"python.analysis.typeCheckingMode": "off"
|
||||
}
|
Binary file not shown.
@ -3,7 +3,6 @@ import os
|
||||
import csv
|
||||
|
||||
|
||||
# Function to determine the data type of a value
|
||||
def get_data_type(value):
|
||||
try:
|
||||
int(value)
|
||||
@ -16,26 +15,45 @@ def get_data_type(value):
|
||||
return "TEXT"
|
||||
|
||||
|
||||
# Connect to the SQLite database
|
||||
conn = sqlite3.connect("items.db")
|
||||
# Connect to the SQLite database and delete existing tables
|
||||
conn = sqlite3.connect("database.db")
|
||||
cursor = conn.cursor()
|
||||
|
||||
# Get a list of CSV files in the "data" directory
|
||||
data_dir = "data" # Change this to your data directory path
|
||||
csv_files = [f for f in os.listdir(data_dir) if f.endswith(".csv")]
|
||||
|
||||
# Iterate through CSV files and create tables
|
||||
for csv_file in csv_files:
|
||||
table_name = os.path.splitext(csv_file)[
|
||||
0
|
||||
] # Remove the file extension to get the table name
|
||||
# Drop all existing tables except for sqlite_sequence
|
||||
cursor.execute("PRAGMA foreign_keys = OFF;")
|
||||
cursor.execute(
|
||||
"SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_sequence';"
|
||||
)
|
||||
existing_tables = cursor.fetchall()
|
||||
for table in existing_tables:
|
||||
cursor.execute(f"DROP TABLE IF EXISTS {table[0]};")
|
||||
|
||||
# Read the first row of the CSV file to determine the column names and data types
|
||||
# Commit the changes to delete existing tables
|
||||
conn.commit()
|
||||
|
||||
# Iterate through CSV files and create new tables
|
||||
for csv_file in csv_files:
|
||||
table_name = os.path.splitext(csv_file)[0]
|
||||
|
||||
# Read the first row of the CSV file to determine the column names
|
||||
with open(os.path.join(data_dir, csv_file), newline="") as csvfile:
|
||||
csv_reader = csv.reader(csvfile)
|
||||
header = next(csv_reader)
|
||||
|
||||
data_types = [get_data_type(value) for value in header]
|
||||
# Read the second row to determine data types
|
||||
with open(os.path.join(data_dir, csv_file), newline="") as csvfile:
|
||||
csv_reader = csv.reader(csvfile)
|
||||
next(csv_reader) # Skip the header row
|
||||
data_row = next(csv_reader)
|
||||
data_types = [get_data_type(value) for value in data_row]
|
||||
|
||||
# Add a primary key column if needed (replace 'unique_id' with your unique identifier column name)
|
||||
if "unique_id" in header:
|
||||
header[header.index("unique_id")] += " PRIMARY KEY"
|
||||
|
||||
# Generate the CREATE TABLE statement dynamically based on the column names and data types
|
||||
create_table_sql = f"CREATE TABLE IF NOT EXISTS {table_name} (\n"
|
||||
@ -46,6 +64,15 @@ for csv_file in csv_files:
|
||||
# Execute the CREATE TABLE statement
|
||||
cursor.execute(create_table_sql)
|
||||
|
||||
# Read and insert data from the CSV file into the table
|
||||
with open(os.path.join(data_dir, csv_file), newline="") as csvfile:
|
||||
csv_reader = csv.reader(csvfile)
|
||||
next(csv_reader) # Skip the header row
|
||||
for row in csv_reader:
|
||||
placeholders = ",".join(["?"] * len(row))
|
||||
insert_sql = f"INSERT INTO {table_name} VALUES ({placeholders});"
|
||||
cursor.execute(insert_sql, row)
|
||||
|
||||
# Commit the changes and close the connection
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
51
Database/data/gear.csv
Normal file
51
Database/data/gear.csv
Normal file
@ -0,0 +1,51 @@
|
||||
id,type,name,rarity,weight,height,width,stack,value,storage,plate
|
||||
NULL,rig,Hunting Vest,1,0.25,3,2,1,120000,6,NULL
|
||||
NULL,rig,Micro Chest Rig,1,0.30,2,3,1,140000,8,NULL
|
||||
NULL,rig,Minimalist Harness,1,1.00,3,3,1,160000,10,NULL
|
||||
NULL,rig,Chest Rig,2,0.70,3,4,1,180000,12,NULL
|
||||
NULL,rig,Heavy Vest,2,0.90,3,4,1,200000,14,NULL
|
||||
NULL,rig,Heavy Chest Rig,2,0.35,4,3,1,250000,16,NULL
|
||||
NULL,rig,Belt Rig,3,0.80,4,3,1,300000,18,NULL
|
||||
NULL,rig,Load Bearing Rig,3,1.00,4,4,1,350000,20,NULL
|
||||
NULL,rig,High Capacity Rig,4,0.65,3,4,1,400000,24,NULL
|
||||
NULL,rigArmor,Damaged Plate Carrier,2,4.50,3,3,1,250000,10,1
|
||||
NULL,rigArmor,Basic Plate Carrier,2,4.20,4,3,1,270000,12,1
|
||||
NULL,rigArmor,Precision Plate Carrier,3,5.90,4,3,1,300000,14,1
|
||||
NULL,rigArmor,Upgraded Plate Carrier,3,6.45,3,4,1,350000,17,1
|
||||
NULL,rigArmor,Multi Mission Plate Carrier,4,7.30,3,4,1,400000,18,1
|
||||
NULL,rigArmor,Arma Plate Carrier,4,8.15,4,4,1,450000,19,1
|
||||
NULL,rigArmor,Armored Plate Carrier,4,9.00,4,4,1,475000,20,1
|
||||
NULL,rigArmor,Ranger Plate Carrier,5,9.55,4,3,1,550000,23,1
|
||||
NULL,rigArmor,Assault Rig,5,12.40,3,4,1,580000,24,1
|
||||
NULL,rigArmor,Armored Vest,5,14.25,4,4,1,600000,25,1
|
||||
NULL,pack,Drawstring Bag,1,1.10,3,2,1,50000,6,NULL
|
||||
NULL,pack,Duffle Bag,1,2.12,2,4,1,80000,8,NULL
|
||||
NULL,pack,Sling Bag,1,1.85,3,3,1,100000,9,NULL
|
||||
NULL,pack,Rucksack,2,2.50,4,3,1,140000,12,NULL
|
||||
NULL,pack,Mini Bag,2,2.38,3,4,1,150000,12,NULL
|
||||
NULL,pack,Tourist Backpack,2,2.25,5,3,1,220000,15,NULL
|
||||
NULL,pack,Standard Backpack,2,1.80,4,4,1,250000,16,NULL
|
||||
NULL,pack,Tactical Backpack,3,2.00,5,4,1,400000,20,NULL
|
||||
NULL,pack,Takedown Backpack,3,2.50,7,3,1,500000,31,NULL
|
||||
NULL,pack,Battle Backpack,3,3.00,5,5,1,600000,25,NULL
|
||||
NULL,pack,Hiking Backpack,4,4.00,6,5,1,750000,30,NULL
|
||||
NULL,pack,Assault Backpack,4,6.00,7,5,1,1000000,35,NULL
|
||||
NULL,pack,Raid Backpack,5,8.00,8,5,1,1500000,40,NULL
|
||||
NULL,ears,Peltor Comtacs,2,1.54,2,2,1,NULL,NULL,NULL
|
||||
NULL,ears,Walker's Razor,2,0.95,2,2,1,NULL,NULL,NULL
|
||||
NULL,helmet,Steel Helmet (2),2,3.31,2,2,1,450000,NULL,NULL
|
||||
NULL,helmet,Motorcycle Helmet (1),1,4.19,2,2,1,120000,NULL,NULL
|
||||
NULL,helmet,Airsoft Replica Helmet (1),2,1.00,2,2,1,200000,NULL,NULL
|
||||
NULL,helmet,Military Helmet Class 4 High Cut,2,4.19,2,2,1,850000,NULL,NULL
|
||||
NULL,helmet,Military Helmet Class 4 Full,3,4.19,2,2,1,900000,NULL,NULL
|
||||
NULL,helmet,Military Helmet Class 4+ High Cut,3,4.19,2,2,1,1125000,NULL,NULL
|
||||
NULL,helmet,Military Helmet Class 4+ Full,4,4.19,2,2,1,1350000,NULL,NULL
|
||||
NULL,armor,Light Body Armor (3),2,7.72,3,3,1,1370000,NULL,NULL
|
||||
NULL,armor,Bullet Proof Vest (4),3,11.46,3,3,1,1658000,NULL,NULL
|
||||
NULL,plate,Class III Plate,2,5.00,3,3,1,1185000,NULL,NULL
|
||||
NULL,plate,Class IV Plate,3,6.00,3,3,1,1480000,NULL,NULL
|
||||
NULL,plate,Class IV+ Plate,4,7.00,3,3,1,1850000,NULL,NULL
|
||||
NULL,pouch,Pouch 1x1,1,0.15,1,1,1,25000,NULL,NULL
|
||||
NULL,pouch,Pouch 2x1,2,0.30,1,2,1,60000,NULL,NULL
|
||||
NULL,pouch,Pouch 3x1,3,0.45,1,3,1,130000,NULL,NULL
|
||||
NULL,pouch,Pouch 2x2,4,0.60,2,2,1,300000,NULL,NULL
|
|
16
Database/data/meds.csv
Normal file
16
Database/data/meds.csv
Normal file
@ -0,0 +1,16 @@
|
||||
id,type,name,rarity,weight,height,width,stack,value
|
||||
NULL,meds,Bandage,1,0.1411,1,1,5,6500
|
||||
NULL,meds,Small Health Kit (SHK),1,0.18,1,1,1,32000
|
||||
NULL,meds,Individual First Aid Kit,2,0.22046,1,1,1,60000
|
||||
NULL,meds,Dual First Aid Kit,2,0.44092,1,2,2,100000
|
||||
NULL,meds,Group First Aid Kit,3,0.88184,2,2,4,120000
|
||||
NULL,meds,Adaptive First Aid Kit,4,0.22046,1,1,1,90000
|
||||
NULL,meds,Surgery Kit,2,0.88185,1,1,2,100000
|
||||
NULL,meds,Surgery Kit (L),3,1.32278,1,2,3,150000
|
||||
NULL,meds,Adrenaline,3,0.22046,1,1,1,50000
|
||||
NULL,meds,Pain killer,1,0.05512,1,1,4,10000
|
||||
NULL,meds,Morphine,2,0.22046,1,1,1,40000
|
||||
NULL,meds,Caffeine (pill),2,0.05512,1,1,4,2500
|
||||
NULL,meds,Tourniquet,1,0.37371,1,1,2,11000
|
||||
NULL,meds,Muscle Stimulant,4,0,0,0,0,0
|
||||
NULL,meds,Rad-x,0,0,0,0,0,0
|
|
31
Database/data/parts.csv
Normal file
31
Database/data/parts.csv
Normal file
@ -0,0 +1,31 @@
|
||||
id,type,name,rarity,weight,height,width,stack,value,vital
|
||||
NULL,mag,STANAG 30-Round Magazine,1,0.375,2,1,1,100000,n
|
||||
NULL,mag,Glock 22 15-Round Magazine,1,0.21164,1,1,1,70000,n
|
||||
NULL,mag,Glock 33-Round Magazine,3,0.33069,2,1,1,180000,n
|
||||
NULL,mag,AK47 30-Round Magazine,1,0.375,2,1,1,80000,n
|
||||
NULL,muzzle,5.56 Flash Hider,1,0.33069,1,1,1,40000,n
|
||||
NULL,muzzle,5.56x45 Silencer,3,0.99869,2,1,1,1000000,n
|
||||
NULL,muzzle,5.56x45 Muzzle Break,2,0.33069,1,1,1,80000,n
|
||||
NULL,muzzle,7.62x39 Flash Hider,1,0.33069,1,1,1,40000,n
|
||||
NULL,muzzle,7.62x39 Silencer,3,0.99869,2,1,1,1000000,n
|
||||
NULL,muzzle,7.62x39 Slant Break,2,0.33069,1,1,1,80000,n
|
||||
NULL,rail,Laser,3,0,1,1,1,350000,n
|
||||
NULL,rail,Flashlight,2,0,1,1,1,100000,n
|
||||
NULL,forgrip,Vertical Foregrip,2,0,1,1,1,100000,n
|
||||
NULL,forgrip,Angled Foregrip,2,0,1,1,1,0,n
|
||||
NULL,optic,EOTech Holographic sight,2,0,1,1,1,700000,n
|
||||
NULL,stock,Ak47 Wood Stock,1,0,2,1,1,120000,n
|
||||
NULL,misc,AK47 Ribbed Dust Cover,1,0,2,1,1,130000,n
|
||||
NULL,Barrels,"16"" 5.56x45 Barrel",1,0,3,1,3,750000,y
|
||||
NULL,Barrels,"10"" 5.56x45 Barrel",3,0,2,1,2,1000000,y
|
||||
NULL,Barrels,"20"" 5.56x45 Barrel",2,0,3,1,2,1000000,y
|
||||
NULL,Handguards,"9"" Quad Rail Handguard",2,0,2,1,2,300000,y
|
||||
NULL,Handguards,"15"" Quad Rail Handguard",1,0,3,1,3,500000,y
|
||||
NULL,Pistol Grips,AR15 Polymer Pistol Grip,2,0,1,1,1,80000,y
|
||||
NULL,Pistol Grips,A2 Pistol Grip,1,0,1,1,1,70000,y
|
||||
NULL,Stocks,M16 Stock,1,0,2,1,1,200000,y
|
||||
NULL,Stocks,AR15 Polymer Stock,2,0,2,1,1,250000,y
|
||||
NULL,Handguards,AK47 Wood Handguard,1,0,1,1,1,120000,y
|
||||
NULL,Pistol Grips,AK47 Wood Pistol Grip,1,0,1,1,1,60000,y
|
||||
NULL,Pistols,"Glock 22 4.5"" Barrel",1,0,0,0,1,0,y
|
||||
NULL,Pistols,Glock 22 Upper Slide,1,0,0,0,1,0,y
|
|
6
Database/data/weapons.csv
Normal file
6
Database/data/weapons.csv
Normal file
@ -0,0 +1,6 @@
|
||||
id,type,name,rarity,weight,height,width,stack,value
|
||||
NULL,m16,M16 Receiver Set,3,7.06582,2,1,1,2000000
|
||||
NULL,ar15,AR15 Receiver Set,2,7.06582,2,1,1,1500000
|
||||
NULL,ak47,"Stripped AK47 16"" Barrel",2,7.06582,3,1,3,1250000
|
||||
NULL,glock22,Glock 22 Lower Receiver,1,0,0,0,0,0
|
||||
NULL,colt1911,Colt 1911 Lower Receiver,1,0,0,0,0,0
|
|
BIN
Database/database.db
Normal file
BIN
Database/database.db
Normal file
Binary file not shown.
@ -3,5 +3,7 @@
|
||||
starting_ids = {
|
||||
"reloading": 20000,
|
||||
"ammo": 10000,
|
||||
"craft": 30000
|
||||
}
|
||||
"craft": 20000,
|
||||
"gear": 30000,
|
||||
"parts": 40000,
|
||||
}
|
||||
|
@ -4,15 +4,12 @@ import sqlite3
|
||||
from id import starting_ids
|
||||
|
||||
# Connect to the SQLite database
|
||||
conn = sqlite3.connect("items.db")
|
||||
conn = sqlite3.connect("database.db")
|
||||
cursor = conn.cursor()
|
||||
|
||||
# Define the directory where the CSV files are located
|
||||
csv_directory = "data" # Change this to your directory path
|
||||
|
||||
# Define the starting IDs for each table type
|
||||
# starting_ids = {"reloading": 20000, "ammo": 10000, "craft": 30000}
|
||||
|
||||
|
||||
# Function to load data from a CSV file into a table
|
||||
def load_csv_data(csv_path, table_name, cursor, starting_id):
|
||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user