From 361a63b478ed54a889d14ab44b43ab3b49043ae4 Mon Sep 17 00:00:00 2001 From: Nate Bowman Date: Tue, 27 Oct 2026 19:23:22 -0400 Subject: [PATCH] Add research deck --- decks/research-non-unique.py | 54 ++++++++++++++++++++++++++++++++++++ flashcards/helpers.py | 3 ++ 2 files changed, 57 insertions(+) create mode 100644 decks/research-non-unique.py create mode 100644 flashcards/helpers.py diff --git a/decks/research-non-unique.py b/decks/research-non-unique.py new file mode 100644 index 0000000..8550ef4 --- /dev/null +++ b/decks/research-non-unique.py @@ -0,0 +1,54 @@ +from flashcards.decks import create_deck +from flashcards.helpers import parse_research_string +from flashcards.maps import (create_maps, + read_data_to_dict, + read_name_data_to_dict, + read_string_data_to_dict) + + + +# your choice of deck name and filename +deck_name = 'Research (Non-Unique)' +deck_fname = 'research-non-unique' + +# specify the namelist to be used to create the deck +# give the relative path of the file from config.namelists_dir +namelist = 'research-non-unique.txt' + +# key into json file specifying which data you want +name_json_keys = 'techs' +data_json_keys = ('data', 'Tech',) +string_json_keys = () + +# --- create list of notes --- + +_, nums = create_maps(namelist, name_json_keys) +data = read_data_to_dict(data_json_keys) +names = read_name_data_to_dict(name_json_keys) +strings = read_string_data_to_dict(string_json_keys) + +# create cards based on data and maps +order = ['Wood', 'Food', 'Gold', 'Stone'] +notes = [] +for name, num in nums.items(): + front = name + + cost = data[num]['Cost'] + # works, but puts wood in the wrong order (i.e., after food) + #all_cost = '\n'.join([f'{res}: {val}' for res, val in cost.items() + #if val != 0]) + all_cost = '\n'.join([f'{k}: {cost[k]}' for k in order + if k in cost.keys() and cost[k] != 0]) + + time_text = f'Research time: {data[num]["ResearchTime"]}' + + help_id = str(names[num]['help_converter']) + help_text = parse_research_string(strings[help_id]) + + back = '\n\n'.join([all_cost, time_text, help_text]) + + notes.append((front, back)) + #print(f'front: {name}\tback: {back}') + +# write deck to .apkg file +deck = create_deck(notes, deck_name, deck_fname) diff --git a/flashcards/helpers.py b/flashcards/helpers.py new file mode 100644 index 0000000..fe03c92 --- /dev/null +++ b/flashcards/helpers.py @@ -0,0 +1,3 @@ +def parse_research_string(string): + no_intro = string.split('\n')[1:] + return ' '.join(no_intro)