Skip to content

Instantly share code, notes, and snippets.

@sedrickcz
Last active February 16, 2018 00:16
Show Gist options
  • Save sedrickcz/a7dc8c2b5bd4af0fe613131bc0f46e28 to your computer and use it in GitHub Desktop.
Save sedrickcz/a7dc8c2b5bd4af0fe613131bc0f46e28 to your computer and use it in GitHub Desktop.
Payment csv merger
payments = SmarterCSV.process('paypal1.csv', { col_sep: ";" })
File.open("paypal_payments.csv", 'w+') { |file|
file.write("status;email;transaction_id;country;country_code\n")
}
payments.each do |payment|
country_code = ISO3166::Country.find_country_by_name(payment[:country])&.alpha2
File.open("paypal_payments.csv", 'a') { |file|
file.write("#{payment[:status]};#{payment[:from_email_address]};#{payment[:transaction_id]};#{payment[:country]};#{country_code}\n")
}
end
payments2 = SmarterCSV.process('paypal2.csv', { col_sep: "," })
payments2.each do |payment|
File.open("paypal_payments.csv", 'a') { |file|
file.write("#{payment[:status]};#{payment[:email]};#{payment[:transaction_id]};#{payment[:country]};#{payment[:country_code]}\n")
}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment