Skip to content

Instantly share code, notes, and snippets.

@hiroxto
Created February 10, 2021 11:10
Show Gist options
  • Save hiroxto/778b3281f96b0f9b9b7d7b153ce18715 to your computer and use it in GitHub Desktop.
Save hiroxto/778b3281f96b0f9b9b7d7b153ce18715 to your computer and use it in GitHub Desktop.
BankCodeJP APIの支店APIのレスポンスをcsvに変換する
# 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