-
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.
|
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: