Skip to content

Commit

Permalink
Correct indentation
Browse files Browse the repository at this point in the history
  • Loading branch information
RosieH1 committed Jul 4, 2024
1 parent 67db404 commit 7b3fa51
Showing 1 changed file with 27 additions and 27 deletions.
54 changes: 27 additions & 27 deletions bin/csv_updater
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ require 'slop'
puts "Running csv updater"

options = Slop.parse do |opts|
opts.string '-b', '--bucket', 'Specify the bucket eg. \"gds-ee-raat-test-csv\"'
opts.string '-f', '--file-path', 'Specify the file path eg. \"./my-csv-file.csv\"'
opts.string '-b', '--bucket', 'Specify the bucket eg. \"gds-ee-raat-test-csv\"'
opts.string '-f', '--file-path', 'Specify the file path eg. \"./my-csv-file.csv\"'
end

if options[:bucket].nil? or options[:'file-path'].nil?
puts "Required fields missing:"
puts options
exit(1)
puts "Required fields missing:"
puts options
exit(1)
end

bucket_name = options[:bucket]
Expand All @@ -24,34 +24,34 @@ csv_file_headers = CSV.open(file_path, 'r') { |csv| csv.first }


def validate_csv_format(csv_file_headers)
required_headers = ["Cost Centre Description", "Cost Centre", "Level 04 Parent Descr", "Level 05 Parent Descr"]
is_valid = required_headers.all? { |header| csv_file_headers.include?(header)}
if not is_valid
STDERR.puts "The required headers are not present in the csv file."
else
puts "The file is in valid a format"
end
is_valid
required_headers = ["Cost Centre Description", "Cost Centre", "Level 04 Parent Descr", "Level 05 Parent Descr"]
is_valid = required_headers.all? { |header| csv_file_headers.include?(header)}
if not is_valid
STDERR.puts "The required headers are not present in the csv file."
else
puts "The file is in valid a format"
end
is_valid
end

def upload_to_s3(file, bucket)
s3 = Aws::S3::Client.new
File.open(file, 'rb') do |body|
begin
s3.put_object(
body: body,
bucket: bucket,
key: "cost_centres.csv"
)
puts "Successfully uploaded file"
rescue Aws::S3::Errors::ServiceError => error
STDERR.puts "File not uploaded: #{error.message}"
end
s3 = Aws::S3::Client.new
File.open(file, 'rb') do |body|
begin
s3.put_object(
body: body,
bucket: bucket,
key: "cost_centres.csv"
)
puts "Successfully uploaded file"
rescue Aws::S3::Errors::ServiceError => error
STDERR.puts "File not uploaded: #{error.message}"
end
end
end

if validate_csv_format(csv_file_headers)
upload_to_s3(file_path, bucket_name)
exit 0
upload_to_s3(file_path, bucket_name)
exit 0
end
exit 1

0 comments on commit 7b3fa51

Please sign in to comment.