Created
March 30, 2014 19:09
-
-
Save valtoni/9878008 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# import the main window object (mw) from ankiqt | |
from aqt import mw | |
# import the "show info" tool from utils.py | |
from aqt.utils import showInfo | |
# import all of the Qt GUI library | |
from aqt.qt import * | |
from time import mktime,time | |
from datetime import datetime | |
def testFunction(): | |
# get the number of cards in the current collection, which is stored in | |
# the main window | |
cardCount = mw.col.cardCount() | |
# show a message box | |
showInfo("Card count: %d" % cardCount) | |
def epochTodayMidnight(): | |
n = datetime.now() | |
midnight = datetime(n.year, n.month, n.day) | |
return mktime(midnight.timetuple()) | |
def deleteRevlog(timeinfo): | |
# showInfo("TIME: %d %d" % (timeinfo * 1000, time() * 1000)) | |
mw.col.db.execute("delete from revlog where id > ?", timeinfo * 1000) | |
def resetYearAgo(): | |
deleteRevlog(epochTodayMidnight() - DAY*365) | |
def resetMonthAgo(): | |
deleteRevlog(epochTodayMidnight() - DAY*30) | |
def resetThreeWeeksAgo(): | |
deleteRevlog(epochTodayMidnight() - DAY*21) | |
def resetTwoWeeksAgo(): | |
deleteRevlog(epochTodayMidnight() - DAY*14) | |
def resetOneWeekAgo(): | |
deleteRevlog(epochTodayMidnight() - DAY*7) | |
def resetYesterday(): | |
deleteRevlog(epochTodayMidnight() - DAY) | |
def resetToday(): | |
deleteRevlog(epochTodayMidnight()) | |
def resetLastHour(): | |
deleteRevlog(time() - HOUR) | |
# Day in seconds | |
DAY = 86400 | |
# Hour in seconds | |
HOUR = 3600 | |
# Create menu Reset Study | |
resetStudy = mw.form.menuTools.addMenu("Reset Study") | |
resetLastHourAction = resetStudy.addAction("Last hour") | |
resetTodayAction = resetStudy.addAction("Today") | |
resetYesterdayAction = resetStudy.addAction("Yesterday") | |
resetOneWeekAction = resetStudy.addAction("One Week") | |
resetTwoWeeksAction = resetStudy.addAction("Two Weeks") | |
resetThreeWeeksAction = resetStudy.addAction("Three Weeks") | |
resetMonthAction = resetStudy.addAction("A month ago") | |
resetYearAction = resetStudy.addAction("A year ago") | |
# Connect actions to functions | |
mw.connect(resetLastHourAction, SIGNAL("triggered()"), resetLastHour) | |
mw.connect(resetTodayAction, SIGNAL("triggered()"), resetToday) | |
mw.connect(resetYesterdayAction, SIGNAL("triggered()"), resetYesterday) | |
mw.connect(resetOneWeekAction, SIGNAL("triggered()"), resetOneWeekAgo) | |
mw.connect(resetTwoWeeksAction, SIGNAL("triggered()"), resetTwoWeeksAgo) | |
mw.connect(resetThreeWeeksAction, SIGNAL("triggered()"), resetThreeWeeksAgo) | |
mw.connect(resetMonthAction, SIGNAL("triggered()"), resetMonthAgo) | |
mw.connect(resetYearAction, SIGNAL("triggered()"), resetYearAgo) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment