Last active
November 7, 2018 03:11
-
-
Save vgmoose/43703dc282152bb633cb82dd799d9d12 to your computer and use it in GitHub Desktop.
WARNING: will overwrite the default local Anki DB, unless PATH is changed
This file contains hidden or 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 anki | |
from anki.storage import Collection | |
from anki.sync import Syncer, FullSyncer, RemoteServer, HttpSyncer | |
from pathlib import Path | |
# git clone [email protected]:dae/anki.git | |
# cd anki | |
# pip3 install -r requirements.txt | |
# python3 demo.py | |
PATH = "%s/Library/Application Support/Anki2/User 1/collection.anki2" % str(Path.home()) | |
col = Collection(PATH) | |
#col = Collection("HelloThere.anki2") | |
# sync first | |
hkey = "RGyN4UdC6JHvxPQ3" | |
hostNum = 2 | |
server = RemoteServer(hkey, hostNum=hostNum) | |
b = FullSyncer(col, hkey, server.client, hostNum) | |
b.download() | |
col = Collection(PATH) | |
#b = Syncer(col, server) | |
#b.sync() | |
query = col.findCards("") # TODO: hardcode deck name | |
# interesting words to target | |
interesting = ["s"] | |
# outgoing list of cids to sort later | |
targets = [] | |
for cid in query: | |
card = col.getCard(cid) | |
note = col.getNote(card.nid) | |
front = note.fields[0] | |
if front in interesting: | |
targets.append(cid) | |
# set the selection of "targets" to position 0 | |
col.sched.sortCards(targets, start=0, shift=True) | |
b = Syncer(col, server) | |
b.sync() | |
col.db.commit() | |
col.db.close() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment