Add examples of deck scripts and namelists

This commit is contained in:
Nate Bowman
2026-11-21 14:49:53 -05:00
parent 6d05bfa7d5
commit a586357cc0
18 changed files with 1506 additions and 1 deletions

54
decks/counters.py Normal file
View File

@@ -0,0 +1,54 @@
from collections import defaultdict
import json
from flashcards.config import config
from flashcards.decks import create_deck
from flashcards.maps import create_maps, read_name_data_to_dict
def generate_counter_list(counters):
all_c_names = []
for c_type in sorted(counters.keys()):
c_names = '\n'.join(counters[c_type])
if len(c_names) > 0:
all_c_names.append(f'<b>{c_type}</b>:\n\n{c_names}')
return '\n\n\n'.join(all_c_names)
# your choice of deck name and filename
deck_name = 'Counters'
deck_fname = 'counters'
# --- create list of notes ---
# read in data
with open(config.data_dir / 'counters.json', 'r') as f:
data = json.load(f)
# determine countered_by from counters
all_countered_by = defaultdict(lambda: defaultdict(list))
for unit, counters in data.items():
for counter_type in counters.keys(): # 'hard' or 'soft'
for unit2 in counters[counter_type]:
all_countered_by[unit2][counter_type].append(unit)
notes = []
for unit in data.keys():
# note: 'counters' contains units countered *by* 'unit'
# note: 'countered_by' contains units that counter 'unit'
counters = data[unit]
countered_by = all_countered_by[unit]
front = f'{unit} is a counter against...'
back = generate_counter_list(counters)
notes.append((front, back))
#print(f'front: {front}\tback: {back}')
front = f'{unit} is countered by...'
back = generate_counter_list(countered_by)
notes.append((front, back))
#print(f'front: {front}\tback: {back}')
# write deck to .apkg file
deck = create_deck(notes, deck_name, deck_fname)