New Feature: Options for importing decks

Hi. Now that I finally got Anki to build locally, I’ve started working on a feature that I would like to add.

Here’s my Use Case:

I’m learning Japanese and I’m doing weekly lessons. I created a deck for all my Japanese notes. Based on the recommendations, you don’t want to create a deck for each week/lesson. But at the same time, I don’t want to add notes for lessons I haven’t started yet.

What I want is to create a deck that has all the notes for all the lessons. The notes will be tagged with the lesson. I would do this in a separate profile. Then I can export this as a deck.

When I switch to my actual profile, I would import this deck, but here’s the part that I’m working on, when you select a deck to import, you can:

  1. Specify an existing deck to import into (or new deck)
  2. Specify any tags that you want to filter the notes by before importing

So I would select my existing Japanese deck. Then select the tag for the lesson I want to import and it will merge it into my existing deck.

Anyway, I’ve already got a hard-coded implementation working. The Anki2Importer already supported deckPrefix to specify which deck to import into. I simply had to add tagFilter and if present, modify the SQL statement.

I know I could create an Add-On for this, but then I would have to duplicate all the functionality of Anki2Importer. So is this feature something that you could see being merged in to master?

# --
   self.nameToNum[unicodedata.normalize("NFC", v)] = k
   # run anki2 importer
+  self.deckPrefix = "Test Deck"
+  self.tagFilter = "HiraganaMaru"
   # import static media

# --
   dupesIgnored = []
   total = 0
-  for note in self.src.db.execute("select * from notes"):
+  sql = "select * from notes"
+  if self.tagFilter:
+      sql += f" where tags like '%{self.tagFilter}%'"
+  for note in self.src.db.execute(sql):
       total += 1
       # turn the db result into a mutable list

That sounds like a good feature, indeed.

1 Like

The importing code is still due for a rewrite soon, though it’s taken me longer than I would have liked. For this reason I don’t think it’s a good idea to be making tweaks to the current code at the moment, but please feel free to post the features you’re wanting on reminder: special fields when importing by Arthur-Milchior · Pull Request #507 · ankitects/anki · GitHub so I can bear them in mind when I rework the code.