From 81c39a2e4270d37081cbd46dae6701e3a1415cd3 Mon Sep 17 00:00:00 2001 From: Diogo Cadavez Date: Mon, 17 Jun 2024 12:03:19 +0200 Subject: [PATCH] added note modification time to notesIndo and created notesModeTime function --- README.md | 39 +++++++++++++++++++++++++++++++++++++-- plugin/__init__.py | 18 ++++++++++++++++++ 2 files changed, 55 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a8c17c4..a0a0f37 100644 --- a/README.md +++ b/README.md @@ -4147,7 +4147,7 @@ Search parameters are passed to Anki, check the docs for more information: https #### `notesInfo` -* Returns a list of objects containing for each note ID the note fields, tags, note type and the cards belonging to +* Returns a list of objects containing for each note ID the note fields, tags, note type, modification time and the cards belonging to the note.
@@ -4177,7 +4177,42 @@ Search parameters are passed to Anki, check the docs for more information: https "fields": { "Front": {"value": "front content", "order": 0}, "Back": {"value": "back content", "order": 1} - } + }, + "mod": 1718377864, + } + ], + "error": null + } + ``` +
+s +#### `notesModTime` + +* Returns a list of objects containings for each note ID the modification time. + +
+ Sample request: + + ```json + { + "action": "notesModTime", + "version": 6, + "params": { + "notes": [1502298033753] + } + } + ``` +
+ +
+ Sample result: + + ```json + { + "result": [ + { + "noteId": 1498938915662, + "mod": 1629454092 } ], "error": null diff --git a/plugin/__init__.py b/plugin/__init__.py index 4037c23..44e5e58 100644 --- a/plugin/__init__.py +++ b/plugin/__init__.py @@ -1699,6 +1699,7 @@ class AnkiConnect: 'tags' : note.tags, 'fields': fields, 'modelName': model['name'], + 'mod': note.mod, 'cards': self.collection().db.list('select id from cards where nid = ? order by ord', note.id) }) except NotFoundError: @@ -1710,6 +1711,23 @@ class AnkiConnect: return result + @util.api() + def notesModTime(self, notes): + result = [] + for nid in notes: + try: + note = self.getNote(nid) + result.append({ + 'noteId': note.id, + 'mod': note.mod + }) + except NotFoundError: + # Anki will give a NotFoundError if the note ID does not exist. + # Best behavior is probably to add an 'empty card' to the + # returned result, so that the items of the input and return + # lists correspond. + result.append({}) + return result @util.api() def deleteNotes(self, notes):