Last active
December 28, 2018 13:17
-
-
Save moyashi/e72aa75573edf3fe8360244daee97173 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 ( https://coincheck.com/ja/affiliates ) からダウンロードできる affiliates-201x-xx-xx_2.csv を、 | |
# Gtax ( https://crypto-city.net/balance ) にインポートできる共通フォーマット形式のcsvに変換するRubyスクリプト | |
# 共通フォーマットサンプル.xlsxはxslxだけど、csvでもインポートできてるぽい | |
# 無保証 | |
# 使い方 | |
# ./coincheck_affiliates_csv_converter.rb affiliates-201x-xx-xx_2.csv | |
# するとカレントディレクトリに affiliates-filtered.csv ができる | |
require 'csv' | |
require 'time' | |
require 'kconv' | |
if (ARGV.length == 0) then | |
STDERR.puts "引数に affiliates-201x-xx-xx_2.csv を渡してください" | |
exit | |
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("affiliates-filtered.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