From e17e9a349c42027de32ef8c48303acd3c42bd6e1 Mon Sep 17 00:00:00 2001 From: Dan Niemitalo Date: Sun, 9 Jun 2024 10:18:30 -0500 Subject: [PATCH] 2024 Fixes 1) The CubeCobra CSV headers have changed slightly, capitalizing some words. 2) Cards in the maybeboard should not be included in the averages, so this filters them out. 3) Minor simplifications made to the keyword and word count analysis files to make it a bit easier for amateurs like me to figure out how to run these scripts. --- analyze_cube_keywords.py | 6 ++++-- cubecobra_csv.py | 25 ++++++++++++++++--------- word_count.py | 5 +++-- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/analyze_cube_keywords.py b/analyze_cube_keywords.py index 45e87eb..2a3a926 100644 --- a/analyze_cube_keywords.py +++ b/analyze_cube_keywords.py @@ -6,8 +6,10 @@ import cubecobra_csv import keyword_stats if __name__ == '__main__': - cube_list = cubecobra_csv.load_cube_names('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') + cube_id = 'jeskaicube' + csv_path = cubecobra_csv.request_cube_csv(cube_id, cube_id) + cube_list = cubecobra_csv.load_cube_names(f'cube_csvs/{cube_id}.csv') + cube_json_filename = cube_json.create_cube_json(cube_list, f'cubes/{cube_id}.json') keyword_dict = keyword_stats.keyword_count(cube_json_filename) # keyword_stats.keyword_report(keyword_dict) diff --git a/cubecobra_csv.py b/cubecobra_csv.py index 3f8ddeb..320c80a 100644 --- a/cubecobra_csv.py +++ b/cubecobra_csv.py @@ -7,7 +7,7 @@ from typing import List, Set import requests EXPECTED_HEADER = [ - 'Name', + 'name', 'CMC', 'Type', 'Color', @@ -15,12 +15,12 @@ EXPECTED_HEADER = [ 'Collector Number', 'Rarity', 'Color Category', - 'Status', + 'status', 'Finish', - 'Maybeboard', - 'Image URL', - 'Image Back URL', - 'Tags', + 'maybeboard', + 'image URL', + 'image Back URL', + 'tags', 'Notes', 'MTGO ID' ] @@ -95,7 +95,8 @@ def load_cube(filename) -> List[CubeCard]: tags = _get_tags(line) color_category = _get_color_category(line) colors = _get_colors(line) - cards.append(CubeCard(card_name, color_category, colors, tags)) + if not _get_maybeboard(line): + cards.append(CubeCard(card_name, color_category, colors, tags)) return cards @@ -104,11 +105,11 @@ def _assert_header(header_line): def _get_name(line: List) -> str: - return line[COLUMNS['Name']] + return line[COLUMNS['name']] def _get_tags(line: List) -> Set[str]: - return set(t.strip() for t in line[COLUMNS['Tags']].split(';')) + return set(t.strip() for t in line[COLUMNS['tags']].split(';')) def _get_color_category(line: List) -> str: @@ -121,3 +122,9 @@ def _get_colors(line: List) -> str: colors = line[COLUMNS['Color']] #assert color_category in _COLOR_CATEGORIES, f'color_category "{color_category}" unknown' return sorted(colors.lower()) + +def _get_maybeboard(line: List) -> str: + maybeboard = line[COLUMNS['maybeboard']] + if 't' in maybeboard.lower(): + return True + return False \ No newline at end of file diff --git a/word_count.py b/word_count.py index 47c6a93..fa8df18 100644 --- a/word_count.py +++ b/word_count.py @@ -173,8 +173,9 @@ if __name__ == '__main__': # cube_list = cubecobra_csv.load_cube_names(csv_path) # 2. If you have your cube in Cube Cobra and want to consider only cards with a certain tag - csv_path = cubecobra_csv.request_cube_csv('TheElegantCube_fetched', 'elegant') - cube_list = cubecobra_csv.load_cube_names(csv_path, tag_filter={'core'}) + cube_id = 'jeskaicube' + csv_path = cubecobra_csv.request_cube_csv(cube_id, cube_id) + cube_list = cubecobra_csv.load_cube_names(csv_path, tag_filter=None) # 3. If you have a .txt of your cube # cube_list = cube_json.load_cube_from_txt('YourCubeHere.txt')