Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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