Skip to content

Instantly share code, notes, and snippets.

@vgmoose
Last active November 7, 2018 03:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vgmoose/43703dc282152bb633cb82dd799d9d12 to your computer and use it in GitHub Desktop.
Save vgmoose/43703dc282152bb633cb82dd799d9d12 to your computer and use it in GitHub Desktop.
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