1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
#!/usr/bin/env python3
import csv
import mxl_types
from argparse import ArgumentParser
from pathlib import Path
from sqlalchemy import create_engine, text
from sqlalchemy.orm import Session
def generate_tcs():
# TODO
# grab weapons, armor, misc? with spawnable=1 *and* who have itemtype with TreasureClass=1 (any itemtype? just direct?)
# qlvl 1-3 in weap3, 4-6 in weap6, 7-9 in weap9 ... 91-93 in weap93
# armo3 ... armo99
# vanilla has bow3 ... bow87 as well, unknown but probably based on the itemtype having Shoots and Quiver
# don't know if misc TCs are generated, neither median nor vanilla actually uses them if they are
pass
def create_db(folder):
engine = create_engine("sqlite+pysqlite:///:memory:", echo=False)
mxl_types.BaseDAO.metadata.create_all(engine)
try1 = (Path(folder) / "Data" / "global" / "excel")
if try1.exists():
data_folder = try1
else:
data_folder = folder
types = [
mxl_types.ItemRatio,
mxl_types.ItemType,
mxl_types.Weapon,
mxl_types.Armor,
mxl_types.Misc,
mxl_types.UniqueItem,
mxl_types.SetItem,
mxl_types.TreasureClass,
]
for mytype in types:
file = data_folder / mytype.filename
with file.open(encoding='windows-1252') as csvfile, Session(engine) as session:
reader = csv.DictReader(csvfile, dialect='excel-tab')
for csv_row in reader:
db_row = mytype(csv_row)
if not db_row.is_valid():
continue
session.add(db_row)
session.commit()
count = session.scalar(text(f'select count(*) from {mytype.__tablename__}'))
print(f'Counted {count} {mytype.__tablename__}')
def handle_args():
parser = ArgumentParser()
parser.add_argument('folder', help='Location of Median XL .txt files')
return parser.parse_args()
def main():
args = handle_args()
create_db(args.folder)
if __name__ == '__main__':
import sys
sys.exit(main())
|