Skip to content

Instantly share code, notes, and snippets.

@thefloweringash
Created June 27, 2016 12:57
Show Gist options
  • Save thefloweringash/bd888b0179bb9b6569fb090715748c1f to your computer and use it in GitHub Desktop.
Save thefloweringash/bd888b0179bb9b6569fb090715748c1f to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'sqlite3'
db = SQLite3::Database.new(ARGV[0])
SEP = "\u001f"
# First field in deck is frame number from the v6 edition (well
# actually the id, but the id and frame number seem to match)
#
# Which you can verify by looking at the flds of the deck
# "flds":
# [ {"name": "id", "rtl": false, "sticky": false, "media": [], "ord": 0, "font": "DejaVu Sans", "size": 14}
# , {"name": "frameNoV4", "rtl": false, "sticky": false, "media": [], "ord": 1, "font": "MS Shell Dlg 2", "size": 14}
# , {"name": "frameNoV6", "rtl": false, "sticky": false, "media": [], "ord": 2, "font": "MS Shell Dlg 2", "size": 14}
# , {"name": "keyword", "rtl": false, "sticky": false, "media": [], "ord": 3, "font": "MS Shell Dlg 2", "size": 14}
# , {"name": "kanji", "rtl": false, "sticky": false, "media": [], "ord": 4, "font": "DejaVu Sans", "size": 26}
# , {"name": "strokeDiagram", "rtl": false, "sticky": false, "media": [], "ord": 5, "font": "Courier New", "size": 14}
# Fields are stored seperated by a special character
notes_to_order = db.execute('select id,flds from notes').each_with_object(Hash.new) do |(id, flds), h|
h[id] = flds.split(SEP).first
end
# Card appearance order seems to be controlled by due, so set the due
# to the frame number and we're done.
arr = db.execute('select id,nid from cards')
arr.each do |card_id, note_id|
db.execute('update cards set due = ? where id = ?', notes_to_order[note_id], card_id)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment