From 7226fc3b179a881e07f5bb968ced58611bd481ee Mon Sep 17 00:00:00 2001 From: Dan Niemitalo Date: Sun, 29 Nov 2020 13:27:14 -0600 Subject: [PATCH] Analyze keywords in cards.json files Count unique keywords in sets and cubes. Output csv files included. --- analyze_keywords.py | 37 +++++++++++- cube_keyword_frequency.csv | 25 ++++++++ set_keyword_frequency.csv | 120 +++++++++++++++++++++++++++++++++++++ 3 files changed, 179 insertions(+), 3 deletions(-) create mode 100644 cube_keyword_frequency.csv create mode 100644 set_keyword_frequency.csv diff --git a/analyze_keywords.py b/analyze_keywords.py index c03f82e..3890111 100644 --- a/analyze_keywords.py +++ b/analyze_keywords.py @@ -1,4 +1,5 @@ import json +import os def get_keywords(card): @@ -39,6 +40,36 @@ def keyword_report(k_dict): print(f'\nTotal unique keywords: {len(k_dict)}') -filename = f'scryfall/sets/ZNR.json' -k_dict = keyword_count(filename) -keyword_report(k_dict) +# ### Example use: print a keyword report for a cards.json file ### +# filename = f'cubes/CoreTheElegantCube.json' +# k_dict = keyword_count(filename) +# keyword_report(k_dict) + + +# ### Example use: count keywords in a list of cube.json files ### +# output = open('cube_keyword_frequency.csv', 'w+') +# all_cube_files = os.listdir('cubes') +# output_file = open('cube_keyword_frequency.csv', 'w+') +# output_file.write('Cube,Keywords\n') +# for filename in all_cube_files: +# if filename.endswith('json'): +# k_dict = keyword_count('cubes/' + filename) +# output_file.write(f"{filename.strip('json')},{len(k_dict)}\n") +# print(filename, len(k_dict)) +# output_file.close() + + +# ### Example use: find keyword count in each set ### +# f = open('set_codes.txt') +# codes = [line.strip() for line in f.readlines()] +# output_file = open('set_keyword_frequency.csv', 'w+') +# output_file.write('Set,Keywords\n') +# for code in codes: +# if code == 'CON': +# code = 'CON_' +# filename = f'scryfall/sets/{code}.json' +# k_dict = keyword_count(filename) +# print(f'{code}: {len(k_dict)}') +# output_file.write(f'{code},{len(k_dict)}\n') +# output_file.close() +# f.close() diff --git a/cube_keyword_frequency.csv b/cube_keyword_frequency.csv new file mode 100644 index 0000000..60146bf --- /dev/null +++ b/cube_keyword_frequency.csv @@ -0,0 +1,25 @@ +Cube,Keywords +AlchemistsCrucible31.,62 +BeginnerCube.,17 +CasualChampionsCube.,71 +CoreResonanceBasic.,16 +CoreSetArchytas.,16 +CoreTheElegantCube.,70 +EvolvingWildsCube.,65 +GraveyardComboCube.,60 +Highball.,63 +kirblinxs_type_4_communal_stack.,85 +NoFreeLunches.,68 +NonblueGridMOriginsV3.,30 +OLDGraveyardComboCube.,64 +OPCube2020.,23 +penny_pincher_20inventors_fair.,57 +igh_a_cube.,66 +Simplicity.,21 +TheBlackCube.,74 +TheCoolSide.,62 +TheElegantCube.,107 +TheGameNightCube.,17 +TheGrandOdyssey.,17 +TheNoobCube.,26 +WheelofChange.,64 diff --git a/set_keyword_frequency.csv b/set_keyword_frequency.csv new file mode 100644 index 0000000..f4e50d6 --- /dev/null +++ b/set_keyword_frequency.csv @@ -0,0 +1,120 @@ +Set,Keywords +2ED,13 +3ED,14 +4ED,15 +5ED,18 +6ED,15 +7ED,14 +8ED,14 +9ED,17 +10E,22 +M10,19 +M11,19 +M12,17 +M13,21 +M14,19 +M15,20 +ORI,21 +M19,16 +M20,19 +M21,22 +POR,10 +P02,10 +PTK,10 +S99,9 +ARN,8 +ATQ,8 +LEG,17 +DRK,12 +FEM,9 +HML,11 +ICE,16 +ALL,13 +MIR,19 +VIS,18 +WTH,17 +TMP,18 +STH,10 +EXO,12 +USG,18 +ULG,12 +UDS,14 +MMQ,18 +NEM,12 +PCY,13 +INV,17 +PLS,10 +APC,11 +ODY,19 +TOR,16 +JUD,15 +ONS,15 +LGN,15 +SCG,20 +MRD,17 +DST,18 +5DN,20 +CHK,22 +BOK,15 +SOK,18 +RAV,22 +GPT,18 +DIS,17 +CSP,13 +TSP,26 +PLC,24 +FUT,50 +LRW,25 +MOR,22 +SHM,22 +EVE,24 +ALA,22 +CON_,25 +ARB,30 +ZEN,23 +WWK,16 +ROE,23 +SOM,21 +MBS,27 +NPH,22 +ISD,22 +DKA,23 +AVR,24 +RTR,23 +GTC,23 +DGM,30 +THS,24 +BNG,20 +JOU,22 +KTK,24 +FRF,21 +DTK,24 +BFZ,23 +OGW,22 +SOI,24 +EMN,25 +KLD,19 +AER,19 +AKH,23 +HOU,23 +XLN,22 +RIX,23 +DOM,22 +GRN,22 +RNA,23 +WAR,19 +ELD,20 +THB,20 +IKO,17 +ZNR,20 +MMA,38 +MM2,37 +EMA,28 +MM3,25 +IMA,29 +A25,31 +UMA,31 +2XM,52 +MH1,58 +CMR,42 +JMP,20