Created
February 10, 2016 19:29
-
-
Save cpetersen/7144eb25fecd3093d7b5 to your computer and use it in GitHub Desktop.
This gist converts your Dash Snippets to a Quiver Notebook. Assumes you Snippets.dash file is in the same directory and produces a Snippets.qvnotebook directory that can be imported into Quiver.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment