Skip to content

Instantly share code, notes, and snippets.

Last active November 7, 2018 03:11
What would you like to do?
WARNING: will overwrite the default local Anki DB, unless PATH is changed
import anki
from import Collection
from anki.sync import Syncer, FullSyncer, RemoteServer, HttpSyncer
from pathlib import Path
# git clone
# cd anki
# pip3 install -r requirements.txt
# python3
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)
col = Collection(PATH)
#b = Syncer(col, server)
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:
# set the selection of "targets" to position 0
col.sched.sortCards(targets, start=0, shift=True)
b = Syncer(col, server)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment