Created
June 3, 2020 19:59
-
-
Save jordanhudgens/25e240ed127e0d135c5c9fe3b92be636 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
begin | |
Net::SFTP.start(HOSTNAME, USERNAME, :password => PASSWORD) do |sftp| | |
sftp.file.open("products.csv", "r") do |f| | |
puts "Opening file..." | |
# Old solution: | |
# data = SmarterCSV.process(f, value_converters: { sku: StringConverter }) | |
# puts "Count: #{data.size}" | |
# product_iterator data | |
# New attempt(s) | |
CSV.foreach(f.read, headers: true, converters: [->(v) { String(v) rescue v }]) do |row| | |
puts "Row: #{row.inspect}" | |
end | |
CSV.foreach(f.read, headers: true) do |row| | |
puts "Row: #{row.inspect}" | |
end | |
CSV.foreach(f, headers: true) do |row| | |
puts "Row: #{row.inspect}" | |
end | |
end | |
# Another attempt | |
# file = sftp.file.open("/home/packtshophacker/product-files/products.csv", "r") | |
# puts file.gets => this outputs the headers for the top of the file | |
# | |
# | |
# CSV.foreach(f, headers: true) do |row| | |
# puts "Row: #{row.inspect}" | |
# end | |
# | |
# file.close | |
end | |
rescue Net::SFTP::StatusException => e | |
puts "Error: ", e.inspect | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment