WordRefAnkiNoteCreate - a python command line utility to automate Anki Note creation

GitHub Repo for WordRefAnkiNoteCreate:

https://github.com/jglotzer/WordRefAnkiNoteCreate


As a committed user of both Anki as well as wordreference.com I've always wanted to have an easy way to create new Anki Cards. Creating Anki Cards (or more accurately, Anki Notes, as a Note consists of two sides while a Card is only one side.) can be a laborious, manual process, depending on how complicated or aesthetic you want the card to be. Most of the information one might want can be found at wordreference.com, it's just not organized and/or formatted in a way that makes sense for the way I happen to use Anki. This is because, quite commonly, words have multiple meanings and I want each meaning to be listed once on each side of the created Note. Also, having appealing fonts and colors is a plus. Anything you can do to make the information "stick" in your brain is going to be helpful with this sort of memorization.

Here's an example of what the wordreference.com site shows its users for an example word:



The first step I made in addressing this goal was to find a nice tool called wordreference.py, This is a python code that uses the python package BeautifulSoup to scrape the web content for a given word one might want to learn. This was already a game changer, but given my preferred workflow, it was not presenting the information in the order that I wanted/needed and even there it was only printing the information to the Linux console, and not inputting it into the Anki software.

Here's an example of the unmodified output from wordreference.py after it scrapes the above page :



While this is very visually appealing, for my particular workflow, I wanted the French word and the French examples on one side of the Anki Card (or Note), and I wanted each definition (both English and French) on the other side of the Anki Note. Oh and by the way, I didn't want the English examples at all. 

The next step was to use the python dictionary provided by wordreference.py and sort the output so that the information was presented in an order that I could leverage. 

The result of this effort was this: 



After some time I realized I could "copy as html" (a feature of Gnome Terminal) the colored text for front and back and paste them into the HTML input part of Anki. 

The result was something like this:

(N.B. Pictures insertion is a key part of my workflow but this still requires human intervention. Probably generative AI might be able to help out here but for now I add the pictures in myself). 


Finally, the next step was to ask, how can I programatically get the same information into Anki without any cut and pasting. After a bit of searching I happened upon the Anki AddOn (AddOns are what Anki calls plugins) called  AnkiConnect AddOn. This is a great piece of software that turns the instance of Anki running on your machine into a local webserver. You send a carefully crafted JSON string in the form of a URL request to this local server and AnkiConnect takes the requested action which in this case is "Create an Anki Note". 

So that is pretty much it. What started out as a very manual process that took a lot of time (5 to 10 minutes) and effort to create a single card (note), is now a fully (well aside from the pictures) automated task that happens in seconds. So now effectively the software goes from the picture at the top to the fully created Anki Note seen in the picture at the bottom (of course minus the pictures which is still a manual step). Basically the basics were already there in the form of wordreference.py  and AnkiConnect AddOn. I just had to write a small amount of code to tie these two pieces together. 





Comments

Popular posts from this blog

Hit failing alternator with a hammer to confirm diagnosis of failing alternator due to bad brushes

alternatives --install gets stuck: failed to read link: No such file or directory

Using SSH, SOCKS, tsocks, and proxy settings to create a simultaneous "dual use" work/home computer