Skip to content

Instantly share code, notes, and snippets.

@KakoozaJerry
Last active January 4, 2022 12:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KakoozaJerry/1c0695f2826d60559d54026d8b90e1cb to your computer and use it in GitHub Desktop.
Save KakoozaJerry/1c0695f2826d60559d54026d8b90e1cb to your computer and use it in GitHub Desktop.
to run do >>>>>>>>> rake experiment:export
namespace :experiment do
desc "This task will export Jobs into a csv file"
task export: :environment do
require 'csv'
number_of_rows = Job.last.id - Job.first.id
maximum_db_rows = 4000
if number_of_rows > maximum_db_rows
posts = Job.all
CSV.open('jobs.csv', 'a+') do |csv_object|
posts.each_with_index do |post, i|
if post.id < (Job.first.id+(number_of_rows-maximum_db_rows))
csv_object << [post.id, post.title, post.company, post.location, post.description, post.industry, post.url, post.tags, post.created_at, post.updated_at, post.tech_stack, post.grouping, post.yearsofexperience, post.job_board ]
puts 'Added: ' + post.title + ':' + post.location + ':' + post.description
Job.delete(post.id)
end
end
end
else
puts 'You are still within the ' + maximum_db_rows.to_s + ' maximum number of rows limit.'
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment