Created
February 10, 2021 11:10
-
-
Save hiroxto/778b3281f96b0f9b9b7d7b153ce18715 to your computer and use it in GitHub Desktop.
BankCodeJP APIの支店APIのレスポンスを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
# BankCodeJP APIの支店APIのレスポンスをcsvに変換する | |
# | |
# 実行方法 | |
# $ ruby convert-to-csv.rb ${source_filename} ${dist_filename} | |
require 'json' | |
require 'csv' | |
if ARGV.length < 2 | |
puts 'ファイル名を渡してください' | |
exit(1) | |
end | |
source_filename = ARGV[0] | |
dist_filename = ARGV[1] | |
response = JSON.parse(File.read(source_filename)) | |
branches = response['data'] | |
csv_string = CSV.generate do |csv| | |
branches.each do |branch| | |
csv << branch.slice('code', 'name', 'halfWidthKana', 'fullWidthKana', 'hiragana').values | |
end | |
end | |
File.write(dist_filename, csv_string) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment