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:
- Specify an existing deck to import into (or new deck)
- 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?
# -- apkg.py
self.nameToNum[unicodedata.normalize("NFC", v)] = k
# run anki2 importer
+ self.deckPrefix = "Test Deck"
+ self.tagFilter = "HiraganaMaru"
Anki2Importer.run(self)
# import static media
# -- anki2.py
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