def call(input_file:, **)
MavisCLI.load_rails
File.open(input_file) do |file|
rows =
CSV.parse(file.read, headers: false, encoding: "ISO-8859-1:UTF-8")
batch_size = 1000
locations = []
progress_bar =
ProgressBar.create(
total: rows.length + 1,
format: "%a %b\u{15E7}%i %p%% %t",
progress_mark: " ",
remainder_mark: "\u{FF65}"
)
rows.each do |row|
ods_code = row[0]
name = row[1]
address_line_1 = row[3]
address_line_2 = row[4]
address_town = row[5]
address_postcode = row[9]
locations << Location.new(
type: :gp_practice,
ods_code:,
name:,
address_line_1:,
address_line_2:,
address_town:,
address_postcode:
)
if locations.size >= batch_size
import_gp_practices(locations)
locations.clear
end
progress_bar.increment
end
import_gp_practices(locations) unless locations.empty?
end
end