-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathanki.py
More file actions
50 lines (42 loc) · 1.3 KB
/
anki.py
File metadata and controls
50 lines (42 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import urllib.request
from typing import Dict
import json
from py_ankiconnect import PyAnkiconnect
anki = PyAnkiconnect()
def sync_anki() -> None:
"trigger anki synchronization"
sync_output = anki(action="sync")
assert (
sync_output is None or sync_output == "None"
), f"Error during sync?: '{sync_output}'"
def addtags(nid: int, tags: str) -> None:
assert isinstance(nid, (int, str))
assert isinstance(tags, str)
out = anki(
action="addTags",
notes=[int(nid)],
tags=tags,
)
assert out == "None" or out is None, f"Exception when adding '{tags}' to note: {nid}"
def removetags(nid: int, tags: str) -> None:
assert isinstance(nid, (int, str))
assert isinstance(tags, str)
out = anki(
action="removeTags",
notes=[int(nid)],
tags=tags,
)
assert out == "None" or out is None, f"Exception when removing '{tags}' to note: {nid}"
def updatenote(nid: int, fields: Dict) -> None:
assert isinstance(nid, (int, str))
assert isinstance(fields, dict)
out = anki(
action="updateNoteFields",
note={
"id": int(nid),
"fields": fields,
},
)
assert (
out == "None" or out is None
), f"Exception when updating note field done tag from note: {nid} {note}"