55 lines
1.6 KiB
Python
55 lines
1.6 KiB
Python
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)
|