-
Notifications
You must be signed in to change notification settings - Fork 1
/
pagefuncs.py
859 lines (748 loc) · 36.4 KB
/
pagefuncs.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
from datetime import date, datetime
import json
import random
from urllib import response
from flask import render_template, request, url_for
import requests
from consthandler import CLASSPECT_DICT, ClasspectComponent, fetchAllClasspects, fetchAllDuals, getAllClasspects, getRandomClasspect
from flask_babel import format_datetime
def compileArr(array):
display = "".join(array)
return display
def invalidCspect(aspect):
return (not aspect.isCanon() and not aspect.isDual())
def invalidCspects(aspects):
for i in aspects:
if not invalidCspect(i):
return False
return True
def dualName(unknown): # compatibility function
if unknown.__class__ != [].__class__:
if unknown.__class__ == ClasspectComponent("base", "class").__class__:
if unknown.isCanon():
return "<a href='#collapseOne' class='link-primary text-decoration-none' onclick='copycat(\"" + unknown.name + "\");' role='button'>" + unknown.name + "</a>"
return unknown.name
else:
x = ""
for i in unknown:
try:
x = "<a href='#collapseOne' class='link-secondary' onclick='copycat(\"" + i.name + "\");' role='button'>" + x + "</a><a href='#collapseOne' class='link-secondary' onclick='copycat(\"" + \
i.name + "\");' role='button'>" + i.name + "</a>"
if len(unknown) > 1 and i != unknown[-1]:
x = "<a href='#collapseOne' class='link-secondary' onclick='copycat(\"" + i.name + \
"\");' role='button'>" + x + "</a>"
except:
pass
return x
def dualClean(unknown): # dualName without js
if unknown.__class__ != [].__class__:
return unknown.name
else:
x = ""
for i in unknown:
try:
x += i.name
except:
pass
return x
def dualTypeInvTest(unknown): # ugly copy of dualName. can't figure out how to make nicer
if unknown.__class__ != [].__class__:
return unknown.typeInverse()
else:
x = ""
for i in unknown:
try:
x += i.typeInverse()
except:
pass
return x
def wrapLi(inputlist, text):
return "<li>" + text + ": " + inputlist + "</li>"
return "<ul class='list-inline'><li class='list-inline-item'><span class='fw-bolder'>•</span> " + text + ": </li><li class='list-inline-item'>" + inputlist + "</li></ul>"
def magicant(form, results, formState):
for i in results:
megaarr = (
not(results[i].isCanon() or results[i].isDual())
and
(
ClasspectComponent(
results[i].name, results[i].typeInverse()).isCanon()
or
ClasspectComponent(
results[i].name, results[i].typeInverse()).isDual()
)
and
(
(invalidCspect(results[results[i].typeInverse()]))
or
(
formState["math"]
and
(
(invalidCspect(
results["math"+results[i].typeInverse()]))
and
(i == "math"+results[i].type)
)
)
)
)
if megaarr:
results = {}
newForm = {"class": form["aspect"], "aspect": form["class"],
"mathclass": form["mathclass"], "mathaspect": form["mathaspect"]}
if formState["math"]:
print(i)
if i == "class":
h = "aspect"
elif i == "aspect":
h = "class"
if (invalidCspect(ClasspectComponent(form["math"+h], h))):
newForm["mathaspect"] = form["mathclass"]
newForm["mathclass"] = form["mathaspect"]
if i == "class" or i == "aspect":
newForm["class"] = form["aspect"]
newForm["aspect"] = form["class"]
else:
newForm["class"] = form["class"]
newForm["aspect"] = form["aspect"]
for x in newForm:
results[x] = ClasspectComponent(
name=newForm[x].capitalize(), type=x.capitalize().replace("Math", ""))
last = list(i.name for i in results.values())
if len(last) != len(set(last)):
if last[0] == last[1]:
if not invalidCspect(ClasspectComponent(last[0], "class")):
validtype = "aspect"
results[validtype] = ClasspectComponent("", validtype)
elif not invalidCspect(ClasspectComponent(last[0], "aspect")):
validtype = "class"
results[validtype] = ClasspectComponent("", validtype)
try:
last[2]
except:
pass
else:
if last[2] == last[3]:
if not invalidCspect(ClasspectComponent(last[2], "class")):
validtype = "aspect"
results["math" +
validtype] = ClasspectComponent("", validtype)
elif not invalidCspect(ClasspectComponent(last[2], "aspect")):
validtype = "class"
results["math" +
validtype] = ClasspectComponent("", validtype)
return results
def sortByType(e):
return e.type
def makePrintable(formState, classpect_data):
for i in classpect_data:
if (dualClean(i) == ""):
formState["singular"] = dualTypeInvTest(i)
# else:
# formState["singular"] = False
fcs = "<div class='input-group display-inline-flex'><span class='form-control px-1' style='display: initial;'>"
fce = "</span><button type='submit' class='btn btn-primary'><i class='bi bi-search'></i></button></div>"
printable_class = dualName(classpect_data[0])
printable_aspect = dualName(classpect_data[1]) + emote(classpect_data[1])
if formState["singular"] == "class":
formState["singular"] = False
return [printable_class]
return [fcs, printable_class, fce]
elif formState["singular"] == "aspect":
formState["singular"] = False
return [printable_aspect]
return [fcs, printable_aspect, fce]
elif not (printable_aspect == "" or printable_class == ""):
of = " of "
return [printable_class, of, printable_aspect]
return [fcs, printable_class, of, printable_aspect, fce]
def dualFlavorText(formState, classpect_data):
dual_class_data = list(classpect_data[0].dualComponents())
dual_aspect_data = list(classpect_data[1].dualComponents())
dual_classpect_data = [dual_class_data, dual_aspect_data] # list of lists
# makes list, stringifies, puts the small tag + class around the string
printable_dual_classpect_flavor_text = wrapMuted(
"".join(makePrintable(formState, dual_classpect_data)))
return printable_dual_classpect_flavor_text
def wrapMuted(inputlist):
return "<small class='text-muted'>or: " + inputlist + "</small>"
def emote(aspect: ClasspectComponent, style="height: 24px;"):
if aspect.__class__ == [].__class__ or aspect.name == "" or (not aspect.isCanon() and not aspect.isDual()):
return ""
urlFront = "<a onclick='copycat(\""
urlFront2 = "\");' role='button'><img src='" + \
url_for('static', filename='images/')
urlMid = ".png' style='position: relative; bottom: 1px; "
urlBack = "' class='img-fluid' /></a>"
if aspect.isDual():
return " " + urlFront + aspect.dualComponents()[0].name + urlFront2 + aspect.dualComponents()[0].name + urlMid + style + urlBack + urlFront + aspect.dualComponents()[1].name + urlFront2 + aspect.dualComponents()[1].name + urlMid + style + urlBack
return " " + urlFront + aspect.name + urlFront2 + aspect.name + urlMid + style + urlBack
def mathValidator(form):
try:
form["mathclass"]
except:
form["mathclass"] = ""
form["mathaspect"] = ""
# if form["class"] + form["aspect"] != "":
# if not (invalidCspect(ClasspectComponent(form["class"],"class"))) or not (invalidCspect(ClasspectComponent(form["aspect"],"aspect"))):
# return True
# return False
results = {}
for i in form:
results[i] = (ClasspectComponent(name=form[i].capitalize(),
type=i.capitalize().replace("Math", "")))
try:
results["mathclass"] + results["class"]
except:
try:
results["mathaspect"] + results["aspect"]
except:
try:
results["mathclass"] - results["class"]
except:
try:
results["mathclass"] - results["aspect"]
except:
try:
results["class"] - results["mathclass"]
except:
try:
results["aspect"] - results["mathaspect"]
except:
pass
else:
return True
else:
return True
else:
return True
else:
return True
else:
return True
else:
return True
return False
def searchpage():
if len(request.args) > 0:
# json.loads(request.args["json"])
argargs = {}
# hidden = json.loads(request.args["json"])
for fixe in ["c", "a", "mc", "ma"]:
try:
argargs[fixe] = request.args[fixe]
except:
argargs[fixe] = ""
if "".join([value for key, value in argargs.items()]) != "":
request.method = "POST"
hidden = {"class": argargs["c"], "aspect": argargs["a"],
"mathclass": argargs["mc"], "mathaspect": argargs["ma"]}
if request.method == 'GET':
display = []
return render_template(
"bettersearch.html", classpects=fetchAllClasspects(),
display=display,
sitetitle="Lookup",
)
if request.method == "POST":
form = dict(request.form)
results = {}
if list(form.values()).count("") == len(form):
try:
hidden
except:
return render_template(
"bettersearch.html",
results=results, classpects=fetchAllClasspects(),
sitetitle="Lookup", display=""
)
else:
form = hidden
formState = {"dual": False, "math": False, "singular": False}
if len(form) >= 3:
try:
form["mathaspect"]
except:
form["mathaspect"] = ""
try:
form["mathclass"]
except:
form["mathclass"] = ""
if form["mathaspect"] != "" or form["mathclass"] != "":
formState["math"] = True
for i in form:
results[i] = ClasspectComponent(
name=form[i].capitalize(), type=i.capitalize().replace("Math", ""))
if results[i].isDual():
formState["dual"] = True
# fix the swapped aspect/class search
results = magicant(form, results, formState)
for i in results.values():
if i.isDual():
formState["dual"] = True
class_data = results["class"]
aspect_data = results["aspect"]
classpect_data = class_data, aspect_data
for i in classpect_data:
if (dualName(i) == ""):
formState["singular"] = dualTypeInvTest(i)
# generating the printable version
printable_classpect = "".join(makePrintable(formState, classpect_data))
# generating the dual flavor text
if formState["dual"]:
printable_dual_classpect_flavor_text = "<br>" + \
dualFlavorText(formState, classpect_data)
elif class_data.isCanon() and aspect_data.isCanon():
printable_dual_classpect_flavor_text = "<br><small class='text-muted'>Examples include: " + \
CLASSPECT_DICT[class_data.name][aspect_data.name] + "</small>"
else:
printable_dual_classpect_flavor_text = ""
# generating inverse and housetrapped
if not invalidCspects(classpect_data):
hr1 = "<hr>"
hr2 = "<hr>"
inverse_classpect_data = class_data.inverse(), aspect_data.inverse()
printable_inverse_classpect = wrapLi(
"".join(makePrintable(formState, inverse_classpect_data)), "Inverse")
if formState["dual"]:
printable_inverse_dual_classpect_flavor_text = "<ul style='margin-bottom: 0px'><li style='color: transparent'>" + \
dualFlavorText(
formState, inverse_classpect_data) + "</li></ul>"
else:
printable_inverse_dual_classpect_flavor_text = ""
housetrapped = """
<hr><p>Want a more detailed explanation?<br>
<small><strong>Click</strong> on any canon Classpect, and you can view information on it below!</small></p>
<div class="accordion" id="accordionExample">
<div class="card">
<div class="card-header" id="headingOne">
<h2 class="mb-0">
<button id="jstarget" class="btn collapsed" type="button" data-toggle="collapse" data-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne" disabled>
Please click on a Classpect!
</button>
</h2>
</div>
<div id="collapseOne" class="collapse open" aria-labelledby="headingOne">
<div class="card-body" style="padding: unset;">
<div class="embed-responsive" style="height:400px;">
<iframe class="embed-responsive-item w-100 h-100" id="housetrapped" src=""></iframe>
</div>
</div>
</div>
</div>
</div>"""
else:
hr1 = ""
hr2 = ""
printable_inverse_classpect = ""
printable_inverse_dual_classpect_flavor_text = ""
housetrapped = ""
# generating paired class
if not invalidCspect(class_data):
printable_paired_class = wrapLi(dualName(class_data.paired(
)), "Paired class for " + dualName(class_data)) # future me i am so sorry
if formState["dual"]:
printable_paired_dual_class_flavor_text = "<ul style='margin-bottom: 0px'><li style='color: transparent'>" + \
dualFlavorText(formState, (class_data.paired(
), ClasspectComponent("", "aspect"))) + "</li></ul>"
else:
printable_paired_dual_class_flavor_text = ""
else:
printable_paired_class = ""
printable_paired_dual_class_flavor_text = ""
if (((invalidCspect(class_data) and aspect_data.name == "") or (invalidCspect(aspect_data) and class_data.name == "") and aspect_data.name != class_data.name)):
hr2 = "<hr>"
# end basic classpect math generation!! :D
display = [printable_classpect, printable_dual_classpect_flavor_text, hr1, printable_inverse_classpect,
printable_inverse_dual_classpect_flavor_text, printable_paired_class, printable_paired_dual_class_flavor_text, hr2]
validmath = {}
if mathValidator(form):
# math tooltip generation
if formState["dual"]:
for i in classpect_data:
if (not i.isDual()) and (i.name != ""):
formState["dual"] = False
tooltip = [
"Add or subtract classpects to make Dual Classes!<br><small>It looks like you've searched for a "]
if not formState["dual"] and (class_data.isCanon() or aspect_data.isCanon()):
tooltip.extend(
"standard Classpect. This means you can add any other standard classpect to it, and it'll give you a unique dual!</small>")
validmath = fetchAllClasspects()
elif formState["dual"]:
components = {"class": [], "aspect": []}
for i in classpect_data:
if i.isDual():
components[i.type].extend(i.dualComponents())
validmath = {
"class": components["class"], "aspect": components["aspect"]}
if components["class"] == []:
pull = components["aspect"]
validmath["class"] = fetchAllClasspects()["class"]
elif components["aspect"] == []:
pull = components["class"]
validmath["aspect"] = fetchAllClasspects()["aspect"]
else:
pull = components["class"] + components["aspect"]
ex1 = random.choice(pull).name
ex2 = ex1
while ex2 == ex1:
ex2 = random.choice(pull).name
if not (class_data.isCanon() or aspect_data.isCanon()):
tooltip.extend("Dual Classpect. Since the Dual Classpect is made up of regular Classpects, you can subtract any of its components <span class='text-muted'>(like " +
ex1 + " or " + ex2 + ")</span> from your search term!</small>")
elif class_data.isCanon() or aspect_data.isCanon():
if class_data.isCanon():
sel = 0
elif aspect_data.isCanon():
sel = 1
ex3 = getRandomClasspect()[sel]
ex4 = ex3
while ex4 == ex3:
ex4 = getRandomClasspect()[sel]
tooltip.extend("mix of the two. Since the Dual Classpect is made up of regular Classpects, you can subtract any of its components <span class='text-muted'>(like " + ex1 + " or " + ex2 +
")</span> from your search term, but you can also add any regular classpect <span class='text-muted'>(like " + ex3 + " or " + ex4 + ")</span> to the non-Dual part of your search!</small>")
display.extend(tooltip)
elif (((not invalidCspect(class_data) and aspect_data.name == "") or (not invalidCspect(aspect_data) and class_data.name == "") and aspect_data.name != class_data.name)):
tooltip = ["Add or subtract classpects to make Dual Classes!"]
validmath = {}
display.extend(tooltip)
else:
validmath = {}
# math result generation
if formState["math"]:
mathdisplay = []
if mathValidator(form):
# math tooltip generation
if not formState["dual"] and (class_data.isCanon() or aspect_data.isCanon()):
summed_data = results["class"] + \
results["mathclass"], results["aspect"] + \
results["mathaspect"]
if (summed_data[0].name + summed_data[1].name) != "":
printable_sum = wrapLi(
"".join(makePrintable(formState, summed_data)), "Sum")
addit = "<ul style='margin-bottom: 0px'><li style='color: transparent'>" + \
dualFlavorText(
formState, summed_data) + "</li></ul>"
mathdisplay.extend([printable_sum, addit])
elif formState["dual"]:
if not (class_data.isCanon() or aspect_data.isCanon()):
summed_data = results["class"] - \
results["mathclass"], results["aspect"] - \
results["mathaspect"]
if (summed_data[0].name + summed_data[1].name) != "":
printable_sum = wrapLi(
"".join(makePrintable(formState, summed_data)), "Difference")
mathdisplay.extend([printable_sum])
elif class_data.isCanon() or aspect_data.isCanon():
summed_data = ()
if class_data.isCanon():
summed_data = results["class"] + \
results["mathclass"], results["aspect"] - \
results["mathaspect"]
elif aspect_data.isCanon():
summed_data = results["class"] - \
results["mathclass"], results["aspect"] + \
results["mathaspect"]
if (summed_data[0].name + summed_data[1].name) != "":
printable_sum = wrapLi(
"".join(makePrintable(formState, summed_data)), "Output")
addit = "<ul style='margin-bottom: 0px'><li style='color: transparent'>" + \
dualFlavorText(
formState, summed_data) + "</li></ul>"
mathdisplay.extend([printable_sum, addit])
elif (((invalidCspect(class_data) and aspect_data.name == "") or (invalidCspect(aspect_data) and class_data.name == "") and aspect_data.name != class_data.name)):
for i in classpect_data:
if invalidCspect(i):
if (form[i.typeInverse()] == "") and not invalidCspect(ClasspectComponent(form["math" + i.typeInverse()], i.typeInverse())):
summed_data = sorted((i, ClasspectComponent(
form["math" + i.typeInverse()], i.typeInverse())), key=sortByType, reverse=True)
printable_sum = wrapLi(
"".join(makePrintable(formState, summed_data)), "Output")
addit = "<ul style='margin-bottom: 0px'><li style='color: transparent'>" + \
dualFlavorText(
formState, summed_data) + "</li></ul>"
mathdisplay.extend([printable_sum, addit])
else:
mathdisplay = []
mathdisplay.extend([housetrapped])
display = compileArr(display)
mathdisplay = compileArr(mathdisplay)
niceresults = dict(results)
for k, v in niceresults.items():
niceresults[k] = v.name
return render_template(
"bettersearch.html",
results=results, niceresults=niceresults, classpects=fetchAllClasspects(),
sitetitle="Lookup", display=display, mathdisplay=mathdisplay, validator=mathValidator(form), validmath=validmath
)
def homepageget():
display = {}
display["date"] = format_datetime(datetime.now(), "EEE, MMM d, yyyy")
listy = [[{inx["type"]:ClasspectComponent(inx["name"], inx["type"]).__dict__}
for inx in types] for types in dict(fetchAllClasspects()).values()]
listy = [{"class": i["class"], "aspect":y["aspect"]}
for i in listy[0] for y in listy[1]]
random.Random(413).shuffle(listy)
listy = json.dumps(dict([(str(indexy), itemy)
for indexy, itemy in enumerate(listy)]))
# random.seed(413)
# seeder = random.getstate()
# random.Random(413).shuffle(listy)
dual_listy = fetchAllDuals()
dual_listy = [{"class": i, "aspect": y} for i in sorted(
dual_listy["class"]) for y in sorted(dual_listy["aspect"])]
random.Random(413).shuffle(dual_listy)
dual_listy = dict(sorted(enumerate(dual_listy), key=lambda item: item))
# random.Random(413).shuffle(loust)
daysNum = ((datetime.now().date() - date(2009, 4, 13)).days) % 4422
print(daysNum, "days")
smalldual_listy = [{"class": dual_listy[i]["class"], "aspect":dual_listy[i]["aspect"], "aspectduals":[component.__dict__ for component in ClasspectComponent(
dual_listy[i]["aspect"], "aspect").dualComponents()]} for i in range((abs(daysNum) - 3), (abs(daysNum) + 3))]
display["classpects"] = fetchAllClasspects()
dual_listy = json.dumps(dual_listy)
smalldual_listy = json.dumps(smalldual_listy)
return (display, listy, dual_listy, smalldual_listy)
def homepage():
pagevars = homepageget()
return render_template(
"cotd.html", sitetitle="Home", display=pagevars[0], listy=pagevars[1], dual_listy=pagevars[2], smalldual_listy=pagevars[3]
)
def testsearchpage():
# json.loads(request.args["json"])
argargs = {}
# hidden = json.loads(request.args["json"])
for fixe in ["c", "a", "mc", "ma"]:
try:
argargs[fixe] = request.args[fixe]
except:
argargs[fixe] = ""
# if "".join([value for value in argargs.values()]) != "":
# request.method = "POST"
form = {"class": argargs["c"], "aspect": argargs["a"],
"mathclass": argargs["mc"], "mathaspect": argargs["ma"]}
# response = requests.get(request.root_url + url_for("api_cspect"),
# params={"type": "class", "name": form["class"]})
formState = {"dual": False, "math": False, "singular": False}
# if len(form) >= 3:
# try:
# form["mathaspect"]
# except:
# form["mathaspect"] = ""
# try:
# form["mathclass"]
# except:
# form["mathclass"] = ""
if form["mathaspect"] != "" or form["mathclass"] != "":
formState["math"] = True
results = {}
for i in form:
results[i] = ClasspectComponent(
name=form[i].capitalize(), type=i.capitalize().replace("Math", ""))
if results[i].isDual():
formState["dual"] = True
# fix the swapped aspect/class search
results = magicant(form, results, formState)
for i in results.values():
if i.isDual():
formState["dual"] = True
class_data = results["class"]
aspect_data = results["aspect"]
classpect_data = class_data, aspect_data
for i in classpect_data:
if (dualName(i) == ""):
formState["singular"] = dualTypeInvTest(i)
# generating the printable version
printable_classpect = "".join(makePrintable(formState, classpect_data))
# generating the dual flavor text
if formState["dual"]:
printable_dual_classpect_flavor_text = "<br>" + \
dualFlavorText(formState, classpect_data)
elif class_data.isCanon() and aspect_data.isCanon():
printable_dual_classpect_flavor_text = "<br><small class='text-muted'>Examples include: " + \
CLASSPECT_DICT[class_data.name][aspect_data.name] + "</small>"
else:
printable_dual_classpect_flavor_text = ""
# generating inverse and housetrapped
if not invalidCspects(classpect_data):
hr1 = "<hr>"
hr2 = "<hr>"
inverse_classpect_data = class_data.inverse(), aspect_data.inverse()
printable_inverse_classpect = wrapLi(
"".join(makePrintable(formState, inverse_classpect_data)), "Inverse")
if formState["dual"]:
printable_inverse_dual_classpect_flavor_text = "<ul style='margin-bottom: 0px'><li style='color: transparent'>" + \
dualFlavorText(
formState, inverse_classpect_data) + "</li></ul>"
else:
printable_inverse_dual_classpect_flavor_text = ""
housetrapped = """
<hr><p>Want a more detailed explanation?<br>
<small><strong>Click</strong> on any canon Classpect, and you can view information on it below!</small></p>
<div class="accordion" id="accordionExample">
<div class="card">
<div class="card-header" id="headingOne">
<h2 class="mb-0">
<button id="jstarget" class="btn collapsed" type="button" data-toggle="collapse" data-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne" disabled>
Please click on a Classpect!
</button>
</h2>
</div>
<div id="collapseOne" class="collapse open" aria-labelledby="headingOne">
<div class="card-body" style="padding: unset;">
<div class="embed-responsive" style="height:400px;">
<iframe class="embed-responsive-item w-100 h-100" id="housetrapped" src=""></iframe>
</div>
</div>
</div>
</div>
</div>"""
else:
hr1 = ""
hr2 = ""
printable_inverse_classpect = ""
printable_inverse_dual_classpect_flavor_text = ""
housetrapped = ""
# generating paired class
if not invalidCspect(class_data):
printable_paired_class = wrapLi(dualName(class_data.paired(
)), "Paired class for " + dualName(class_data)) # future me i am so sorry
if formState["dual"]:
printable_paired_dual_class_flavor_text = "<ul style='margin-bottom: 0px'><li style='color: transparent'>" + \
dualFlavorText(formState, (class_data.paired(
), ClasspectComponent("", "aspect"))) + "</li></ul>"
else:
printable_paired_dual_class_flavor_text = ""
else:
printable_paired_class = ""
printable_paired_dual_class_flavor_text = ""
if (((invalidCspect(class_data) and aspect_data.name == "") or (invalidCspect(aspect_data) and class_data.name == "") and aspect_data.name != class_data.name)):
hr2 = "<hr>"
# end basic classpect math generation!! :D
display = [printable_classpect, printable_dual_classpect_flavor_text, hr1, printable_inverse_classpect,
printable_inverse_dual_classpect_flavor_text, printable_paired_class, printable_paired_dual_class_flavor_text, hr2]
validmath = {}
if mathValidator(form):
# math tooltip generation
if formState["dual"]:
for i in classpect_data:
if (not i.isDual()) and (i.name != ""):
formState["dual"] = False
tooltip = [
"Add or subtract classpects to make Dual Classes!<br><small>It looks like you've searched for a "]
if not formState["dual"] and (class_data.isCanon() or aspect_data.isCanon()):
tooltip.extend(
"standard Classpect. This means you can add any other standard classpect to it, and it'll give you a unique dual!</small>")
validmath = fetchAllClasspects()
elif formState["dual"]:
components = {"class": [], "aspect": []}
for i in classpect_data:
if i.isDual():
components[i.type].extend(i.dualComponents())
validmath = {
"class": components["class"], "aspect": components["aspect"]}
if components["class"] == []:
pull = components["aspect"]
validmath["class"] = fetchAllClasspects()["class"]
elif components["aspect"] == []:
pull = components["class"]
validmath["aspect"] = fetchAllClasspects()["aspect"]
else:
pull = components["class"] + components["aspect"]
ex1 = random.choice(pull).name
ex2 = ex1
while ex2 == ex1:
ex2 = random.choice(pull).name
if not (class_data.isCanon() or aspect_data.isCanon()):
tooltip.extend("Dual Classpect. Since the Dual Classpect is made up of regular Classpects, you can subtract any of its components <span class='text-muted'>(like " +
ex1 + " or " + ex2 + ")</span> from your search term!</small>")
elif class_data.isCanon() or aspect_data.isCanon():
if class_data.isCanon():
sel = 0
elif aspect_data.isCanon():
sel = 1
ex3 = getRandomClasspect()[sel]
ex4 = ex3
while ex4 == ex3:
ex4 = getRandomClasspect()[sel]
tooltip.extend("mix of the two. Since the Dual Classpect is made up of regular Classpects, you can subtract any of its components <span class='text-muted'>(like " + ex1 + " or " + ex2 +
")</span> from your search term, but you can also add any regular classpect <span class='text-muted'>(like " + ex3 + " or " + ex4 + ")</span> to the non-Dual part of your search!</small>")
display.extend(tooltip)
elif (((not invalidCspect(class_data) and aspect_data.name == "") or (not invalidCspect(aspect_data) and class_data.name == "") and aspect_data.name != class_data.name)):
tooltip = ["Add or subtract classpects to make Dual Classes!"]
validmath = {}
display.extend(tooltip)
else:
validmath = {}
# math result generation
if formState["math"]:
mathdisplay = []
if mathValidator(form):
# math tooltip generation
if not formState["dual"] and (class_data.isCanon() or aspect_data.isCanon()):
summed_data = results["class"] + \
results["mathclass"], results["aspect"] + \
results["mathaspect"]
if (summed_data[0].name + summed_data[1].name) != "":
printable_sum = wrapLi(
"".join(makePrintable(formState, summed_data)), "Sum")
addit = "<ul style='margin-bottom: 0px'><li style='color: transparent'>" + \
dualFlavorText(
formState, summed_data) + "</li></ul>"
mathdisplay.extend([printable_sum, addit])
elif formState["dual"]:
if not (class_data.isCanon() or aspect_data.isCanon()):
summed_data = results["class"] - \
results["mathclass"], results["aspect"] - \
results["mathaspect"]
if (summed_data[0].name + summed_data[1].name) != "":
printable_sum = wrapLi(
"".join(makePrintable(formState, summed_data)), "Difference")
mathdisplay.extend([printable_sum])
elif class_data.isCanon() or aspect_data.isCanon():
summed_data = ()
if class_data.isCanon():
summed_data = results["class"] + \
results["mathclass"], results["aspect"] - \
results["mathaspect"]
elif aspect_data.isCanon():
summed_data = results["class"] - \
results["mathclass"], results["aspect"] + \
results["mathaspect"]
if (summed_data[0].name + summed_data[1].name) != "":
printable_sum = wrapLi(
"".join(makePrintable(formState, summed_data)), "Output")
addit = "<ul style='margin-bottom: 0px'><li style='color: transparent'>" + \
dualFlavorText(
formState, summed_data) + "</li></ul>"
mathdisplay.extend([printable_sum, addit])
elif (((invalidCspect(class_data) and aspect_data.name == "") or (invalidCspect(aspect_data) and class_data.name == "") and aspect_data.name != class_data.name)):
for i in classpect_data:
if invalidCspect(i):
if (form[i.typeInverse()] == "") and not invalidCspect(ClasspectComponent(form["math" + i.typeInverse()], i.typeInverse())):
summed_data = sorted((i, ClasspectComponent(
form["math" + i.typeInverse()], i.typeInverse())), key=sortByType, reverse=True)
printable_sum = wrapLi(
"".join(makePrintable(formState, summed_data)), "Output")
addit = "<ul style='margin-bottom: 0px'><li style='color: transparent'>" + \
dualFlavorText(
formState, summed_data) + "</li></ul>"
mathdisplay.extend([printable_sum, addit])
else:
mathdisplay = []
mathdisplay.extend([housetrapped])
display = compileArr(display)
mathdisplay = compileArr(mathdisplay)
niceresults = dict(results)
for k, v in niceresults.items():
niceresults[k] = v.name
# results = {"class": "", "aspect": ""}
# niceresults = {}
# display = (json.loads(response.text))
# mathdisplay = {}
# validmath = {}
return render_template(
"bettersearch.html",
results=results, niceresults=niceresults, classpects=fetchAllClasspects(),
sitetitle="Lookup", display=display, mathdisplay=mathdisplay, validator=mathValidator(form), validmath=validmath
)