-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdbInit.py
2234 lines (1756 loc) · 68.1 KB
/
dbInit.py
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import json
import os
import sqlite3
from sqlite3 import Error
def create_connection(db_file):
conn = None
try:
conn = sqlite3.connect(db_file)
return conn
except Error as e:
print(e)
return conn
def create_table(conn, create_table_sql):
try:
c = conn.cursor()
c.execute(create_table_sql)
except Error as e:
print(e)
def create_class_spellcasting_link_table(conn):
statement = '''
CREATE TABLE IF NOT EXISTS class_spellcasting_link (
class_id TEXT,
spellcasting_id TEXT
)
'''
create_table(conn, statement)
def create_class_subclass_link_table(conn):
statement = '''
CREATE TABLE IF NOT EXISTS class_subclass_link (
class_id TEXT,
subclass_id TEXT
)
'''
create_table(conn, statement)
def create_class_saving_throws_table(conn):
statement = '''
CREATE TABLE IF NOT EXISTS class_saving_throws (
class_id TEXT,
ability_scores_id TEXT
)
'''
create_table(conn, statement)
def create_class_starting_equipment_link_table(conn):
statement = '''
CREATE TABLE IF NOT EXISTS class_starting_equipment_link (
class_id TEXT,
starting_equipment_id TEXT
)
'''
create_table(conn, statement)
def create_class_proficiencies_link_table(conn):
statement = '''
CREATE TABLE IF NOT EXISTS class_proficiencies_link (
class_id TEXT,
proficiency_id TEXT
)
'''
create_table(conn, statement)
def create_class_proficiency_choice_link_table(conn):
statement = '''
CREATE TABLE IF NOT EXISTS class_proficiency_choice_link (
choose INTEGER,
choice_group INTEGER,
class_id TEXT,
proficiency_id TEXT
)
'''
create_table(conn, statement)
def create_level_class_specific_sneak_attack_table(conn):
statement = '''
CREATE TABLE IF NOT EXISTS level_class_specific_sneak_attack (
level_id INTEGER,
dice_count INTEGER,
dice_value INTEGER
)
'''
create_table(conn, statement)
def create_level_class_specific_martial_arts_table(conn):
statement = '''
CREATE TABLE IF NOT EXISTS level_class_specific_martial_arts (
level_id INTEGER,
dice_count INTEGER,
dice_value INTEGER
)
'''
create_table(conn, statement)
def create_level_class_specific_creating_spell_slots_table(conn):
statement = '''
CREATE TABLE IF NOT EXISTS level_class_specific_creating_spell_slots (
level_id INTEGER,
spell_slot_level_1_sorcery_point_cost INTEGER,
spell_slot_level_2_sorcery_point_cost INTEGER,
spell_slot_level_3_sorcery_point_cost INTEGER,
spell_slot_level_4_sorcery_point_cost INTEGER,
spell_slot_level_5_sorcery_point_cost INTEGER
)
'''
create_table(conn, statement)
def create_level_spellcasting_table(conn):
statement = '''
CREATE TABLE IF NOT EXISTS level_spellcasting (
class_id TEXT,
level INT,
level_id INTEGER,
cantrips_known INTEGER,
spell_slots_level_1 INTEGER,
spell_slots_level_2 INTEGER,
spell_slots_level_3 INTEGER,
spell_slots_level_4 INTEGER,
spell_slots_level_5 INTEGER,
spell_slots_level_6 INTEGER,
spell_slots_level_7 INTEGER,
spell_slots_level_8 INTEGER,
spell_slots_level_9 INTEGER,
spells_known INTEGER
)
'''
create_table(conn, statement)
def create_class_specifics_table(conn):
statement = '''
CREATE TABLE IF NOT EXISTS class_specifics (
level INTEGER,
class_id TEXT,
level_id INTEGER,
action_surges INTEGER,
arcane_recovery_levels INTEGER,
aura_range INTEGER,
bardic_inspiration_die INTEGER,
brutal_critical_dice INTEGER,
channel_divinity_charges INTEGER,
destroy_undead_cr INTEGER,
extra_attacks INTEGER,
favored_enemies INTEGER,
favored_terrain INTEGER,
indomitable_uses INTEGER,
invocations_known INTEGER,
ki_points INTEGER,
magical_secrets_max_5 INTEGER,
magical_secrets_max_7 INTEGER,
magical_secrets_max_9 INTEGER,
metamagic_known INTEGER,
mystic_arcanum_level_6 INTEGER,
mystic_arcanum_level_7 INTEGER,
mystic_arcanum_level_8 INTEGER,
mystic_arcanum_level_9 INTEGER,
rage_count INTEGER,
rage_damage_bonus INTEGER,
song_of_rest_die INTEGER,
sorcery_points INTEGER,
unarmored_movement INTEGER,
wild_shape_fly BOOLEAN,
wild_shape_max_cr REAL,
wild_shape_swim BOOLEAN
)
'''
create_table(conn, statement)
def create_subclass_specifics_table(conn):
statement = '''
CREATE TABLE IF NOT EXISTS subclass_specifics (
class_id TEXT,
level INT,
level_id INTEGER,
additional_magical_secrets_max_lvl INTEGER
)
'''
create_table(conn, statement)
def create_levels_feature_choices_link_table(conn):
statement = '''
CREATE TABLE IF NOT EXISTS levels_feature_choices_link(
class_id TEXT,
level INT,
level_id INT,
feature_id TEXT
)
'''
create_table(conn, statement)
def create_levels_feature_link_table(conn):
statement = '''
CREATE TABLE IF NOT EXISTS levels_feature_link(
class_id TEXT,
level INT,
level_id INT,
feature_id TEXT
)
'''
create_table(conn, statement)
def create_levels_table(conn):
create_class_specifics_table(conn)
create_levels_feature_choices_link_table(conn)
create_levels_feature_link_table(conn)
create_subclass_specifics_table(conn)
create_level_spellcasting_table(conn)
create_level_class_specific_creating_spell_slots_table(conn)
create_level_class_specific_martial_arts_table(conn)
create_level_class_specific_sneak_attack_table(conn)
statement = '''
CREATE TABLE IF NOT EXISTS levels (
ability_score_bonuses INTEGER,
class_id TEXT,
id INTEGER,
level INTEGER,
prof_bonus INTEGER,
spell_slots_level_1 INTEGER,
spell_slots_level_2 INTEGER,
spell_slots_level_3 INTEGER,
spell_slots_level_4 INTEGER,
spell_slots_level_5 INTEGER,
subclass TEXT
)
'''
create_table(conn, statement)
with open('src/5e-SRD-Levels.json', 'r') as f:
data = json.load(f)
c = conn.cursor()
statement = '''
INSERT INTO levels (
ability_score_bonuses,
class_id,
id,
level,
prof_bonus,
spell_slots_level_1,
spell_slots_level_2,
spell_slots_level_3,
spell_slots_level_4,
spell_slots_level_5,
subclass
) VALUES (?,?,?,?,?,?,?,?,?,?,?)
'''
for level in data:
record = (
level["ability_score_bonuses"] if "ability_score_bonuses" in level.keys() else None,
level["class"]["url"].split("/")[-1] if "class" in level.keys() else None,
level["index"],
level["level"],
level["prof_bonus"] if "prof_bonus" in level.keys() else None,
level["spell_slots_level_1"] if "spell_slots_level_1" in level.keys() else None,
level["spell_slots_level_2"] if "spell_slots_level_2" in level.keys() else None,
level["spell_slots_level_3"] if "spell_slots_level_3" in level.keys() else None,
level["spell_slots_level_4"] if "spell_slots_level_4" in level.keys() else None,
level["spell_slots_level_5"] if "spell_slots_level_5" in level.keys() else None,
level["subclass"]["url"] if "url" in level["subclass"].keys() else None,
)
c.execute(statement, record)
if "feature_choices" in level.keys():
for feature in level["feature_choices"]:
statement2 = 'INSERT INTO levels_feature_choices_link (class_id, level, level_id, feature_id) VALUES (?,?,?,?)'
record2 = (level["class"]["url"].split('/')[-1], level["level"], level["index"], feature["url"].split("/")[-1])
c.execute(statement2, record2)
if "features" in level.keys():
for feature in level["features"]:
statement2 = 'INSERT INTO levels_feature_link (class_id, level, level_id, feature_id) VALUES (?,?,?,?)'
record2 = (level["class"]["url"].split("/")[-1], level["level"], level["index"], feature["url"].split("/")[-1])
c.execute(statement2, record2)
if "class_specific" in level.keys():
cs = level["class_specific"]
statement3 = '''
INSERT INTO class_specifics (
level,
class_id,
level_id,
action_surges,
arcane_recovery_levels,
aura_range,
bardic_inspiration_die,
brutal_critical_dice,
channel_divinity_charges,
destroy_undead_cr,
extra_attacks,
favored_enemies,
favored_terrain,
indomitable_uses,
invocations_known,
ki_points,
magical_secrets_max_5,
magical_secrets_max_7,
magical_secrets_max_9,
metamagic_known,
mystic_arcanum_level_6,
mystic_arcanum_level_7,
mystic_arcanum_level_8,
mystic_arcanum_level_9,
rage_count,
rage_damage_bonus,
song_of_rest_die,
sorcery_points,
unarmored_movement,
wild_shape_fly,
wild_shape_max_cr,
wild_shape_swim
) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
'''
record3 = (
level["level"],
level["class"]["url"].split("/")[-1],
level["index"],
cs["action_surges"] if "action_surges" in cs.keys() else None,
cs["arcane_recovery_levels"] if "arcane_recovery_levels" in cs.keys() else None,
cs["aura_range"] if "aura_range" in cs.keys() else None,
cs["bardic_inspiration_die"] if "bardic_inspiration_die" in cs.keys() else None,
cs["brutal_critical_dice"] if "brutal_critical_dice" in cs.keys() else None,
cs["channel_divinity_charges"] if "channel_divinity_charges" in cs.keys() else None,
cs["destroy_undead_cr"] if "destroy_undead_cr" in cs.keys() else None,
cs["extra_attacks"] if "extra_attacks" in cs.keys() else None,
cs["favored_enemies"] if "favored_enemies" in cs.keys() else None,
cs["favored_terrain"] if "favored_terrain" in cs.keys() else None,
cs["indomitable_uses"] if "indomitable_uses" in cs.keys() else None,
cs["invocations_known"] if "invocations_known" in cs.keys() else None,
cs["ki_points"] if "ki_points" in cs.keys() else None,
cs["magical_secrets_max_5"] if "magical_secrets_max_5" in cs.keys() else None,
cs["magical_secrets_max_7"] if "magical_secrets_max_7" in cs.keys() else None,
cs["magical_secrets_max_9"] if "magical_secrets_max_9" in cs.keys() else None,
cs["metamagic_known"] if "metamagic_known" in cs.keys() else None,
cs["mystic_arcanum_level_6"] if "mystic_arcanum_level_6" in cs.keys() else None,
cs["mystic_arcanum_level_7"] if "mystic_arcanum_level_7" in cs.keys() else None,
cs["mystic_arcanum_level_8"] if "mystic_arcanum_level_8" in cs.keys() else None,
cs["mystic_arcanum_level_9"] if "mystic_arcanum_level_9" in cs.keys() else None,
cs["rage_count"] if "rage_count" in cs.keys() else None,
cs["rage_damage_bonus"] if "rage_damage_bonus" in cs.keys() else None,
cs["song_of_rest_die"] if "song_of_rest_die" in cs.keys() else None,
cs["sorcery_points"] if "sorcery_points" in cs.keys() else None,
cs["unarmored_movement"] if "unarmored_movement" in cs.keys() else None,
cs["wild_shape_fly"] if "wild_shape_fly" in cs.keys() else None,
cs["wild_shape_max_cr"] if "wild_shape_max_cr" in cs.keys() else None,
cs["wild_shape_swim"] if "wild_shape_swim" in cs.keys() else None
)
c.execute(statement3, record3)
if "creating_spell_slots" in cs.keys():
statement6 = '''
INSERT INTO level_class_specific_creating_spell_slots (
level_id,
spell_slot_level_1_sorcery_point_cost,
spell_slot_level_2_sorcery_point_cost,
spell_slot_level_3_sorcery_point_cost,
spell_slot_level_4_sorcery_point_cost,
spell_slot_level_5_sorcery_point_cost
) VALUES (?,?,?,?,?,?)
'''
record6 = (
level["index"],
2,
3,
5,
6,
7
)
c.execute(statement6, record6)
if "martial_arts" in cs.keys():
statement7 = '''
INSERT INTO level_class_specific_martial_arts (
level_id,
dice_count,
dice_value
) VALUES (?,?,?)
'''
record7 = (
level["index"],
1,
cs["martial_arts"]["dice_value"]
)
c.execute(statement7, record7)
if "sneak_attack" in cs.keys():
statement8 = '''
INSERT INTO level_class_specific_sneak_attack (
level_id,
dice_count,
dice_value
) VALUES (?,?,?)
'''
record8 = (
level["index"],
cs["sneak_attack"]["dice_count"],
cs["sneak_attack"]["dice_value"]
)
c.execute(statement8, record8)
if "subclass_specific" in level.keys():
scs = level["subclass_specific"]
statement4 = '''
INSERT INTO subclass_specifics (class_id, level, level_id, additional_magical_secrets_max_lvl) VALUES (?,?,?,?)
'''
record4 = (
level["class"]["url"].split('/')[-1],
level["level"],
level["index"],
scs[
"additional_magical_secrets_max_lvl"] if "additional_magical_secrets_max_lvl" in scs.keys() else None
)
c.execute(statement4, record4)
if "spellcasting" in level.keys() and len(level["spellcasting"].keys()) > 0:
sc = level["spellcasting"]
statement5 = '''
INSERT INTO level_spellcasting (
class_id,
level,
level_id,
cantrips_known,
spell_slots_level_1,
spell_slots_level_2,
spell_slots_level_3,
spell_slots_level_4,
spell_slots_level_5,
spell_slots_level_6,
spell_slots_level_7,
spell_slots_level_8,
spell_slots_level_9,
spells_known
) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)
'''
record5 = (
level["class"]["url"].split('/')[-1],
level["level"],
level["index"],
sc["cantrips_known"] if "cantrips_known" in sc.keys() else None,
sc["spell_slots_level_1"] if "spell_slots_level_1" in sc.keys() else None,
sc["spell_slots_level_2"] if "spell_slots_level_2" in sc.keys() else None,
sc["spell_slots_level_3"] if "spell_slots_level_3" in sc.keys() else None,
sc["spell_slots_level_4"] if "spell_slots_level_4" in sc.keys() else None,
sc["spell_slots_level_5"] if "spell_slots_level_5" in sc.keys() else None,
sc["spell_slots_level_6"] if "spell_slots_level_6" in sc.keys() else None,
sc["spell_slots_level_7"] if "spell_slots_level_7" in sc.keys() else None,
sc["spell_slots_level_8"] if "spell_slots_level_8" in sc.keys() else None,
sc["spell_slots_level_9"] if "spell_slots_level_9" in sc.keys() else None,
sc["spells_known"] if "spells_known" in sc.keys() else None
)
c.execute(statement5, record5)
def create_classes_table(conn):
create_levels_table(conn)
create_class_proficiencies_link_table(conn)
create_class_proficiency_choice_link_table(conn)
create_class_saving_throws_table(conn)
create_class_starting_equipment_link_table(conn)
create_class_subclass_link_table(conn)
create_class_spellcasting_link_table(conn)
statement = '''
CREATE TABLE IF NOT EXISTS classes (
hit_die INTEGER,
id TEXT,
name TEXT
)
'''
create_table(conn, statement)
c = conn.cursor()
with open('src/5e-SRD-Classes.json', 'r') as f:
data = json.load(f)
for dnd_class in data:
statement = '''
INSERT INTO classes (hit_die, id, name) VALUES (?,?,?)
'''
record = (dnd_class["hit_die"], dnd_class["index"], dnd_class["name"])
c.execute(statement, record)
for prof in dnd_class["proficiencies"]:
statement2 = '''
INSERT INTO class_proficiencies_link (class_id, proficiency_id) VALUES (?,?)
'''
record2 = (dnd_class["index"], prof["url"].split("/")[-1])
c.execute(statement2, record2)
choice_group = 1
for prof_choice in dnd_class["proficiency_choices"]:
statement3 = '''
INSERT INTO class_proficiency_choice_link (
choose,
choice_group,
class_id,
proficiency_id
) VALUES (?,?,?,?)
'''
for choose_from in prof_choice["from"]:
record3 = (prof_choice["choose"], choice_group, dnd_class["index"], choose_from["url"].split("/")[-1])
c.execute(statement3, record3)
choice_group += 1
del choice_group
for saving_throw in dnd_class["saving_throws"]:
statement4 = '''
INSERT INTO class_saving_throws (
class_id,
ability_scores_id
) VALUES (?,?)
'''
record4 = (dnd_class["index"], saving_throw["url"].split("/")[-1])
c.execute(statement4, record4)
statement5 = '''
INSERT INTO class_starting_equipment_link (class_id, starting_equipment_id) VALUES (?,?)
'''
record5 = (dnd_class["index"], dnd_class["starting_equipment"]["url"].split("/")[-1])
c.execute(statement5, record5)
for subclass in dnd_class["subclasses"]:
statement6 = '''
INSERT INTO class_subclass_link (class_id, subclass_id) VALUES (?,?)
'''
record6 = (dnd_class["index"], subclass["url"].split("/")[-1])
c.execute(statement6, record6)
if len(dnd_class["spellcasting"].keys()) > 0:
statement7 = '''
INSERT INTO class_spellcasting_link (class_id, spellcasting_id) VALUES (?,?)
'''
record7 = (
dnd_class["index"],
dnd_class["spellcasting"]["url"].split("/")[-1]
)
c.execute(statement7, record7)
def create_skills_table(conn):
statement = '''CREATE TABLE IF NOT EXISTS skills (
id TEXT,
name TEXT,
description TEXT
)'''
create_table(conn, statement)
statement = '''INSERT INTO skills(
id,
name,
description
) VALUES (?,?,?)'''
with open('src/5e-SRD-Skills.json', 'r') as f:
data = json.load(f)
for skill in data:
record = (
skill["index"],
skill["name"],
skill["desc"][0]
)
c = conn.cursor()
c.execute(statement, record)
def create_skills_as_link_table(conn):
statement = '''CREATE TABLE IF NOT EXISTS skills_ability_score_link (
ability_score_id TEXT,
skill_id TEXT
)'''
create_table(conn, statement)
def create_ability_scores_table(conn):
statement = '''CREATE TABLE IF NOT EXISTS ability_scores (
id TEXT,
name TEXT,
full_name TEXT,
description TEXT,
check_description TEXT
)'''
create_table(conn, statement)
with open('src/5e-SRD-Ability-Scores.json', 'r') as f:
data = json.load(f)
statement = '''INSERT INTO ability_scores (
id,
name,
full_name,
description,
check_description
) VALUES (?,?,?,?,?)'''
for a_s in data:
record = (
a_s["index"],
a_s["name"],
a_s["full_name"],
a_s["desc"][0],
a_s["desc"][1]
)
c = conn.cursor()
c.execute(statement, record)
for skill in a_s["skills"]:
c.execute('INSERT INTO skills_ability_score_link (ability_score_id, skill_id) VALUES (?,?)',(a_s["index"], skill["url"].split("/")[-1]))
def create_monster_sense_link_table(conn):
statement = '''CREATE TABLE IF NOT EXISTS monster_senses_link (
monster_id TEXT,
sense TEXT
)'''
create_table(conn, statement)
def create_monster_reactions_link_table(conn):
statement = '''CREATE TABLE IF NOT EXISTS monster_reactions_link (
monster_id TEXT,
reaction TEXT,
description TEXT
)'''
create_table(conn, statement)
def create_monster_proficiencies_link_table(conn):
statement = '''CREATE TABLE IF NOT EXISTS monster_proficiencies_link (
monster_id TEXT,
proficiency TEXT
)'''
create_table(conn, statement)
def create_condition_immunities_link_table(conn):
sql_create_prop_equip_link_table = '''CREATE TABLE IF NOT EXISTS conditional_immunities (
monster_id TEXT,
condition TEXT
)'''
create_table(conn, sql_create_prop_equip_link_table)
def create_monsters_table(conn):
create_skills_as_link_table(conn)
create_skills_table(conn)
create_ability_scores_table(conn)
create_monster_reactions_link_table(conn)
create_monster_sense_link_table(conn)
create_condition_immunities_link_table(conn)
create_monster_proficiencies_link_table(conn)
sql_create_monster_table = """
CREATE TABLE IF NOT EXISTS monsters (
alignment TEXT,
armor_class INTEGER,
challenge_rating INTEGER,
charisma INTEGER,
constitution INTEGER,
damage_immunities TEXT,
damage_resistances TEXT,
damage_vulnerabilities TEXT,
dexterity INTEGER,
hit_dice TEXT,
hit_points INTEGER,
id TEXT PRIMARY KEY NOT NULL,
intelligence INTEGER,
languages TEXT,
name TEXT NOT NULL,
other_speeds TEXT,
size TEXT,
speed_climb TEXT,
speed_hover TEXT,
speed_walk TEXT,
speed_burrow TEXT,
speed_fly TEXT,
speed_swim TEXT,
strength INTEGER,
subtype TEXT,
type TEXT,
wisdom INTEGER
);
"""
create_table(conn, sql_create_monster_table)
with open('src/5e-SRD-Monsters.json') as f:
data = json.load(f)
for monster in data:
statement = '''
INSERT INTO monsters(
alignment,
armor_class,
challenge_rating,
charisma,
constitution,
damage_immunities,
damage_resistances,
damage_vulnerabilities,
dexterity,
hit_dice,
hit_points,
id,
intelligence,
languages,
name,
other_speeds,
size,
speed_climb,
speed_hover,
speed_walk,
speed_burrow,
speed_fly,
speed_swim,
strength,
subtype,
type,
wisdom
) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)'''
record = (
monster["alignment"] if "alignment" in monster.keys() else None,
monster["armor_class"] if "armor_class" in monster.keys() else None,
monster["challenge_rating"] if "challenge_rating" in monster.keys() else None,
monster["charisma"] if "charisma" in monster.keys() else None,
monster["constitution"] if "constitution" in monster.keys() else None,
", ".join(monster["damage_immunities"]) if "damage_immunities" in monster.keys() else None,
", ".join(monster["damage_resistances"]) if "damage_resistances" in monster.keys() else None,
", ".join(monster["damage_vulnerabilities"]) if "damage_vulnerabilities" in monster.keys() else None,
monster["dexterity"] if "dexterity" in monster.keys() else None,
monster["hit_dice"] if "hit_dice" in monster.keys() else None,
monster["hit_points"] if "hit_points" in monster.keys() else None,
monster["index"] if "index" in monster.keys() else None,
monster["intelligence"] if "intelligence" in monster.keys() else None,
monster["languages"] if "languages" in monster.keys() else None,
monster["name"] if "name" in monster.keys() else None,
"; ".join([f'{form["form"]}: walk - {form["speed"]["walk"]} climb - {form["speed"]["climb"] if "climb" in form["speed"].keys() else ""}' for form in monster["other_speeds"]]) if "other_speeds" in monster.keys() else None,
monster["size"] if "size" in monster.keys() else None,
monster["speed"]["climb"] if "climb" in monster["speed"].keys() else None,
monster["speed"]["hover"] if "hover" in monster["speed"].keys() else None,
monster["speed"]["walk"] if "walk" in monster["speed"].keys() else None,
monster["speed"]["burrow"] if "burrow" in monster["speed"].keys() else None,
monster["speed"]["fly"] if "fly" in monster["speed"].keys() else None,
monster["speed"]["swim"] if "swim" in monster["speed"].keys() else None,
monster["strength"] if "strength" in monster.keys() else None,
monster["subtype"] if "subtype" in monster.keys() else None,
monster["type"] if "type" in monster.keys() else None,
monster["wisdom"] if "wisdom" in monster.keys() else None
)
c = conn.cursor()
c.execute(statement, record)
if "senses" in monster.keys():
for sense in monster["senses"]:
statement = '''INSERT INTO monster_senses_link(monster_id, sense) VALUES (?,?)'''
record = (monster["index"], f'{sense} - {monster["senses"][sense]}')
c.execute(statement, record)
if "reactions" in monster.keys():
for reaction in monster["reactions"]:
statement = '''INSERT INTO monster_reactions_link(monster_id, reaction, description) VALUES (?,?,?)'''
record = (monster["index"], reaction["name"], reaction["desc"])
c.execute(statement, record)
if len(monster["condition_immunities"]) > 0:
for condition in monster["condition_immunities"]:
statement = '''INSERT INTO conditional_immunities(monster_id, condition) VALUES (?,?)'''
record = (monster["index"], condition["url"].split("/")[-1])
c.execute(statement, record)
if len(monster["proficiencies"]) > 0:
for proficiency in monster["proficiencies"]:
statement = '''INSERT INTO monster_proficiencies_link(monster_id, proficiency) VALUES (?,?)'''
record = (monster["index"], proficiency["url"].split("/")[-1])
c.execute(statement, record)
def create_prop_equip_link_table(conn):
sql_create_prop_equip_link_table = '''CREATE TABLE IF NOT EXISTS property_equipment_link (
equipment_id TEXT,
property TEXT
)'''
create_table(conn, sql_create_prop_equip_link_table)
def damage_types_table(conn):
sql_create_damage_types_table = '''CREATE TABLE IF NOT EXISTS damage_types (
id TEXT,
name TEXT,
description TEXT
)'''
create_table(conn, sql_create_damage_types_table)
with open('src/5e-SRD-Damage-Types.json') as f:
data = json.load(f)
for damage_type in data:
statement = '''INSERT INTO damage_types (id, name, description) VALUES (?,?,?)'''
record = (damage_type["index"], damage_type["name"], damage_type["desc"][0])
c = conn.cursor()
c.execute(statement, record)
def create_weapon_properties_table(conn):
sql_create_damage_types_table = '''CREATE TABLE IF NOT EXISTS weapon_properties (
id TEXT,
name TEXT,
description TEXT
)'''
create_table(conn, sql_create_damage_types_table)
with open('src/5e-SRD-Weapon-Properties.json') as f:
data = json.load(f)
for weapon_property in data:
statement = '''INSERT INTO weapon_properties (id, name, description) VALUES (?,?,?)'''
record = (weapon_property["index"], weapon_property["name"], weapon_property["desc"][0])
c = conn.cursor()
c.execute(statement, record)
def create_equipment_contents_link_table(conn):
sql_create_prop_equip_link_table = '''CREATE TABLE IF NOT EXISTS equipment_contents_link (
equipment_id TEXT,
content_id TEXT
)'''
create_table(conn, sql_create_prop_equip_link_table)
def create_equipment_table(conn):
create_weapon_properties_table(conn)
damage_types_table(conn)
create_equipment_contents_link_table(conn)
create_prop_equip_link_table(conn)
create_equipment_categories_table(conn)
sql_create_equipment_table = """
CREATE TABLE IF NOT EXISTS equipment (
armor_category TEXT,
armor_class_base INTEGER,
armor_class_dex_bonus BOOLEAN,
armor_class_max_bonus INTEGER,
capacity TEXT,
category_range TEXT,
cost TEXT,
damage_dice_2h TEXT,
damage_bonus_2h INTEGER,
damage_type_2h TEXT,
damage_dice TEXT,
damage_bonus INTEGER,
damage_type TEXT,
description TEXT,
equipment_category TEXT,
equipment_category_id TEXT,
gear_category TEXT,
id TEXT PRIMARY KEY NOT NULL,
name TEXT NOT NULL,
range_normal INTEGER,
range_long INTEGER,
special TEXT,
speed TEXT,
stealth_disadvantage BOOLEAN,
str_minimum INTEGER,
throw_range_normal INTEGER,
throw_range_long INTEGER,
tool_category TEXT,
vehicle_category TEXT,
weapon_category TEXT,
weapon_range TEXT,
weight INTEGER
);
"""
create_table(conn, sql_create_equipment_table)
with open('src/5e-SRD-Equipment.json') as f:
data = json.load(f)
for equipment in data:
e_record = (
equipment["armor_category"] if "armor_category" in equipment.keys() else None,
equipment["armor_class"]["base"] if "armor_class" in equipment.keys() else None,
equipment["armor_class"]["dex_bonus"] if "armor_class" in equipment.keys() else None,
equipment["armor_class"]["max_bonus"] if "armor_class" in equipment.keys() else None,
equipment["capacity"] if "capacity" in equipment.keys() else None,
equipment["category_range"] if "category_range" in equipment.keys() else None,
f'{equipment["cost"]["quantity"]} {equipment["cost"]["unit"]}' if "cost" in equipment.keys() else None,
equipment["2h_damage"]["damage_dice"] if "2h_damage" in equipment.keys() else None,
equipment["2h_damage"]["damage_bonus"] if "2h_damage" in equipment.keys() else None,
equipment["2h_damage"]["damage_type"]["name"] if "2h_damage" in equipment.keys() else None,
equipment["damage"]["damage_dice"] if "damage" in equipment.keys() else None,
equipment["damage"]["damage_bonus"] if "damage" in equipment.keys() else None,
equipment["damage"]["damage_type"]["name"] if "damage" in equipment.keys() else None,
equipment["desc"][0] if "desc" in equipment.keys() else None,
equipment["equipment_category"] if "equipment_category" in equipment.keys() else None,
equipment["equipment_category"].lower().replace(" ","-") if "equipment_category" in equipment.keys() else None,
equipment["gear_category"] if "gear_category" in equipment.keys() else None,
equipment["index"],
equipment["name"],
equipment["range"]["normal"] if "range" in equipment.keys() else None,
equipment["range"]["long"] if "range" in equipment.keys() else None,
equipment["special"][0] if "special" in equipment.keys() else None,
f'{equipment["speed"]["quantity"]} {equipment["speed"]["unit"]}' if "speed" in equipment.keys() else None,
equipment["stealth_disadvantage"] if "stealth_disadvantage" in equipment.keys() else None,
equipment["str_minimum"] if "str_minimum" in equipment.keys() else None,
equipment["throw_range"]["normal"] if "throw_range" in equipment.keys() else None,
equipment["throw_range"]["long"] if "throw_range" in equipment.keys() else None,