Created
June 16, 2012 08:41
-
-
Save rummelonp/2940548 to your computer and use it in GitHub Desktop.
メディアマーカーの CSV をブクログ形式にするやつ
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
# -*- 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