From 4091fcdd44dcf85667a8230ef28a02f915f56a1a Mon Sep 17 00:00:00 2001 From: Gabe Farrell Date: Tue, 13 Jun 2023 04:13:08 +0000 Subject: [PATCH] Add cleaned data upload script for Lowell --- lib/tasks/upload.rake | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 lib/tasks/upload.rake diff --git a/lib/tasks/upload.rake b/lib/tasks/upload.rake new file mode 100644 index 00000000..54cdd6b7 --- /dev/null +++ b/lib/tasks/upload.rake @@ -0,0 +1,24 @@ +namespace :upload do + desc 'upload cleaned Lowell CSVs to the SFTP server' + task lowell: :environment do + new_files = Array.new + input_filepath = Rails.root.join('tmp', 'data', 'rpp_data', 'clean') + Dir.foreach(input_filepath) do |filename| + next if filename.start_with?('.') # skip hidden files and ./.. directories + # this can probably be replaced with Dir.join or similar + input_filename = Rails.root.join('tmp', 'data', 'rpp_data', 'clean', filename).to_s + sftptogo_url = ENV['SFTPTOGO_URL'] + uri = URI.parse(sftptogo_url) + Net::SFTP.start(uri.host, uri.user, password: uri.password) do |sftp| + puts "Uploading #{filename}..." + sftp.upload!(input_filename, "/data/survey_responses/clean/#{filename}") + end + new_files.append(filename) + end + # print remote directory contents with new files marked + path = '/data/survey_responses/clean/' + Sftp::Directory.open(path:) do |file| + # the open method already prints all the contents... + end + end +end \ No newline at end of file