112 lines
4.5 KiB
Python
112 lines
4.5 KiB
Python
import os
|
|
import sys
|
|
import time
|
|
from dotenv import load_dotenv
|
|
|
|
import db
|
|
import importer
|
|
|
|
def main():
|
|
# Load configuration
|
|
load_dotenv()
|
|
|
|
db_host = os.getenv("DB_HOST", "localhost")
|
|
db_port = int(os.getenv("DB_PORT", "3306"))
|
|
db_user = os.getenv("DB_USER", "root")
|
|
db_password = os.getenv("DB_PASSWORD", "")
|
|
db_name = os.getenv("DB_NAME", "poe2_items")
|
|
item_bases_url = os.getenv("ITEM_BASES_URL", "https://repoe-fork.github.io/poe2/base_items.json")
|
|
skill_gems_url = os.getenv("SKILL_GEMS_URL", "https://repoe-fork.github.io/poe2/skill_gems.json")
|
|
item_classes_url = os.getenv("ITEM_CLASSES_URL", "https://repoe-fork.github.io/poe2/item_classes.json")
|
|
uniques_url = os.getenv("UNIQUES_URL", "https://repoe-fork.github.io/poe2/uniques.json")
|
|
|
|
print("=" * 60)
|
|
print("Path of Exile 2 Base Items MySQL Importer Starting")
|
|
print("=" * 60)
|
|
print(f"Target DB Host: {db_host}:{db_port}")
|
|
print(f"Target Database: {db_name}")
|
|
print(f"Target User: {db_user}")
|
|
print("-" * 60)
|
|
|
|
start_time = time.time()
|
|
conn = None
|
|
try:
|
|
# Step 1: Initialize Database & Table
|
|
print("Step 1: Connecting to MySQL & Initializing Schema...")
|
|
conn = db.init_db(
|
|
host=db_host,
|
|
port=db_port,
|
|
user=db_user,
|
|
password=db_password,
|
|
db_name=db_name
|
|
)
|
|
|
|
# Step 2: Download & Parse base items
|
|
print("\nStep 2: Downloading & Parsing remote base items JSON...")
|
|
items_data = importer.download_and_parse_items(item_bases_url)
|
|
|
|
# Step 3: Clear existing table contents
|
|
print("\nStep 3: Clearing existing records from 'item_bases' table...")
|
|
db.clear_items_table(conn)
|
|
|
|
# Step 4: Insert into MySQL
|
|
print("\nStep 4: Upserting base items records into 'item_bases' table...")
|
|
items_upserted_count = db.bulk_upsert_items(conn, items_data)
|
|
|
|
# Step 5: Download & Parse skill gems
|
|
print("\nStep 5: Downloading & Parsing remote skill gems JSON...")
|
|
skills_data = importer.download_and_parse_skills(skill_gems_url)
|
|
|
|
# Step 6: Clear existing skill gems table contents
|
|
print("\nStep 6: Clearing existing records from 'skill_gems' table...")
|
|
db.clear_skills_table(conn)
|
|
|
|
# Step 7: Insert skill gems into MySQL
|
|
print("\nStep 7: Upserting skill gems records into 'skill_gems' table...")
|
|
skills_upserted_count = db.bulk_upsert_skills(conn, skills_data)
|
|
|
|
# Step 8: Download & Parse item classes
|
|
print("\nStep 8: Downloading & Parsing remote item classes JSON...")
|
|
classes_data = importer.download_and_parse_item_classes(item_classes_url)
|
|
|
|
# Step 9: Clear existing item classes table contents
|
|
print("\nStep 9: Clearing existing records from 'item_classes' table...")
|
|
db.clear_item_classes_table(conn)
|
|
|
|
# Step 10: Insert item classes into MySQL
|
|
print("\nStep 10: Upserting item classes records into 'item_classes' table...")
|
|
classes_upserted_count = db.bulk_upsert_item_classes(conn, classes_data)
|
|
|
|
# Step 11: Download & Parse uniques
|
|
print("\nStep 11: Downloading & Parsing remote uniques JSON...")
|
|
uniques_data = importer.download_and_parse_uniques(uniques_url)
|
|
|
|
# Step 12: Clear existing uniques table contents
|
|
print("\nStep 12: Clearing existing records from 'item_uniques' table...")
|
|
db.clear_uniques_table(conn)
|
|
|
|
# Step 13: Insert uniques into MySQL
|
|
print("\nStep 13: Upserting uniques records into 'item_uniques' table...")
|
|
uniques_upserted_count = db.bulk_upsert_uniques(conn, uniques_data)
|
|
|
|
elapsed = time.time() - start_time
|
|
print("\n" + "=" * 60)
|
|
print("IMPORT PROCESS COMPLETED SUCCESSFULLY")
|
|
print(f"Total time elapsed: {elapsed:.2f} seconds")
|
|
print(f"Base items upserted: {items_upserted_count}")
|
|
print(f"Skill gems upserted: {skills_upserted_count}")
|
|
print(f"Item classes upserted: {classes_upserted_count}")
|
|
print(f"Uniques upserted: {uniques_upserted_count}")
|
|
print("=" * 60)
|
|
|
|
except Exception as e:
|
|
print(f"\n[ERROR] An error occurred during the import process: {e}", file=sys.stderr)
|
|
sys.exit(1)
|
|
finally:
|
|
if conn and conn.is_connected():
|
|
conn.close()
|
|
print("Database connection closed cleanly.")
|
|
|
|
if __name__ == "__main__":
|
|
main()
|