Advertisement
Guest User

Untitled

a guest
Feb 10th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. require "json"
  2. require "sqlite3"
  3. require "fileutils"
  4.  
  5. notebook_name = "Snippets.qvnotebook"
  6. notebook_uuid = SecureRandom.uuid
  7. FileUtils::mkdir_p(notebook_name)
  8. notebook_meta = {
  9. name: "Imported from Dash",
  10. uuid: notebook_uuid
  11. }
  12. File.open("#{notebook_name}/meta.json", "w") { |f| f.puts notebook_meta.to_json }
  13.  
  14. db = SQLite3::Database.new("Snippets.dash")
  15. db.execute("select sid, title, body, syntax from snippets") do |note_row|
  16. tags = []
  17. db.execute("select t.tag from tags t, tagsIndex ti where t.tid = ti.tid AND ti.sid = ?", note_row.first) do |tag_row|
  18. tags << tag_row.first
  19. end
  20. note_syntax = case note_row[3]
  21. when "Shell"
  22. "sh"
  23. else
  24. note_row[3].downcase
  25. end
  26. note_uuid = SecureRandom.uuid
  27. FileUtils::mkdir_p("#{notebook_name}/#{note_uuid}.qvnote")
  28. note_meta = {
  29. created_at: Time.now.to_i,
  30. updated_at: Time.now.to_i,
  31. tags: tags,
  32. title: note_row[1],
  33. uuid: note_uuid
  34. }
  35. File.open("#{notebook_name}/#{note_uuid}.qvnote/meta.json", "w") { |f| f.puts note_meta.to_json }
  36.  
  37. note_content = {
  38. title: note_row[1],
  39. cells: [
  40. {
  41. type: "code",
  42. language: note_syntax,
  43. data: note_row[2]
  44. }
  45. ]
  46. }
  47. File.open("#{notebook_name}/#{note_uuid}.qvnote/content.json", "w") { |f| f.puts note_content.to_json }
  48. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement