Move .csvs to subdirectory, refactor cube_json.py out of word_count.py
This commit is contained in:
parent
7226fc3b17
commit
32f8c20b2e
8 changed files with 110 additions and 95 deletions
|
|
@ -1,6 +1,8 @@
|
|||
import json
|
||||
import os
|
||||
|
||||
import cube_json
|
||||
import word_count
|
||||
|
||||
def get_keywords(card):
|
||||
if 'keywords' in card.keys():
|
||||
|
|
@ -40,36 +42,40 @@ def keyword_report(k_dict):
|
|||
print(f'\nTotal unique keywords: {len(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)
|
||||
if __name__ == '__main__':
|
||||
### Example use: print a keyword report for a cards.json file ###
|
||||
# cube_list = cube_json.load_cube_from_csv('cube_csvs/TheElegantCube_2020-11-17_5.0.4.csv', {'core'})
|
||||
# cube_json_filename = cube_json.create_cube_json(cube_list, 'cubes/TheElegantCube_2020-11-17_5.0.4.json')
|
||||
# keyword_dict = keyword_count(cube_json_filename)
|
||||
# keyword_report(keyword_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: 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()
|
||||
# ### 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()
|
||||
|
||||
pass
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue