Created
December 28, 2018 08:32
-
-
Save moyashi/94d74f6ef1c50572207a753d96324a14 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env ruby | |
# coding: utf-8 | |
# coincheckからダウンロードできる affiliates-201x-xx-xx_2.csv を、 | |
# Gtaxにインポートできる共通フォーマット形式のcsvに変換するRubyスクリプト | |
# 共通フォーマットサンプル.xlsxはxslxだけど、csvでもインポートできてるぽい | |
# 無保証 | |
# 使い方 | |
# ./coincheck_affiliates_csv_converter.rb affiliates-201x-xx-xx_2.csv | |
# するとカレントディレクトリに output.csv ができる | |
require 'csv' | |
require 'time' | |
require 'kconv' | |
if (ARGV.length == 0) then | |
STDERR.puts "引数に affiliates-201x-xx-xx_2.csv を渡してください" | |
end | |
buf = open(ARGV[0]).read | |
buf.gsub!("\r\n", "\n") | |
buf.gsub!("\r", "\n") | |
csv_data = CSV.parse(buf, headers: true) | |
output = CSV.generate do |csv| | |
row = "取引所名|日時(JST)|取引種別|取引通貨名(+)|取引量(+)|取引通貨名(-)|取引量(-)|取引額時価|手数料通貨名|手数料数量".split("|") | |
csv << row | |
csv_data.each do |data| | |
if (data["Progress"] != "canceled") then | |
t = Time.parse(data["Confirmed"]).localtime.strftime("%Y/%m/%d %H:%M") | |
rate = 1.0 / data["Amount"].to_f * data["JPY Amount"].to_f | |
row = [ | |
# 取引所名 | |
"coincheck", | |
# 日時(JST) | |
t, | |
# 取引種別 | |
"ボーナス", | |
# 取引通貨名(+) | |
data["Currency"], | |
# 取引量(+) | |
data["Amount"], | |
# 取引通貨名(-) | |
nil, | |
# 取引量(-) | |
nil, | |
# 取引額時価 | |
rate, | |
# 手数料通貨名 | |
nil, | |
# 手数料数量" | |
nil | |
] | |
csv << row | |
end | |
end | |
end | |
File.open("output.csv", 'w') do |file| | |
file.write(output.gsub("\n", "\r\n").tosjis) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment