added note modification time to notesIndo and created notesModeTime function

This commit is contained in:
Diogo Cadavez 2024-06-17 12:03:19 +02:00 committed by Alex Yatskov
parent f52e0c2e24
commit 81c39a2e42
2 changed files with 55 additions and 2 deletions

View File

@ -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.
<details>
@ -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
}
```
</details>
s
#### `notesModTime`
* Returns a list of objects containings for each note ID the modification time.
<details>
<summary><i>Sample request:</i></summary>
```json
{
"action": "notesModTime",
"version": 6,
"params": {
"notes": [1502298033753]
}
}
```
</details>
<details>
<summary><i>Sample result:</i></summary>
```json
{
"result": [
{
"noteId": 1498938915662,
"mod": 1629454092
}
],
"error": null

View File

@ -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):