Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require "json"
- require "sqlite3"
- require "fileutils"
- notebook_name = "Snippets.qvnotebook"
- notebook_uuid = SecureRandom.uuid
- FileUtils::mkdir_p(notebook_name)
- notebook_meta = {
- name: "Imported from Dash",
- uuid: notebook_uuid
- }
- File.open("#{notebook_name}/meta.json", "w") { |f| f.puts notebook_meta.to_json }
- db = SQLite3::Database.new("Snippets.dash")
- db.execute("select sid, title, body, syntax from snippets") do |note_row|
- tags = []
- db.execute("select t.tag from tags t, tagsIndex ti where t.tid = ti.tid AND ti.sid = ?", note_row.first) do |tag_row|
- tags << tag_row.first
- end
- note_syntax = case note_row[3]
- when "Shell"
- "sh"
- else
- note_row[3].downcase
- end
- note_uuid = SecureRandom.uuid
- FileUtils::mkdir_p("#{notebook_name}/#{note_uuid}.qvnote")
- note_meta = {
- created_at: Time.now.to_i,
- updated_at: Time.now.to_i,
- tags: tags,
- title: note_row[1],
- uuid: note_uuid
- }
- File.open("#{notebook_name}/#{note_uuid}.qvnote/meta.json", "w") { |f| f.puts note_meta.to_json }
- note_content = {
- title: note_row[1],
- cells: [
- {
- type: "code",
- language: note_syntax,
- data: note_row[2]
- }
- ]
- }
- File.open("#{notebook_name}/#{note_uuid}.qvnote/content.json", "w") { |f| f.puts note_content.to_json }
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement