repl.it
@zonemultiwhs/

smon_all

Python

No description

fork
loading
Files
  • main.py
main.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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
import json
import requests
import time
from collections import OrderedDict

#=========================
MAX_NUM_CARD_PRINTING = 20
MAX_BATTLE_NUM = 3

INT_CARDS = ['Furious Chicken', 'Beetle Queen', 'Lord Arianthus']

INT_ACCOUNTS = ['tradingideas']
#==========================


CARDS = []
MARKET_REAL_DATA = []
XP_Based_On_Rarity = {1:15, 2:75, 3:175, 4:750}
XP_Based_On_Rarity_GOLD = {1:200, 2:400, 3:800, 4:2000}
MAX_CAP = {1:400000, 2:100000, 3:40000, 4:10000}
SMON_SETTINGS = []
MIN_PRICES = {}
EDITIONS = {0 : 'Alpha', 1 : 'Beta', 2 : 'Promo', 3 : 'Reward'}

CARD_TYPE_NAME = {
    1:"Common",
    2:"Rare",
    3:"Epic",
    4:"Legendary"
}
CARD_ID_NAME = {
'1':['Goblin Shaman', 1 , 3 ,'Red','any'],
'2':['Giant Roc', 1 , 5 ,'Red','any'],
'3':['Kobold Miner', 1 , 2 ,'Red','any'],
'4':['Fire Beetle', 1 , 3 ,'Red','ranged'],
'5':['Malric Inferno', 2 , 3 ,'Red','any'],
'6':['Serpentine Soldier', 2 , 5 ,'Red','any'],
'7':['Pit Ogre', 2 , 6 ,'Red','any'],
'8':['Cerberus', 2 , 4 ,'Red','any'],
'9':['Fire Demon', 3 , 4 ,'Red','ranged'],
'10':['Serpent of the Flame', 3 , 6 ,'Red','any'],
'11':['Elemental Phoenix', 4 , 7 ,'Red','magic'],
'12':['Pirate Captain', 1 , 3 ,'Blue','ranged'],
'13':['Spineback Turtle', 1 , 4 ,'Blue','any'],
'14':['Crustacean King', 1 , 3 ,'Blue','any'],
'15':['Sabre Shark', 1 , 3 ,'Blue','any'],
'16':['Alric Stormbringer', 2 , 3 ,'Blue','any'],
'17':['Medusa', 2 , 4 ,'Blue','magic'],
'18':['Water Elemental', 2 , 5 ,'Blue','ranged'],
'19':['Frozen Soldier', 2 , 6 ,'Blue','any'],
'20':['Mischievous Mermaid', 3 , 5 ,'Blue','magic'],
'21':['Naga Warrior', 3 , 5 ,'Blue','any'],
'22':['Frost Giant', 4 , 7 ,'Blue','any'],
'23':['Flesh Golem', 1 , 6 ,'Green','any'],
'24':['Goblin Sorcerer', 1 , 3 ,'Green','magic'],
'25':['Rexxie', 1 , 7 ,'Green','any'],
'26':['Minotaur Warrior', 1 , 4 ,'Green','any'],
'27':['Lyanna Natura', 2 , 3 ,'Green','any'],
'28':['Earth Elemental', 2 , 3 ,'Green','ranged'],
'29':['Stone Golem', 2 , 5 ,'Green','any'],
'30':['Stonesplitter Orc', 2 , 6 ,'Green','any'],
'31':['Magi of the Forest', 3 , 4 ,'Green','magic'],
'32':['Swamp Thing', 3 , 2 ,'Green','ranged'],
'33':['Spirit of the Forest', 4 , 7 ,'Green','ranged'],
'34':['Divine Healer', 1 , 3 ,'White','any'],
'35':['Feral Spirit', 1 , 3 ,'White','any'],
'36':['Silvershield Knight', 1 , 6 ,'White','any'],
'37':['Silvershield Warrior', 1 , 4 ,'White','any'],
'38':['Tyrus Paladium', 2 , 3 ,'White','any'],
'39':['Peacebringer', 2 , 4 ,'White','ranged'],
'40':['Silvershield Paladin', 2 , 5 ,'White','any'],
'41':['Clay Golem', 2 , 6 ,'White','any'],
'42':['Defender of Truth', 3 , 4 ,'White','magic'],
'43':['Air Elemental', 3 , 5 ,'White','ranged'],
'44':['Angel of Light', 4 , 5 ,'White','any'],
'45':['Animated Corpse', 1 , 4 ,'Black','any'],
'46':['Haunted Spider', 1 , 3 ,'Black','ranged'],
'47':['Skeleton Assassin', 1 , 3 ,'Black','any'],
'48':['Spineback Wolf', 1 , 5 ,'Black','any'],
'49':['Zintar Mortalis', 2 , 3 ,'Black','any'],
'50':['Haunted Spirit', 2 , 5 ,'Black','any'],
'51':['Twisted Jester', 2 , 4 ,'Black','ranged'],
'52':['Undead Priest', 2 , 2 ,'Black','any'],
'53':['Dark Enchantress', 3 , 6 ,'Black','magic'],
'54':['Screaming Banshee', 3 , 3 ,'Black','magic'],
'55':['Lord of Darkness', 4 , 7 ,'Black','any'],
'56':['Selenia Sky', 4 , 3 ,'Gold','any'],
'57':['Lightning Dragon', 4 , 7 ,'Gold','ranged'],
'58':['Chromatic Dragon', 4 , 7 ,'Gold','any'],
'59':['Gold Dragon', 4 , 7 ,'Gold','magic'],
'60':['Peaceful Giant', 1 , 5 ,'Gray','any'],
'61':['Grumpy Dwarf', 1 , 4 ,'Gray','any'],
'62':['Elven Cutthroat', 1 , 3 ,'Gray','any'],
'63':['Centaur', 1 , 4 ,'Gray','ranged'],
'64':['Cocatrice', 2 , 2 ,'Gray','any'],
'65':['Cyclops', 2 , 6 ,'Gray','ranged'],
'66':['Enchanted Pixie', 2 , 3 ,'Gray','magic'],
'67':['Raging Impaler', 3 , 6 ,'Gray','any'],
'68':['Magi Sphinx', 3 , 5 ,'Gray','magic'],
'69':['Hydra', 4 , 7 ,'Gray','any'],
'70':['Talia Firestorm', 3 , 2 ,'Red','any'],
'71':['Xia Seachan', 3 , 2 ,'Blue','any'],
'72':['Xander Foxwood', 3 , 2 ,'Green','any'],
'73':['Kiara Lightbringer', 3 , 2 ,'White','any'],
'74':['Jarlax the Undead', 3 , 2 ,'Black','any'],
'75':['Dragon Whelp', 1 , 3 ,'Gold','magic'],
'76':['Royal Dragon Archer', 3 , 6 ,'Gold','ranged'],
'77':['Shin-Lo', 4 , 1 ,'Gold','magic'],
'78':['Neb Seni', 2 , 4 ,'Gold','any'],
'79':['Highland Archer', 1 , 3 ,'Gray','ranged'],
'80':['Rusty Android', 1 , 6 ,'Gray','any'],
'81':['Hobgoblin', 2 , 5 ,'Gray','any'],
'82':['Lord Arianthus', 4 , 5 ,'Gray','any'],
'83':['Sea Genie', 1 , 6 ,'Blue','magic'],
'84':['Divine Sorceress', 3 , 3 ,'White','magic'],
'85':['Mushroom Seer', 2 , 5 ,'Green','magic'],
'86':['Vampire', 1 , 5 ,'Black','ranged'],
'87':['Flame Imp', 2 , 3 ,'Red','magic'],
'88':['Daria Dragonscale', 3 , 4 ,'Gold','any'],
'89':['Sacred Unicorn', 4 , 7 ,'White','any'],
'90':['Wood Nymph', 1 , 4 ,'Green','magic'],
'91':['Creeping Ooze', 1 , 1 ,'Gray','any'],
'92':['Phantom Soldier', 3 , 8 ,'Black','magic'],
'93':['Pirate Archer', 2 , 2 ,'Blue','ranged'],
'94':['Naga Fire Wizard', 2 , 8 ,'Red','magic'],
'95':['Brownie', 3 , 1 ,'Green','any'],
'96':['Silvershield Archers', 1 , 2 ,'White','ranged'],
'97':['Goblin Mech', 1 , 10 ,'Gray','any'],
'98':['Ruler of the Seas', 4 , 6 ,'Blue','magic'],
'99':['Skeletal Warrior', 2 , 2 ,'Black','any'],
'100':['Imp Bowman', 3 , 2 ,'Red','ranged'],
'101':['Crystal Werewolf', 2 , 3 ,'White','any'],
'102':['Javelin Thrower', 2 , 5 ,'Green','ranged'],
'103':['Sea Monster', 1 , 8 ,'Blue','any'],
'104':['Prismatic Energy', 2 , 8 ,'Gray','magic'],
'105':['Undead Minotaur', 1 , 6 ,'Black','any'],
'106':['Exploding Dwarf', 1 , 5 ,'Red','any'],
'107':['Manticore', 3 , 4 ,'Gold','any'],
'108':['Black Dragon', 4 , 6 ,'Gold','magic'],
'109':['Crypt Mancer', 4 , 5 ,'Black','any'],
'110':['Plado Emberstorm', 4 , 5 ,'Red','any'],
'111':['Valnamor', 4 , 5 ,'Blue','any'],
'112':['Prince Rennyn', 4 , 5 ,'Green','any'],
'113':['The Peakrider', 4 , 5 ,'White','any'],
'114':['Delwyn Dragonscale', 1 , 5 ,'Gold','any'],
'115':['Dragonling Bowman', 2 , 4 ,'Gold','ranged'],
'116':['Fiendish Harpy', 3 , 2 ,'Gold','any'],
'117':['Red Dragon', 4 , 8 ,'Gold','magic'],
'118':['Armorsmith', 1 , 2 ,'White','any'],
'119':['Silvershield Bard', 2 , 1 ,'White','any'],
'120':['Goblin Chef', 1 , 3 ,'Green','ranged'],
'121':['Minotaur Warlord', 4 , 8 ,'Green','any'],
'122':['Electric Eels', 2 , 4 ,'Blue','any'],
'123':['Mermaid Healer', 3 , 3 ,'Blue','any'],
'124':['Undead Archer', 2 , 2 ,'Black','ranged'],
'125':['Corrupted Pegasus', 4 , 6 ,'Black','any'],
'126':['Molten Ogre', 1 , 9 ,'Red','any'],
'127':['Lord of Fire', 4 , 3 ,'Red','ranged'],
'128':['Enchanted Defender', 1 , 4 ,'Gray','any'],
'129':['Dwarven Wizard', 3 , 3 ,'Gray','magic'],
'130':['Archmage Arius', 4 , 5 ,'Gold','any'],
'131':['Furious Chicken', 2 , 0 ,'Gray','any'],
'132':['Fallen Specter', 4 , 2 ,'Black','magic'],
'133':['Beetle Queen', 2 , 4 ,'Red','magic'],
'134':['Naga Windmaster', 2 , 4 ,'Blue','ranged'],
'135':['Maggots', 1 , 3 ,'Black','any'],
'136':['Cursed Slimeball', 1 , 1 ,'Black','any'],
'137':['Giant Scorpion', 1 , 4 ,'Black','any'],
'138':['Undead Badger', 1 , 2 ,'Black','any'],
'139':['Dark Astronomer', 2 , 4 ,'Black','ranged'],
'140':['Bone Golem', 2 , 7 ,'Black','any'],
'141':['Death Elemental', 2 , 3 ,'Black','magic'],
'142':['Soulstorm', 3 , 5 ,'Black','ranged'],
'143':['Darkest Mage', 3 , 2 ,'Black','magic'],
'144':[" Dark Ha'on ", 4 , 10 ,'Black','any'],
'145':["Contessa L'ament", 2 , 3 ,'Black','any'],
'146':['Cave Slug', 1 , 5 ,'White','any'],
'147':['Crystal Jaguar', 1 , 4 ,'White','any'],
'148':['Lone Boatman', 1 , 5 ,'White','ranged'],
'149':['Herbalist', 1 , 2 ,'White','ranged'],
'150':['Truthspeaker', 2 , 3 ,'White','any'],
'151':['Luminous Eagle', 2 , 6 ,'White','any'],
'152':['Shieldbearer', 2 , 8 ,'White','any'],
'153':['Light Elemental', 3 , 4 ,'White','magic'],
'154':['Thunderbird', 3 , 3 ,'White','ranged'],
'155':['High Priest Darius', 4 , 10 ,'White','magic'],
'156':['Mother Khala', 2 , 3 ,'White','any'],
'157':['Kobold Bruiser', 1 , 3 ,'Red','any'],
'158':['Serpentine Spy', 1 , 3 ,'Red','any'],
'159':['Magma Troll', 1 , 4 ,'Red','any'],
'160':['Goblin Fireballer', 1 , 2 ,'Red','ranged'],
'161':['Fire Elemental', 2 , 5 ,'Red','ranged'],
'162':['Living Lava', 2 , 7 ,'Red','any'],
'163':['Spark Pixies', 2 , 4 ,'Red','ranged'],
'164':['Ferexia General', 3 , 5 ,'Red','ranged'],
'165':['Pyromaniac', 3 , 6 ,'Red','ranged'],
'166':['Magnor', 4 , 10 ,'Red','any'],
'167':['Pyre', 2 , 3 ,'Red','any'],
'168':['Feasting Seaweed', 1 , 4 ,'Blue','any'],
'169':['Albatross', 1 , 1 ,'Blue','any'],
'170':['Tortisian Fighter', 1 , 4 ,'Blue','any'],
'171':['Sniping Narwhal', 1 , 5 ,'Blue','ranged'],
'172':['Ice Pixie', 2 , 2 ,'Blue','magic'],
'173':['Giant Squid', 2 , 5 ,'Blue','ranged'],
'174':['Serpent of Eld', 2 , 7 ,'Blue','any'],
'175':['Coral Wraith', 3 , 4 ,'Blue','magic'],
'176':['Azmare Harpoonist', 3 , 6 ,'Blue','ranged'],
'177':['Phantom of the Abyss', 4 , 10 ,'Blue','magic'],
'178':['Bortus', 2 , 3 ,'Blue','any'],
'179':['Goblin Thief', 1 , 4 ,'Green','any'],
'180':['Failed Summoner', 1 , 2 ,'Green','any'],
'181':['Biceratops', 1 , 4 ,'Green','any'],
'182':['Orc Sergeant', 1 , 5 ,'Green','any'],
'183':['Khmer Princess', 2 , 2 ,'Green','magic'],
'184':['Unicorn Mustang', 2 , 8 ,'Green','any'],
'185':['Child of the Forest', 2 , 3 ,'Green','ranged'],
'186':['Mitica Headhunter', 3 , 8 ,'Green','ranged'],
'187':['Sporcerer', 3 , 6 ,'Green','magic'],
'188':['Kron the Undying', 4 , 10 ,'Green','magic'],
'189':['Wizard of Eastwood', 2 , 3 ,'Green','any'],
'190':['Elven Defender', 1 , 8 ,'Gray','any'],
'191':['Horny Toad', 1 , 3 ,'Gray','any'],
'192':['Mantoid', 1 , 6 ,'Gray','ranged'],
'193':['Parasitic Growth', 1 , 4 ,'Gray','any'],
'194':['Elven Mystic', 2 , 4 ,'Gray','magic'],
'195':['Goblin Chariot', 2 , 5 ,'Gray','ranged'],
'196':['Tower Griffin', 2 , 4 ,'Gray','ranged'],
'197':['War Chaang', 3 , 7 ,'Gray','ranged'],
'198':['Tortisian Chief', 3 , 5 ,'Gray','magic'],
'199':['Cornealus', 4 , 10 ,'Gray','ranged'],
'200':['Camila Sungazer', 4 , 3 ,'Gold','any'],
'201':['The Vigilator', 4 , 9 ,'Gold','ranged'],
'202':['Scale Doctor', 4 , 5 ,'Gold','ranged'],
'203':['Dragon Jumper', 4 , 7 ,'Gold','any'],
'204':['Gloridax Magus', 4 , 6 ,'Gold','magic'],
'205':['Prince Julian', 4 , 2 ,'Gold','any'],
'206':['Boogeyman', 2 , 6 ,'Black','magic'],
'207':['Spirit Miner', 4 , 6 ,'Gray','magic'],
'208':['Battle Orca', 2 , 3 ,'Blue','any'],
'209':['Chain Golem', 4 , 8 ,'Gray','any'],
'210':['Diamond Dragon', 4 , 10 ,'Gold','magic'],
'211':['Gloridax Guardian', 4 , 6 ,'Gold','magic'],
'212':['Fire Spitter', 3 , 4 ,'Gold','ranged'],
'213':['The Kraken', 4 , 12 ,'Blue','any'],
'214':['Ettin Spearman', 1 , 8 ,'Red','ranged'],
'215':['Octopider', 2 , 8 ,'Black','ranged'],
'216':['Silvershield Assassin', 2 , 7 ,'White','any'],
'217':['Baby Unicorn', 1 , 3 ,'White','any'],
'218':['Gelatinous Cube', 1 , 6 ,'Gray','any'],
'219':['Gremlin Blaster', 2 , 3 ,'Gray','any'],
'220':['Screeching Vulture', 1 , 3 ,'Green','any'],
'221':['Spirit Shaman', 3 , 4 ,'Green','magic'],
'222':['Zalran Efreet', 4 , 5 ,'Red','magic'],
'223':['Serpentine Mystic', 2 , 3 ,'Gold','magic'],
'224':['Drake of Arnak', 2, 4, 'Gold', 'any'],
#[name, rarity]
}


def get_card_detail_info(from_file=0) :
    # get the carddetails from steemmonsters.com
    global CARDS
    # get the carddetails from steemmonsters.com
    if CARDS == [] :
        if (from_file) :
            CARDS = load_json_from_file("sm_get_details.txt")
        else :
            r = requests.get("https://steemmonsters.com/cards/get_details")
            CARDS = r.json()

def card_issued_status(from_file=0, only_full=0) :
    get_card_detail_info(from_file) 
    card_lists = []
    card_lists_so = []  # sold out
    print("===========================================")
    print("id       name          issued       remain")
    print("===========================================")
    for card in CARDS :
        if (card['editions'] == '3') :
            xp = XP_Based_On_Rarity[card['rarity']]
            xp_gold = XP_Based_On_Rarity_GOLD[card['rarity']]
            # XP가 0으로 시작하므로, 현재 남은 카드 수량*xp 한 만큼 XP 더한 후 XP로 나눈다.
            # gold 카드의 경우에는 한 장부터 XP가 있으므로 그냥 XP로 나누면 된다.
            num_printed_cards = (int(card['distribution'][0]['total_xp']) + int(card['distribution'][0]['num_cards'])*xp) / xp  + \
                                (int(card['distribution'][0]['total_burned_xp']) + int(card['distribution'][0]['num_burned'])*xp) / xp
            num_printed_cards_gold = int(card['distribution'][1]['total_xp']) / xp_gold  + \
                                int(card['distribution'][1]['total_burned_xp']) / xp_gold
            percent = (num_printed_cards+num_printed_cards_gold)/ MAX_CAP[card['rarity']] * 10000
            info = [card['id'], card['name'], card['rarity'], card['editions'], card['distribution'][0], int(percent)]
            if (percent >= 10000.0) :
                card_lists_so.append(info)
            else :
                card_lists.append(info)

    slist = sorted(card_lists, key = lambda x: (x[5], x[0]), reverse=True)  # 0번째가 key
    slist_so = sorted(card_lists_so, key = lambda x: (x[5], x[0]), reverse=True)  # 0번째가 key
    cnt = 0

    if (only_full) :
        for card_info in slist_so :  # 100% 채굴된 카드
            remain = MAX_CAP[card_info[2]] * (1 - card_info[5]/10000)
            print(format(card_info[0], "3d"), format(card_info[1], "20s"), format(card_info[5]/100, "6.2f"), '%', format(int(remain), "7,d"))
        return slist, slist_so
    
    for card_info in slist :
        if (cnt > MAX_NUM_CARD_PRINTING ) :
            break
        cnt += 1
        remain = MAX_CAP[card_info[2]] * (1 - card_info[5]/10000)
        print(format(card_info[0], "3d"), format(card_info[1], "20s"), format(card_info[5]/100, "6.2f"), '%', format(int(remain), "7,d"))

# def get_card_details()에서 rarity를 찾아야한다.
# rarity : 1 - 4 (common, rare, epic, legandary)
UNKNOWN_CARDS = []
def get_single_cards(card_detail_id, edition, gold, xp):
    global CARD_ID_NAME
    global UNKNOWN_CARDS
    cards = 0
    if str(card_detail_id) not in CARD_ID_NAME :
      if card_detail_id in UNKNOWN_CARDS :
        return 1
      print("unknown card ", card_detail_id)
      UNKNOWN_CARDS.append(card_detail_id)
      return 1
    rarity = CARD_ID_NAME[str(card_detail_id)][1]
    # Alpha Edition Cards per XP
    if edition == 0 and gold == 0 and rarity == 4:
        cards = (xp / 1000) +1
    if edition == 0 and gold == 0 and rarity == 3:
        cards = (xp / 250) +1
    if edition == 0 and gold == 0 and rarity == 2:
        cards = (xp / 100) +1
    if edition == 0 and gold == 0 and rarity == 1:
        cards = (xp / 20) +1
    if edition == 0 and gold == 1 and rarity == 4:
        cards = xp / 2500
    if edition == 0 and gold == 1 and rarity == 3:
        cards = xp / 1000
    if edition == 0 and gold == 1 and rarity == 2:
        cards = xp / 500
    if edition == 0 and gold == 1 and rarity == 1:
        cards = xp / 250
    # Beta Edition Cards per XP
    if edition == 1 and gold == 0 and rarity == 4:
        cards = (xp / 750) +1
    if edition == 1 and gold == 0 and rarity == 3:
        cards = (xp / 175) +1
    if edition == 1 and gold == 0 and rarity == 2:
        cards = (xp / 75) +1
    if edition == 1 and gold == 0 and rarity == 1:
        cards = (xp / 15) +1
    if edition == 1 and gold == 1 and rarity == 4:
        cards = xp / 2000
    if edition == 1 and gold == 1 and rarity == 3:
        cards = xp / 800
    if edition == 1 and gold == 1 and rarity == 2:
        cards = xp / 400
    if edition == 1 and gold == 1 and rarity == 1:
        cards = xp / 200
    # Promo Edition Cards per XP
    if edition == 2 and gold == 0 and rarity == 4:
        cards = (xp / 1000) +1
    if edition == 2 and gold == 0 and rarity == 3:
        cards = (xp / 250) +1
    if edition == 2 and gold == 0 and rarity == 2:
        cards = (xp / 100) +1
    if edition == 2 and gold == 0 and rarity == 1:
        cards = (xp / 20) +1
    if edition == 2 and gold == 1 and rarity == 4:
        cards = xp / 2000
    if edition == 2 and gold == 1 and rarity == 3:
        cards = xp / 800
    if edition == 2 and gold == 1 and rarity == 2:
        cards = xp / 400
    if edition == 2 and gold == 1 and rarity == 1:
        cards = xp / 200
    # reward Edition Cards per XP
    if edition == 3 and gold == 0 and rarity == 4:
        cards = (xp / 750) +1
    if edition == 3 and gold == 0 and rarity == 3:
        cards = (xp / 175) +1
    if edition == 3 and gold == 0 and rarity == 2:
        cards = (xp / 75) +1
    if edition == 3 and gold == 0 and rarity == 1:
        cards = (xp / 15) +1
    if edition == 3 and gold == 1 and rarity == 4:
        cards = xp / 2000
    if edition == 3 and gold == 1 and rarity == 3:
        cards = xp / 800
    if edition == 3 and gold == 1 and rarity == 2:
        cards = xp / 400
    if edition == 3 and gold == 1 and rarity == 1:
        cards = xp / 200

    return cards


__url__ = 'https://steemmonsters.com/'
__url2__ = 'https://api.steemmonsters.io'

def get_data_from_sm(cmd, url2=0) :
    url = __url__ + cmd
    if (url2) :
       url = __url2__ + cmd

    response = ""
    cnt2 = 0
    while str(response) != '<Response [200]>' and cnt2 < 15:
        response = requests.get(url)
        if str(response) != '<Response [200]>':
            time.sleep(1)
        cnt2 += 1

    rets = response.json()
    return rets

def get_smon_settings() :
    global SMON_SETTINGS
    SMON_SETTINGS = get_data_from_sm('settings')
    
    steem_price = SMON_SETTINGS['steem_price']
    dec_price = SMON_SETTINGS['dec_price']

    MIN_PRICES['general_beta_rewards'] = {
        'common' : dec_price * SMON_SETTINGS['dec']['burn_rate'][0]* 1.05, 
        'rare': dec_price * SMON_SETTINGS['dec']['burn_rate'][1]* 1.05,
        'epic' : dec_price * SMON_SETTINGS['dec']['burn_rate'][2]* 1.05,
        'leg' : dec_price * SMON_SETTINGS['dec']['burn_rate'][3]* 1.05
    }
    gd_factor = SMON_SETTINGS['dec']['gold_burn_bonus']
    MIN_PRICES['general_beta_rewards_gold'] = {
        'common' : dec_price * SMON_SETTINGS['dec']['burn_rate'][0] * gd_factor* 1.05, 
        'rare': dec_price * SMON_SETTINGS['dec']['burn_rate'][1]* gd_factor* 1.05,
        'epic' : dec_price * SMON_SETTINGS['dec']['burn_rate'][2]* gd_factor* 1.05,
        'leg' : dec_price * SMON_SETTINGS['dec']['burn_rate'][3]* gd_factor* 1.05
    }
    

def save_to_file_json(file_name, data) :
    with open(file_name,'w',encoding="utf-8") as make_file: 
       json.dump(data, make_file, ensure_ascii=False, indent="\t") 

def load_json_from_file(file_name) :
    try :
        with open(file_name,'r',encoding="utf-8") as make_file: 
           data=json.load(make_file) 
    except :
        data = {}
    return data
def reload_market_data() :
    global MARKET_REAL_DATA
    MARKET_REAL_DATA = get_data_from_sm("market/for_sale")

def get_cards_price(print_all=1, from_file=0):
    global MARKET_REAL_DATA
    count = 0
    if from_file :
        MARKET_REAL_DATA = load_json_from_file("sm_market.txt")
    else:
        MARKET_REAL_DATA = get_data_from_sm("market/for_sale")
#            save_to_file_json("sm_market.txt", rets)

    market_data = []
    market_gd_data = []
    for r in MARKET_REAL_DATA:
        market_id = r["market_id"]
        card_detail_id = r["card_detail_id"]
        edition = r["edition"]
        gold = r["gold"]
        uid = r["uid"]
        buy_price = r["buy_price"]
        seller = r["seller"]
        xp = r["xp"]

        count += 1
        #print(card_detail_id, edition, gold, uid, buy_price, seller, xp)
        cards = get_single_cards(card_detail_id, edition, gold, xp)
        if (cards == 0 ) :
            cards = 1
        bcx_price = float(buy_price) / cards
        if str(card_detail_id) not in CARD_ID_NAME :
          continue
        else :
          card_name = CARD_ID_NAME[str(card_detail_id)]
#        if card_name[0] == 'Flame Imp' :
#           print('h')

        card_info = [card_detail_id, CARD_ID_NAME[str(card_detail_id)], buy_price, xp, bcx_price]
        if (gold) :
            market_gd_data.append(card_info)
        else :
            market_data.append(card_info)

    slist = sorted(market_data, key = lambda x: (x[4]))  # 0번째가 key
    sglist = sorted(market_gd_data, key = lambda x: (x[4]))  # 0번째가 key
    return slist, sglist

def print_market_card_list(print_all, slist, sglist) :
    print("== general ==")
    display_cards(print_all, slist, MIN_PRICES['general_beta_rewards'])
    print("== gold ==")
    display_cards(print_all, sglist, MIN_PRICES['general_beta_rewards_gold'])

MARGIN = 0.97
def display_cards(print_all, slist, min_price) :
    displayed = []
    cnt = 1
    # cd = [id, [name, rarirty(카드종류)], 가격(str), 0, 가격(float)]
    # common or intesting card
    for cd in slist :
        if ( print_all and cnt > MAX_NUM_CARD_PRINTING ):
            break
        if ( cd[0] not in displayed) :
            if print_all :
                displayed.append(cd[0])
                buy = ''
                if (cd[4] < min_price['common'] * MARGIN) :
                    buy = 'buy f'
                    if (cd[4] < min_price['common'] / 1.05 * 1.01 * MARGIN) :
                        buy_s = 'buy s'
                # id, name, price, below여부
                print (format(cd[0], "3d"), format(cd[1][0], "20s"), format(cd[4], "6.3f"), buy)
                cnt += 1
            elif cd[1][0] in INT_CARDS :
                displayed.append(cd[0])
                print (format(cd[0], "3d"), format(cd[1][0], "20s"), format(cd[4], "6.3f"))
                cnt += 1
    if (print_all == 0) :
        return
    # rare
    print('--- rare ---')
    displayed = []
    cnt= 1
    for cd in slist :
        if ( cnt > 5 ):
            break
        if ( cd[0] not in displayed) :
            if print_all :
                if cd[1][1] == 2 : #rare
                    displayed.append(cd[0])
                    buy = ''
                    buy_s = ''
                    if (cd[4] < min_price['rare']* MARGIN) :
                        buy = 'buy f'
                    if (cd[4] < min_price['rare'] / 1.05 * 1.01 * MARGIN) :
                        buy_s = 'buy s'
                    print (format(cd[0], "3d"), format(cd[1][0], "20s"), format(cd[4], "6.3f"), buy, buy_s)
                    cnt += 1
    # epic
    print('--- epic ---')
    displayed = []
    cnt= 1
    for cd in slist :
        if ( cnt > 3 ):
            break
        if ( cd[0] not in displayed) :
            if print_all :
                if cd[1][1] == 3 : #epic
                    displayed.append(cd[0])
                    buy = ''
                    if (cd[4] < min_price['epic']* MARGIN) :
                        buy = 'buy f'
                    if (cd[4] < min_price['epic'] / 1.05 * 1.01 * MARGIN) :
                        buy_s = 'buy s'
                    print (format(cd[0], "3d"), format(cd[1][0], "20s"), format(cd[4], "6.3f"), buy, buy_s)
                    cnt += 1
    # leg
    print('--- leg ---')
    displayed = []
    cnt= 1
    for cd in slist :
        if ( cnt > 2 ):
            break
        if ( cd[0] not in displayed) :
            if print_all :
                if cd[1][1] == 4 : #leg
                    displayed.append(cd[0])
                    buy = ''
                    if (cd[4] < min_price['leg']* MARGIN) :
                        buy = 'buy f'
                    if (cd[4] < min_price['leg'] / 1.05 * 1.01 * MARGIN) :
                        buy_s = 'buy s'
                    print (format(cd[0], "3d"), format(cd[1][0], "20s"), format(cd[4], "6.3f"), buy, buy_s)
                    cnt += 1

def print_this_team_info(type, account, res) :
    details = json.loads(res["details"])
    winner = res['winner']
    player1 = res['player_1']
    player2 = res['player_2']
    team = details['team2']
    if (player1 == winner) : # team1
        team = details['team1']

    print(type, player1, player2, 'winner is ', winner)
    if (team == None) :
        return 
#        self.my_team_info
# { 'mana': 'ruleset':'inactive';'color';'summoner':{uid, id}, 'monsters':[{}{}{}]

    print("\nConditions:", res['mana_cap'], res['ruleset'], res['inactive'])

    summoner_id = str(team['summoner']['card_detail_id'])
    print("--- winner team info ---")

    print(team['color'], '\nsummoner:', CARD_ID_NAME[summoner_id][0])

    monsters = team['monsters']
    found = []
    for mon in monsters :
        found.append(CARD_ID_NAME[str(mon['card_detail_id'])][0])

    print('monsters:', found)
    print('---')


def request_get(url, headers=0, echo=0) :
    response = ""
    cnt2 = 0
    while str(response) != '<Response [200]>' and cnt2 < 10:
        if echo : 
          print("requests request_get", url)
        response = requests.get(url, headers=headers)
        if str(response) != '<Response [200]>':
            print('sleep ', url)
            time.sleep(15)
        cnt2 += 1
    return response.json()


def find_card(name) :
    for acc in INT_ACCOUNTS :
        found = []
        url = "https://steemmonsters.com/cards/collection/"+acc
        holding_cards = request_get(url)
        for card in holding_cards['cards'] :
            id = card['card_detail_id']
            if ( CARD_ID_NAME[str(id)][0].upper() == name.upper()) :
                if (acc not in found) :
                    print(format(acc, "16s"), name)
                    found.append(acc)
     

def game_history(account) :
        url = "https://steemmonsters.com/battle/history?player=%s" % account
        battles = request_get(url)
        cnt = 1
        updated = 0
        for battle in battles['battles'] :
            if cnt > MAX_BATTLE_NUM :
                break
            cnt += 1
            res_url = "https://steemmonsters.com/battle/result?id=%s" %  battle['battle_queue_id_1']
            res = request_get(res_url)
            print_this_team_info(battle['match_type'], account, res)


def get_date(tm) :
    tt = tm.split("T")
    return tt[0]

def find_prize(tour, user) :
    path = 'tournaments/find?id='+tour['id']
    tourna_info = get_data_from_sm(path)

    for winner in tourna_info['players'] :
        if winner['player'] == user :
            if winner['prize'] == None:
                return 0

            print(get_date(tour['start_date']), format(winner['prize'], "16s"), tour['name'])
            amount = winner['prize'].split(' ')
            return float(amount[0])
    return 0

    
def tournament_prizes(user) :
    total = 0
    completed_tours = get_data_from_sm("tournaments/completed")
    cnt = 0
    for tour in completed_tours :
        amount = find_prize(tour, user)
        if ( amount > 0 ) :
            total += amount
            cnt += 1
        if (cnt > 5) :
            break
    print("total prize :", total)

def get_cur_low_card_price(id, plist) :
    cnt = 0
    for p in plist :
        if p[0] == id :
            return p[4]
    return 0

# updated 2019/9/27 open_all에 대한 대응 추가
def value_of_open_packs(player, num_packs, param, plist, pglist) :
#    https://api.steemmonsters.io/players/history?username=tradingideas&from_block=-1&limit=250&types=sm_pack_purchase,sm_open_pack,open_pack,sm_open_all,open_all
    print(' id : ', player)
    packs = get_data_from_sm("/players/history?username="+player+"&from_block=-1&limit=250&types="+param, 1)
    open_cards = {}
    cnt = 1
    if len(packs) == 0 : 
      print('no opened pack')
      return
    for pack in packs :
        if ( cnt > int(num_packs) ) :
            break
        if (pack['result'] == None) :
            continue
        if pack['error'] != None :
          print (pack['error'])
          continue
        cards = json.loads(pack['result'])
        if param != "sm_claim_reward" :
            cards = cards['cards']    # reward와 open pack의 경우에 key가 틀리다.        
            cnt += len(cards)/5   # beta orb open (for open_all)
        else :
            cnt += 1            # reward open
        if 'cards' in cards  :
            cards = cards['cards']    # reward와 open pack의 경우에 key가 틀리다.        
        for card in cards :
            gold = ''
            if card['gold'] :
                gold = 'gold'
            id = card['card_detail_id']
            if id in open_cards : 
                val = open_cards[id]
                if card['gold'] :
                    val[1] += 1
                else :
                    val[0] += 1
            else :
                if card['gold'] :
                    open_cards[id] = [0,1]
                else :
                    open_cards[id] = [1,0]

    total =[0,0]
    list = []
    for card in open_cards :
        val = open_cards[card]
        total[0] += val[0]
        total[1] += val[1]
        #[id, type, val1, val2]
        info = [card, CARD_ID_NAME[str(card)][1], val[0], val[1]]
        list.append(info)

    gen_prices = 0
    gold_prices = 0
    slist = sorted(list, key = lambda x: (x[1]))  # 1번째가 key (type)
    for card in slist :
        price = get_cur_low_card_price(card[0], plist)
        price_gold = get_cur_low_card_price(card[0], pglist)
        gen_prices += card[2] * price
        gold_prices += card[3] * price_gold
        name = CARD_ID_NAME[str(card[0])][0]
        print(format(name, "20s"), format(CARD_TYPE_NAME[card[1]], "9s"), "[", format(card[2], "3d"), ",", format(card[3],"3d"), "]", format(card[2] * price,"6.2f"), format(card[3] * price_gold,"6.2f") )

    print("-----\ntotal value: $", format(gen_prices+gold_prices, "7,.2f"), ' total #cards:', total[0]+total[1])

def    has_gold_card_order(acc, sglist, cd_id) :
    for cd in sglist :
        if ( cd[0] == cd_id) :
            return 'Gold'
    return ' '

def print_this_pending_order(card, gd, num) :
    gold = ' '
    if gd != ' ' :
        gold = '+ gold card'
    # id, name, price, edition
    edition = EDITIONS[card[6]]
    print (format(card[0], "3d"), format(card[1][0], "20s"), format(card[2], "8s"), format(edition, "6s"), format(num, "4d"), gold)

def    print_my_pending_orders(acc, slist, sglist) :
    displayed = []
    cnt = 1
    gold = ' '
    # cd = [id, [name, rarirty(카드종류)], 가격(str), 0, id, seller]
    # common or intesting card
    pre_card = [-1]
    same_card = 1
    for cd in slist :
      if ( cd[0] not in displayed) :
          displayed.append(cd[0])
      if (pre_card[0] == -1) :  # 첫 카드에 대한 예외처리
          pre_card = cd
          continue

      if (pre_card[0] == cd[0]) : # 동일한 카드의 주문이 또 있느냐?
          same_card += 1
          continue
  
      gd = has_gold_card_order(acc, sglist, pre_card[0])
      print_this_pending_order(pre_card, gd, same_card)

      printed = pre_card[0]
      cnt += 1
      pre_card = cd
      same_card = 1
#            if (cnt % 20) == 0 :
#                print("press any key")
#                input()
    if printed != pre_card[0] : # print last card
        gd = has_gold_card_order(acc, sglist, pre_card[0])
        print_this_pending_order(pre_card, gd, same_card)

    # find only gold card
    print_pending_gold_only(displayed, sglist)
    print('-----------\n Total pending cards is ', len(slist) + len(sglist) )

def    print_pending_gold_only(displayed, sglist) :
    for card in sglist :
        if card[0] not in displayed :
            displayed.append(card[0])
            print_this_pending_order(card, 'Gold', 0)

def    get_my_pending_orders(acc) :
    market_data = []
    market_gd_data = []
    count = 0
    slist = []
    sglist = []
    for r in MARKET_REAL_DATA:
        if r["seller"] != acc :
            continue
        market_id = r["market_id"]
        card_detail_id = r["card_detail_id"]
        edition = r["edition"]
        gold = r["gold"]
        uid = r["uid"]
        buy_price = r["buy_price"]
        xp = r["xp"]
        card_name = CARD_ID_NAME[str(card_detail_id)]

        count += 1
        card_info = [card_detail_id, CARD_ID_NAME[str(card_detail_id)], buy_price, xp, market_id, acc, edition]
        if (gold) :
            market_gd_data.append(card_info)
        else :
            market_data.append(card_info)

        # alphabet 순으로 소팅
        slist = sorted(market_data, key = lambda x: (x[1]), reverse=False)  # 1번째가 key (name)
        sglist = sorted(market_gd_data, key = lambda x: (x[1]), reverse=False)  # 1번째가 key (name)

    return slist, sglist

def    my_pending_orders(acc) :
    print("id : ", acc)
    reload_market_data()
    slist, sglist = get_my_pending_orders(acc)
    if slist == [] :
        return    
    print_my_pending_orders(acc, slist, sglist)

import time
from datetime import datetime
#start : format "2019-10-05T14:00:52.206Z"
#end : format "2019-10-05T14:00:52.206Z" 
#    or '' 현재 utc 시간 얻어서 처리
def time_diff_in_sec(start, end='', utc=1) : # return based on sec
    st = start.split('.')  # milisec 삭제
    st_time = datetime.strptime(st[0],'%Y-%m-%dT%H:%M:%S') # datetime 포맷으로 변경

    if end == '' : # 현재 시각을 얻는다.
        end_time = datetime.utcnow()
        if utc != 1  : # local time 
            end_time = datetime.now()
    else :
        end = end.split('.')  # milisec 삭제
        end_time = datetime.strptime(end[0],'%Y-%m-%dT%H:%M:%S') # datetime 포맷으로 변경

    diff = end_time-st_time
    return (diff.total_seconds())

QUEST_NAME = {'Rising Dead' : 'Black',
              'Pirate Attacks' : 'Blue',
              "Stir the Volcano" : 'Red',
              "Lyanna's Call" : 'Green',
              'Defend the Borders' : 'White',
}
def print_dec_quest() :
    print("--- quest info ---")
    for acc in INT_ACCOUNTS :
        url =  'https://steemmonsters.com/players/quests?username=' + acc
        r = requests.get(url)
        quest_inf = r.json()
        if quest_inf == [] :
            continue
        quest_info = quest_inf[0]
        quest_done = 0
        diff_hours = time_diff_in_sec(quest_info['created_date']) / 3600  # 현재 시간 기준으로 비교
        # claim되었는지 확인, 이전 quest가 끝났다는 의미
        if quest_info['claim_date'] :
            # qeust 이후 24시간이 지났는지 확인
            if diff_hours < 24 :
                quest_done = 1

        print(format(acc,"13s"), "quest :",  quest_done, format(diff_hours,"5.2f"), QUEST_NAME[quest_info['name']])

        time.sleep(5)

    # https://steemmonsters.com/players/balances?username==tradingideas
    dec_total = 0
    for acc in INT_ACCOUNTS :
        url =  'https://steemmonsters.com/players/balances?username=' + acc
        r = requests.get(url)
        profiles = r.json()
        if profiles == [] :
            print("not existed account", acc)
            continue
        dec = 0
        ecr = 0
        for site in profiles:
            if site['token'] == 'DEC' :
                dec = site['balance']
                dec_total += dec
            elif site['token'] == 'ECR' :
                ecr = site['balance']

        print(format(acc, "15s"), "mana:", ecr, "dec:", format(dec, "8,.0f"))
        time.sleep(5)
    print("DEC total :", format(dec_total, "8,.0f"))

SPLINTER_TO_COLOR = {
    "fire" : 'Red',
    "water" : 'Blue',
    "earth" : 'Green',
    "life" : 'White',
    "death" : 'Black',
    "dragon" : 'Gold',
    "neutral" : 'Gray',
}

VALID_STATS = ['attack','ranged', 'magic']
VALID_SPLINTERS = ['fire', 'water','earth', 'life', 'death', 'dragon', 'neutral']

def get_stat_value(card, stat) :
    val = 0
    if card['type'] == 'Summoner' :
        val = card['stats'][stat]
    else :
        val = card['stats'][stat][len(card['stats'][stat])-1]
    
    return val

def print_cards_based_on_stat(splinter, stat) :
    cards = get_card_detail_info(0)
    color = SPLINTER_TO_COLOR[splinter]

    wanted = []
    wanted_neu = []
    for card in CARDS :
        if card['color'] == color or card['color'] == 'Gray':
            if card['type'] == 'Summoner' :
                continue
#                mana = card['stats']['mana']
            else :
                mana = card['stats']['mana'][len(card['stats']['mana'])-1]
            val = get_stat_value(card, stat)
            if ( val ) :
                if card['color'] == 'Gray':
                    wanted_neu.append([card['name'], mana, val])
                else :    
                    wanted.append([card['name'], mana, val])

    slist = sorted(wanted, key = lambda x: (x[1]), reverse=False)  # 2번째가 key 
    slist_neu = sorted(wanted_neu, key = lambda x: (x[1]), reverse=False)  # 2번째가 key

    print('splinter : ', splinter, 'stat : ', stat)
    print('------------------------------------')
    print('       name           mana stat_val')
    print('------------------------------------')
    for card in slist :
        print(format(card[0], "20s"), format(card[1], "5d"), format(card[2], "3d"))
    print('----------------------------------')
    print('splinter : Neutral',  'stat : ', stat)
    print('----------------------------------')
    for card in slist_neu :
        print(format(card[0], "20s"), format(card[1], "5d"), format(card[2], "3d"))

    print("finished, press any key and enter to contiune")
    name = input()
def card_trade_print_cond_user(tr, buyer, seller) :
    if buyer == 'all' and seller == 'all' :
        return 1
    if 'purchaser' in tr :
        if tr['purchaser'] != buyer and buyer != 'all' :
            return 0

        if tr['purchaser'] == buyer :
            return 1
        if tr['purchaser'] == seller :
            return 0
    try :
        if 'locked_by' in tr[0] :
            if buyer == 'all' :
                return 0
    except :
        return 1
#    if tr['purchaser'] == seller :
#        return 1
    return 1

def card_trade_print_cond(card_info, buyer, seller, edition, id) :
    if card_info['purchaser'] == buyer or buyer =='all' :
        if card_info['seller'] == seller or seller =='all' :
            if card_info['cards'][0]['edition'] == edition or edition == -1 :
                card_id = card_info['cards'][0]['card_detail_id'] # card_id : int
                if str(card_id) == id or id == 'all' :
                    return 1
    return 0

def print_trading_info_by_player(limit, buyer='all', seller='all', target_card_id='all') :
    if buyer != 'all' or seller != 'all' :
        user = buyer
        if user == 'all' :
            user = seller
        trades = get_data_from_sm("/players/history?from_block=-1&limit=100&types=sm_market_purchase,market_purchase,sm_market_sale,market_sale&username="+user, 1)

    print("Currency : USD", )
    cnt = 0

    # market_purchase : ok
    # sm_market_purchase : ing
    for tr in trades :
        if tr['result'] == None  : # 단순히 매도 주문
            continue
        results = json.loads(tr['result'])
        if card_trade_print_cond_user(results, buyer, seller) == 0 :
            continue
        if 'by_seller' not in results :  # 매수한 경우
            continue
        cnt+=1
        if cnt >= MAX_NUM_CARD_PRINTING :
            break;
        for result in results['by_seller'] :
            if result['total_usd'] >= float(limit) :
#                if result['buy_price'] >= float(limit) + 0.011 :
#                    continue
                for item in result['items'] :
                    # 매도인 경우에는 seller와 나와 같은 조건
                    if seller != 'all' :
                        if result['seller'] != seller :
                            continue

                    # 매수 혹은 매도의 경우에는 나의 것인 경우
                    trx_id = item
                    card_info = get_data_from_sm('market/status?id='+trx_id)
                    if float(card_info['buy_price']) < float(limit)  :
                        continue
                    if card_trade_print_cond(card_info, buyer, seller, -1, 'all') :
                        edition = card_info['cards'][0]['edition']
                        card_id = card_info['cards'][0]['card_detail_id']
                        gold = ' '
                        if card_info['cards'][0]['gold'] :
                            gold = 'G'
                        xp = card_info['cards'][0]['xp']
                        card_name = 'unknown'
                        if str(card_id) in CARD_ID_NAME :
                            card_name = CARD_ID_NAME[str(card_id)][0]
                        comp_date = card_info['completed_date'].split('T')
                        date_len = len(card_info['completed_date'])
                        comp_date = card_info['completed_date'][0:date_len-5]
                        print (comp_date, format(card_name, "17s"), format(card_info['buy_price'],"8s"), 'ed:', edition, 'xp:', format(xp,"4d"), gold, format(card_info['purchaser'],"13s"), format(card_info['seller'],"13s"))
        
def print_each_trading_info(trx_id, limit, buyer, seller, first) :
    card_info = get_data_from_sm('market/status?id='+trx_id)

    if float(card_info['buy_price']) < float(limit)  :
        return 0
    if card_trade_print_cond(card_info, buyer, seller, -1, 'all') :
        edition = card_info['cards'][0]['edition']
        card_id = card_info['cards'][0]['card_detail_id']
        gold = '    '
        if card_info['cards'][0]['gold'] :
            gold = 'Gold'
        xp = card_info['cards'][0]['xp']
        card_name = 'unknown'
        if str(card_id) in CARD_ID_NAME :
            card_name = CARD_ID_NAME[str(card_id)][0]
        comp_date = card_info['completed_date'].split('T')
        date_len = len(card_info['completed_date'])
        comp_date = card_info['completed_date'][0:date_len-5]
        if first  :
            print (comp_date, format(card_info['purchaser'],"13s"), format(card_info['seller'],"13s"))
            print ("    ", format(card_name, "17s"), format(card_info['buy_price'],"8s"), 'ed:', edition, 'xp:', format(xp,"4d"), gold)
        else :
            print ("    ", format(card_name, "17s"), format(card_info['buy_price'],"8s"), 'ed:', edition, 'xp:', format(xp,"4d"), gold)
        return 1
    return 0

def get_trading_sum_info(card_info, buyer, seller, wanted_card, wanted_buyer) :
        edition = card_info['cards'][0]['edition']
        card_id = card_info['cards'][0]['card_detail_id']
        gold = ' '
        if card_info['cards'][0]['gold'] :
            gold = 'G'
        xp = card_info['cards'][0]['xp']
        card_name = 'unknown'
        if str(card_id) in CARD_ID_NAME :
            card_name = CARD_ID_NAME[str(card_id)][0]
        if card_info['completed_date'] == None :
            tr_date = card_info['created_date']
        else :
            tr_date = card_info['completed_date']
        date_len = len(tr_date)

        comp_date = tr_date[5:date_len-8]

        if card_id in wanted_card :
            wanted_card[card_id] += 1
        else :
            wanted_card[card_id] = 1

        if card_info['purchaser'] in wanted_buyer :
            wanted_buyer[card_info['purchaser']] += 1
        else :
            wanted_buyer[card_info['purchaser']] = 1

#        print('buyer:', card_info['purchaser'], 'seller', card_info['seller'], 'price', card_info['buy_price'])
        return [comp_date, card_id, gold, xp, edition, float(card_info['buy_price']), card_info['purchaser'], card_info['seller']]


def print_trading_info(limit, buyer='all', seller='all', target_edition=-1, target_card_id='all') :
    num_tr = 1000
#    trades = get_data_from_sm("/transactions/history?from_block=-1&limit="+str(num_tr)+"&types=sm_market_sale,market_sale,sm_market_purchase,market_purchase", 1)
    trades = get_data_from_sm("/transactions/history?from_block=-1&limit="+str(num_tr)+"&types=sm_market_purchase", 1)

    print("Currency : USD", )
    cnt = 1
    wanted = []
    wanted_card = {}
    total_sold_cards = 0
    wanted_buyer = {}
    number_of_buyers = 0
    
    price_limit = 1
    block_id = ''
    for tr in trades :
        if tr['type'] == 'sm_market_purchase':
            if block_id == tr['id'] :
                continue
            block_id = tr['id']

            results = json.loads(tr['result'])
            for result in results :
                if 'error' in result :
                    continue
                total_sold_cards += 1
                if result['buy_price'] >= price_limit :
    #                if result['buy_price'] >= float(limit) + 0.011 :
    #                    continue
                        card_info = get_data_from_sm('market/status?id='+result['sell_trx_id'])
                        if card_trade_print_cond(card_info, buyer, seller, target_edition, target_card_id) :
                            data = get_trading_sum_info(card_info, buyer, seller, wanted_card, wanted_buyer)
                            wanted.append(data)
            cnt+=1
            if (cnt % 20 == 0) :
                print("processing", cnt)
            continue
        else :
            continue

    
    number_of_buyers = len(wanted_buyer)
    slist = sorted(wanted, key = lambda x: (x[5], x[0]), reverse=True)  # price, date가 key
    # [comp_date, card_id, gold, xp, edition, card_info['buy_price'], card_info['purchaser'], card_info['seller']
    stat_limit = 10
    cnt = 0
    for tr in slist :
        if cnt >= MAX_NUM_CARD_PRINTING :
            break;
        if tr[5] > float(limit) :
            print_this_trade(tr)
            cnt += 1
    if cnt == 0 :
        print("not exist more than ", limit)

    cnt = 0
    print('\n--------     Statistics [', num_tr, ']----------')
    # # card, # buyers
    print("num.of sold cards :", total_sold_cards, "num.of buyers :", number_of_buyers)
    print('\n-------- (1) High Price    ----------')
    for tr in slist :
        print_this_trade(tr)
        cnt += 1
        if cnt >= (stat_limit + 10) :
            break

    print('-------- (2) Freq. Sold     ----------')
    slist = sorted(wanted_card.items(), key = lambda t : t[1], reverse=True)  # 1: value

    cnt = 0
    for tr in slist :
        card_id = tr
        card_name = 'unknown'
        if str(card_id[0]) in CARD_ID_NAME :
            card_name = CARD_ID_NAME[str(card_id[0])][0]

        print(format(card_name, "22s"), tr[1])
        cnt += 1
        if cnt >= stat_limit :
            break

    print('\n-------- (3) Freq. Buyer     ----------')
    slist = sorted(wanted_buyer.items(), key = lambda t : t[1], reverse=True)  # 1: value
    cnt = 0
    for tr in slist :
        print(format(tr[0], "18s"), tr[1])
        cnt += 1
        if cnt >= stat_limit :
            break

def print_this_trade(tr) :
            card_name = 'unknown'
            card_id = str(tr[1])
            if card_id in CARD_ID_NAME :
                card_name = CARD_ID_NAME[card_id][0]
            print (tr[0], format(card_name, "20s"), format(str(tr[5]),"8s"), 'ed:', tr[4], 'xp:', format(tr[3],"4d"), tr[2], format(tr[6],"12s"))

def print_trading_info_old(limit) :
    trades = get_data_from_sm("/transactions/history?from_block=-1&limit=1000&types=sm_market_purchase, market_purchase", 1)
    print("Currency : USD", )
    cnt = 0
    for tr in trades :
        results = json.loads(tr['result'])
        for result in results :
            if cnt >= MAX_NUM_CARD_PRINTING :
                break;
            if result['buy_price'] >= float(limit) :
                card_info = get_data_from_sm('market/status?id='+result['sell_trx_id'])
                card_id = card_info['cards'][0]['card_detail_id']
                edition =card_info['cards'][0]['edition']
                gold = ' '
                if card_info['cards'][0]['gold'] :
                    gold = 'G'
                xp = card_info['cards'][0]['xp']
                card_name = 'unknown'
                if str(card_id) in CARD_ID_NAME :
                    card_name = CARD_ID_NAME[str(card_id)][0]
                comp_date = card_info['completed_date'].split('T')
                date_len = len(card_info['completed_date'])
                comp_date = card_info['completed_date'][0:date_len-5]
                print (comp_date, format(card_name, "18s"), format(card_info['buy_price'],"8s"), 'xp:', format(xp,"4d"), gold, format(card_info['purchaser'],"13s"))
                cnt+=1
        
    print("\nfinished, press any key and enter to contiune")
    name = input()

def print_delegation_cards(acc) :
    return
    gold = 0
    common = 0
    found = []

    headers = {
        'authority': 'kr.peakmonsters.com',
        'User-Agent': 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Mobile Safari/537.36'}

    url = 'https://kr.peakmonsters.com/api/contracts/' + acc +'?skip=0&limit=100&open=false'
    holding_delegate_cards = request_get(url, headers)
    
    delegatee_cards = {}
    delegator_cards = {}
    total_fee_per_day = 0
    total_income_per_day = 0
    for card in holding_delegate_cards['contracts'] :
        if card['delegatee'] == acc :
            uid = card['card_uid']  # string
            delegatee_cards[uid] = card['pending_payout'] # int
            total_fee_per_day += card['usd_price']
        if card['delegator'] == acc :
            uid = card['card_uid']  # string
            delegator_cards[uid] = card['pending_payout'] # int
            total_income_per_day += card['usd_price']

    slistee = sorted(delegatee_cards.items(), key = lambda t : t[1], reverse=False)  # 1: value
    slistor = sorted(delegator_cards.items(), key = lambda t : t[1], reverse=False)  # 1: value

    uids = ''
    for k in slistee :
        uids += (k[0]+',')
    
    url = "https://steemmonsters.com/cards/find?ids="+uids[0:len(uids)-1]
    cards_info = request_get(url)

    print("total deletaion fee per day", total_fee_per_day)
    print('------------')
    for data in slistee :
            card_info = get_card_info(cards_info, data[0]) # uid가 있는 card이름 전달
#            if v[0] > 0 or v[1] > 0 :
            print(format(card_info,"28s"), format(data[1],"3d"))

#-------------------
    uids = ''
    for k in slistor :
        uids += (k[0]+',')
    
    url = "https://steemmonsters.com/cards/find?ids="+uids[0:len(uids)-1]
    cards_info = request_get(url)
    print('------------')
    print("total deletaion income per day", total_income_per_day)
    print('------------')
    for data in slistor :
            card_info = get_card_info(cards_info, data[0]) # uid가 있는 card이름 전달
#            if v[0] > 0 or v[1] > 0 :
            print(format(card_info,"28s"), format(data[1],"3d"))


def get_card_info(lists, uid) :
    for c in lists :
        if c['uid'] == uid :
            id = c['card_detail_id']
            card_name = CARD_ID_NAME[str(id)][0].upper()
            gold = 'G'
            if c['gold'] == False :
                gold = ' '

            return card_name + ' (' + gold + ')'
    return 'unknown'

def menu1() :

    while(1) :
        print("\n=============================")
        print("1) card prices")
        print("2) interesting cards price")
        print("3) card remain status")
        print("31) mined-out cards")
        print("32) trading info by amount")
        print("33) trading info by player")

        print("----")
        print("4) my pending orders")
        print("5) cards need for purchasing")
        print("----")
        print("6) tournament prizes")
        print("----")
        print("7) open packs value")
        print("71) daily quest value")
        print("----")
        print("8) find the card holder")
        print("85) game history")
        print("----")
        print("9) print stats for each splinter")
        print("  usage : 9 splinter stat")
        print("   splinter(fire, water,earth, life, death, dragon, neutral")
        print("   stat(attack,ranged, magic)")
        print("91) print delegation cards for the given acc")
        print("----")
        print("10) DEC and Quest status")
        print("----")
        print("0) end")
        print("=============================")

        val = input()
        args = val.split(' ')
        if ( val == '1' ) :
            get_smon_settings()
            print('steem price : ', SMON_SETTINGS['steem_price'], 'dec price :', SMON_SETTINGS['dec_price']/SMON_SETTINGS['steem_price'])
            slist, sglist = get_cards_price(1,0) # (print_all = 1, from file = 1)
            print_market_card_list(1, slist, sglist)
        elif ( args[0] == '2' ) :
            get_smon_settings()
            slist, sglist = get_cards_price(0,0) # (print_all = 0(only int), from file = 1)
            print_market_card_list(0, slist, sglist)
        elif ( args[0] == '3' ) :
            card_issued_status(0, 0)
        elif ( args[0] == '31' ) :
            card_issued_status(0, 1)
        elif ( args[0] == '33' or args[0] == '32') :
            if len(args) >= 5 :
                if args[4] == 'all' :
                    ed = -1
                else :
                    ed = int(args[4])

            if (len(args) == 2) :
                print_trading_info(args[1]) # USD
            elif (len(args) == 3) :
                print_trading_info_by_player(args[1], args[2]) # USB from
            elif (len(args) == 4) :
                print_trading_info_by_player(args[1], args[2], args[3]) # USB from to
            elif (len(args) == 5) :
                print_trading_info_by_player(args[1], args[2], args[3], ed) # USB from to edition
            elif (len(args) == 6) :
                print_trading_info_by_player(args[1], args[2], args[3], ed, args[5]) # USB from to edition card_id
            else :
                print("usage : 32 USD(more) ")
                print("usage : 33 USD(more) seller buyer edtion(0,1,2,3,4) card_id")
        elif ( args[0] == '4' ) :
            if (len(args) > 1) :
                my_pending_orders(args[1])
            elif (len(args) == 1) :
                my_pending_orders(INT_ACCOUNTS[0])
            else :
                print("usage : 4 account")
        elif ( args[0] == '5' ) :
            get_smon_settings()
            sm_trading.init_steem_bc()
            sm_trading.buy_cards_within_condition()
        elif ( args[0] == '6' ) :
            if (len(args) > 1) :
                tournament_prizes(args[1])
            elif (len(args) == 1) :
                tournament_prizes(INT_ACCOUNTS[0])
            else :
                print("usage : 6 account")
        elif ( args[0] == '7' or args[0] == '71') :
            get_smon_settings()
            acc = INT_ACCOUNTS[0] 
            if (len(args) > 2) :
                acc = args[1]
                num = args[2]
            elif(len(args) == 2) :
                num = args[1]
            else :
                print("usage : 7 account #packs or 7 #packs")
                continue

            get_smon_settings()
            slist, sglist = get_cards_price(1,0) # (print_all = 1, from file = 1)
            param = "sm_pack_purchase,sm_open_pack,open_pack,sm_open_all,open_all"
            if args[0] == '71' :
                param = "sm_claim_reward"
            value_of_open_packs(acc, num, param, slist, sglist)
        elif ( args[0] == '8' ) :
            if (len(args) == 1) :
                name = input()
                find_card(name)
            else :
                print("usage : 8 (enter) card_name")
        elif ( args[0] == '85' ) :
            if (len(args) > 1) :
                game_history(args[1])
            elif (len(args) == 1) :
                game_history(INT_ACCOUNTS[0])
            else :
                print("usage : 85 account")

        elif ( args[0] == '9' ) :
            failed = 1
            if (len(args) == 3) :
                # args[1] splinter, args[2] stat
                if ( args[1] in VALID_SPLINTERS and args[2] in VALID_STATS) :
                    print_cards_based_on_stat(args[1], args[2])
                    failed = 0
            if failed :
                print("usage : 9 splinter(fire, water,earth, life, death, dragon, neutral)   stat(attack, ranged, magic)")
        elif ( args[0] == '91' ) :
            failed = 1
            if (len(args) == 2) :
                # args[1] acc, args[2] splinter
                print_delegation_cards(args[1])
            else :
                print("usage : 91 acc")

        elif ( args[0] == '10' ) :
            print_dec_quest()                
        elif ( val == '0' ) :
            return
        else  :
            print("press number")

if __name__ == "__main__":
    menu1()





Fetching token
?