Skip to content

Instantly share code, notes, and snippets.

@vgmoose
Last active Nov 7, 2018
Embed
What would you like to do?
WARNING: will overwrite the default local Anki DB, unless PATH is changed
import anki
from anki.storage import Collection
from anki.sync import Syncer, FullSyncer, RemoteServer, HttpSyncer
from pathlib import Path
# git clone git@github.com: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