Instantly share code, notes, and snippets.

Embed
What would you like to do?
メディアマーカーの CSV をブクログ形式にするやつ
# -*- coding: utf-8 -*-
#
# メディアマーカーの CSV をブクログ形式にするやつ
# 使い方
# ruby mm2bl.rb /path/to/MediaMarkerExport.csv > output.csv
# 参考
# http://d.hatena.ne.jp/Unicellular/20120507/1336411135
require 'csv'
path = ARGV.shift
raise SystemExit.new 1 unless File.exists? path
lines = CSV.read(path)
lines.shift
lines = lines.map do |l|
_, _, _, _, category, _, _, _, _, isbn, _, _, asin, _, tag, comment, assess, _, _, _, purchase_date, _, state, read_date, _ = *l
servece_id = 1
state = case state
when '未読' then '積読'
when '読中' then 'いま読んでる'
when '読了' then '読み終わった'
else '読みたい'
end
memo = ''
[servece_id, asin, isbn, category, assess, state, comment, tag, memo, purchase_date, read_date]
end
puts lines.map { |l| '"' + l.map { |w| w.to_s.gsub(/"/, '\"').encode('SJIS') }.join('","') + '"' }.join("\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment