-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use Anki's API to send cards to Anki #3
Comments
I have looked a bit into the AnkiConnect and tried to make something. I documented the findings below. Here are the things that learned: The setupNaturally, the user needs to install AnkiConnect plugin and have Anki running. AnkiConnect exposes a ton of functionality via HTTP API. Structure of APIHTTP requests needs to contain a JSON-encoded object, with specific fields: {
"action": "forgetCards",
"version": 6,
"params": {
"cards": [1498938915662, 1502098034048]
}
} Where:
HTTP responses look like this: {
"result": ["Default", "Filtered Deck 1"],
"error": null
} Where:
What I tried to doI played a bit with the provided Python snippet and tried a few of the API methods. addNoteAs the name says, this is the action for adding notes. I could create a test note with the following JSON, I think that the most fields are self-explanatory. There are also possible {
"action": "addNote",
"version": 6,
"params": {
"note": {
"deckName": "Work Notes",
"modelName": "Basic",
"fields": {
"Front": "front content",
"Back": "back content"
},
"options": {
"allowDuplicate": false,
"duplicateScope": "deck",
"duplicateScopeOptions": {
"deckName": "Work Notes",
"checkChildren": true,
"checkAllModels": true
}
},
"picture": [{
"url": "https://upload.wikimedia.org/wikipedia/commons/thumb/c/c7/A_black_cat_named_Tilly.jpg/220px-A_black_cat_named_Tilly.jpg",
"filename": "black_cat.jpg",
"skipHash": "8d6e4646dfae812bf39651b59d7429ce",
"fields": [
"Back"
]
}],
"tags": [
"testinput"
]
}
}
} Some remarks:
updateNoteSame fields as above, with addition of {
"action": "updateNote",
"version": 6,
"params": {
"note": {
"id": 1514547547030,
"fields": {
"Front": "new front content",
"Back": "new back content"
},
"tags": ["new", "tags"]
}
}
} Some remarks:
Topics to discuss and do.
|
This is a prototype implementation. In the current state the md2anki will: - Send processed cards to the Anki via 'addNote' API - Send images to the Anki via 'storeMediaFile' API - Display basic info when that is being done - Display error messages if any step fails This feature is far from done: - deck name and note type are currently hardcoded, they should be provided by the caller for each card/note. - error handling and validation are missing. - code style will probably need to be adjusted. There are several TODO comments that ask questions. Related: Mochitto#3
This is a prototype implementation. In the current state the md2anki will: - Send processed cards to the Anki via 'addNote' API - Send images to the Anki via 'storeMediaFile' API - Display basic info when that is being done - Display error messages if any step fails This feature is far from done: - deck name and note type are currently hardcoded, they should be provided by the caller for each card/note. - error handling and validation are missing. - code style will probably need to be adjusted. There are several TODO comments that ask questions. Related: #3
Hello after quite some time! I would like to get back to working on this, since I have some free time in the coming months :) I looked again code that I wrote in the #16 and would like some input where to take this.
|
This commit adds for uploading cards via AnkiConnect plugin. Generated cards are now by default uploaded to the Anki via the plugin. The accompanying images references in the cards are also uploaded via the plugin. The addition of the AnkiConnect support means that frontmatter block is mandatory, since some of the fields are required by the plugin to upload the cards to the correct Anki deck, to use the correct note type, etc. The mandatory formatter fields are: - deck_name - note_type_basic - note_type_cloze The tags field is optional. The generation of Anki cards in CSV format is now marked as a legacy feature, it is by default turned off. User can also change the default URL of the AnkiConnect server via the .ini config file. Future work: - The code currently skips when trying to upload a card duplicate. In the future there an update system could be implemented. This would support a usecase where users would like to fix the already uploaded card via the markdown input file. - Currently the users need to provide the images file to the md2anki config file. This is not really needed, as the information about the image location is in the input markdown document itself. So that could be removed and thus UX would be a bit better, since that would be one less config option to carry about. - Currently the images must be local, there is no support for providing URL image links. Support for that could be added. Related: Mochitto#16 Closes: Mochitto#3
This commit adds support for uploading cards via AnkiConnect plugin. Generated cards are now by default uploaded to the Anki via the plugin. The accompanying images references in the cards are also uploaded via the plugin. The addition of the AnkiConnect support means that frontmatter block is mandatory, since some of the fields are required by the plugin to upload the cards to the correct Anki deck, to use the correct note type, etc. The mandatory formatter fields are: - deck_name - note_type_basic - note_type_cloze The tags field is optional. The generation of Anki cards in CSV format is now marked as a legacy feature, it is by default turned off. User can also change the default URL of the AnkiConnect server via the .ini config file. Future work: - The code currently skips when trying to upload a card duplicate. In the future there an update system could be implemented. This would support a usecase where users would like to fix the already uploaded card via the markdown input file. - Currently the users need to provide the images file to the md2anki config file. This is not really needed, as the information about the image location is in the input markdown document itself. So that could be removed and thus UX would be a bit better, since that would be one less config option to carry about. - Currently the images must be local, there is no support for providing URL image links. Support for that could be added. Related: Mochitto#16 Closes: Mochitto#3
Using CSV/manual import is a bit annoying; it would be nice if you could use the Anki API (it would require you to add the path to the collection file to the config) to send the cards automatically to anki.
Maybe it can also send images automatically (would remove the need of manually adding the media folder).
The text was updated successfully, but these errors were encountered: