Fix stupid mistake, add arguments for specifying input/output directories
This commit is contained in:
parent
1b88e6a526
commit
0b24072ca2
25
parse_db.py
25
parse_db.py
@ -10,24 +10,35 @@ Description: This script parses key elements of IW4MAdmin's database into a sing
|
|||||||
import sqlite3
|
import sqlite3
|
||||||
import argparse
|
import argparse
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
|
|
||||||
def setup_argparser():
|
def setup_argparser():
|
||||||
parser = argparse.ArgumentParser(description="Parses IW4MAdmin's database into a consolidated, easy-to-read format.")
|
parser = argparse.ArgumentParser(description="Accurately parses IW4MAdmin's database into a consolidated, easy-to-read format.")
|
||||||
|
parser.add_argument('-p', '--path', type=str, default="Database.db", help="Path to the IW4MAdmin database file.")
|
||||||
|
parser.add_argument('-o', '--output', type=str, help="Output directory for the parsed database file.")
|
||||||
return parser.parse_args()
|
return parser.parse_args()
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
# Parse arguments (for future expansion, currently only handles help)
|
|
||||||
args = setup_argparser()
|
args = setup_argparser()
|
||||||
|
|
||||||
# Check if Database.db exists
|
db_path = args.path
|
||||||
if not os.path.isfile("Database.db"):
|
output_dir = args.output if args.output else '.' # Use current directory if no output directory is specified
|
||||||
print("No database file (Database.db) found. Please ensure the file is in the same directory as this script.")
|
output_db_path = os.path.join(output_dir, "Database_parsed.db")
|
||||||
|
|
||||||
|
# Ensure the output directory exists
|
||||||
|
if not os.path.isdir(output_dir):
|
||||||
|
print(f"Creating output directory at {output_dir}")
|
||||||
|
os.makedirs(output_dir, exist_ok=True)
|
||||||
|
|
||||||
|
# Check if the specified Database.db exists
|
||||||
|
if not os.path.isfile(db_path):
|
||||||
|
print(f"No database file ({db_path}) found. Please ensure the file exists.")
|
||||||
return # Exit the script if file not found
|
return # Exit the script if file not found
|
||||||
|
|
||||||
existing_conn = sqlite3.connect("Database.db")
|
existing_conn = sqlite3.connect(db_path)
|
||||||
existing_cur = existing_conn.cursor()
|
existing_cur = existing_conn.cursor()
|
||||||
|
|
||||||
new_conn = sqlite3.connect("Database_parsed.db")
|
new_conn = sqlite3.connect(output_db_path)
|
||||||
new_cur = new_conn.cursor()
|
new_cur = new_conn.cursor()
|
||||||
|
|
||||||
# ------------------- IPAddresses Table -------------------
|
# ------------------- IPAddresses Table -------------------
|
||||||
|
Loading…
Reference in New Issue
Block a user