-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddOneDay.py
More file actions
92 lines (72 loc) · 2.48 KB
/
addOneDay.py
File metadata and controls
92 lines (72 loc) · 2.48 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
from anki.find import Finder
from anki.hooks import addHook
from aqt import mw
from aqt.qt import QAction
from aqt.utils import getText, showWarning, tooltip
from anki.lang import _
from .config import getIntervalCoefficient, getIntervalForNegativeCoefficient
# From https://stackoverflow.com/questions/1265665/how-can-i-check-if-a-string-represents-an-int-without-using-try-except
def RepresentsInt(s):
try:
return int(s)
except ValueError:
return None
def getDelay():
return getDelayWithResponse()[0]
def getDelayWithResponse():
(s, r) = getText("How many days would you like to postpone your cards? (negative number to subtract days)")
if r:
return (RepresentsInt(s), r)
return (None, r)
def getReviewCards():
cids = mw.col.find_cards("is:review")
return cids
def addDelay(cids):
(delay, delayResp) = getDelayWithResponse()
if delay is None:
if delayResp:
showWarning("Please enter an integral number of days")
return
mw.checkpoint("Adding delay")
mw.progress.start()
ivlDelay = max(0, round(delay * (getIntervalCoefficient()
if delay > 0 else getIntervalForNegativeCoefficient())))
for cid in cids:
card = mw.col.getCard(cid)
if card.type != 2:
continue
card.ivl += ivlDelay
if card.odid: # Also update cards in filtered decks
card.odue += delay
else:
card.due += delay
card.flush()
mw.progress.finish()
mw.col.reset()
mw.reset()
tooltip(_("""Delay added."""))
def addOneDayDelay(cids):
(delay, delayResp) = (1,1)
if delay is None:
if delayResp:
showWarning("Please enter an integral number of days")
return
mw.checkpoint("Adding delay")
mw.progress.start()
ivlDelay = max(0, round(delay * (getIntervalCoefficient()
if delay > 0 else getIntervalForNegativeCoefficient())))
for cid in cids:
card = mw.col.getCard(cid)
if card.type != 2:
continue
card.ivl += ivlDelay
if card.odid: # Also update cards in filtered decks
card.odue += delay
else:
card.due += delay
card.flush()
mw.progress.finish()
mw.col.reset()
mw.reset()
tooltip(_("""Delay added."""))
addOneDayDelay(getReviewCards())