Skip to content

Instantly share code, notes, and snippets.

@htakeuchi
Last active July 24, 2017 05:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save htakeuchi/933064d05c2178da9da3 to your computer and use it in GitHub Desktop.
Save htakeuchi/933064d05c2178da9da3 to your computer and use it in GitHub Desktop.
KobitoのデータベースからMarkdownを抽出
# -*- coding: utf-8 -*-
require 'rubygems'
require 'sqlite3'
# ~/Library/Containers/com.qiita.Kobito/Data/Library/Kobito/Kobito.db
KOBITO_DB = "/tmp/Kobito.db"
EXPORT_PATH = "/tmp/export"
COLUMNS = %w(ZTITLE ZRAW_BODY)
db = SQLite3::Database.new(KOBITO_DB)
db.execute("select #{COLUMNS.join(',')} from ZITEM where ZIN_TRASH IS NULL") do |note|
file = %!#{EXPORT_PATH}/#{note[0].gsub(/(\/|\.\.)/, '_')}.md!
open(file, 'w') {|f| f.write note[1]}
puts file
end
db.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment