Skip to content

Commit

Permalink
Allow converting extended deck from CrowdAnki format to source
Browse files Browse the repository at this point in the history
Fix anki-geo#666

It would be convenient for a single recipe to exist, and (given that
we're not actually saving the note model itself to file) it should be
possible, from a theoretical flow-of-data point of view, but I don't
think this is currently supported by BrainBrew — the exact name of the
note model has to be provided.  (It would also likely be non-trivial
to do this correctly, robustly and flexibly (while also not dropping
the option of using `save_to_file` in the general case), given that
the only reason this could theoretically work is because both note
models have the exact same fields.)

Tested that the recipe works as expected by:

1. Generate the CrowdAnki files in `build/` with the source to Anki
recipe.

2. Make a change in one of the `src/data/*.csv` files. (Note: this
is necessary before *3* because otherwise BrainBrew correctly notices
there are no changes, and doesn't actually re-sort the notes, which
would make the later comparison messy.)

3. Run the Anki to source [extended] recipe.  (This resorts the notes,
but resetting the actual content to the state from before *2*.)

4. Make a change in `build/Ultimate Geography [EN]
[Extended]/deck.json`.

5. Run the Anki to source [extended] recipe.

6. Compare the state between after *3* and after *5* and verify that
your change was applied.
  • Loading branch information
aplaice authored and axelboc committed Jan 27, 2025
1 parent 5ed604c commit f5f44f5
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 3 deletions.
12 changes: 9 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,17 @@ On first run, this recipe generates all the missing files and folders in the `bu
pipenv run brain_brew run recipes/anki_to_source.yaml
```

This recipe allows editing the English standard or extended deck in Anki, and then pulling the changes into the CSVs. Other languages are currently not supported. It also does not support editing the note model, card templates, deck description, etc. -- only the content of the notes.
or

```bash
pipenv run brain_brew run recipes/anki_to_source_[extended].yaml
```

These recipes allows editing the English standard or extended deck in Anki, and then pulling the changes into the CSVs. Other languages are currently not supported. It also does not support editing the note model, card templates, deck description, etc. -- only the content of the notes.

1. Make your edits in Anki.
1. Export the deck with CrowdAnki into the `build/Ultimate Geography [EN]` folder (even if you've edited the extended deck).
1. Run `pipenv run brain_brew run recipes/anki_to_source.yaml`.
1. Export the deck with CrowdAnki into the `build/Ultimate Geography [EN]` or `build/Ultimate Geography [EN] [Extended]` folders for the standard and extended decks respectively.
1. Run `pipenv run brain_brew run recipes/anki_to_source.yaml` or `pipenv run brain_brew run recipes/anki_to_source_[extended].yaml`.
1. Any new media will be placed at the top level of the `src/media` folder and will need to be moved into the appropriate sub-folder.

### How-to's
Expand Down
56 changes: 56 additions & 0 deletions recipes/anki_to_source_[extended].yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
- build_parts:
- notes_from_crowd_anki:
source: build/Ultimate Geography [EN] [Extended]
part_id: extended notes
sort_order: [Country]
# save_to_file: src/notes/english.yaml
- note_model_from_crowd_anki:
- source: build/Ultimate Geography [EN] [Extended]
part_id: Ultimate Geography [Extended]
# save_to_file: src/note_models/Ultimate_Geography_[Extended].yaml
- headers_from_crowd_anki:
- source: build/Ultimate Geography [EN] [Extended]
part_id: default
# save_to_file: src/headers/default.yaml
- media_group_from_crowd_anki:
- source: build/Ultimate Geography [EN] [Extended]
part_id: all_anki_media
- save_media_group_to_folder:
parts: [all_anki_media]
folder: src/media
clear_folder: false
recursive: true

- generate_csvs:
notes: extended notes

note_model_mappings:
- note_models:
- Ultimate Geography [Extended]

columns_to_fields:
guid: guid
country: Country
country info: Country Info
capital: Capital
capital info: Capital Info
capital hint: Capital hint
flag: flag
flag similarity: Flag similarity
map: map
tags: tags

personal_fields: []

file_mappings:
- file: src/data/main.csv
note_model: Ultimate Geography [Extended]

derivatives:
- file: src/data/guid.csv
- file: src/data/country.csv
- file: src/data/country_info.csv
- file: src/data/capital.csv
- file: src/data/capital_info.csv
- file: src/data/capital_hint.csv
- file: src/data/flag_similarity.csv

0 comments on commit f5f44f5

Please sign in to comment.