Skip to content

Commit

Permalink
move logic out of rake task
Browse files Browse the repository at this point in the history
  • Loading branch information
Ches-ctrl committed May 29, 2024
1 parent 66b55d6 commit 073cbba
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 64 deletions.
57 changes: 57 additions & 0 deletions app/services/csv/import_csv.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
module Csv
class ImportCsv
def import_company_urls
company_list = AtsIdentifiers.load

company_csv = 'storage/new/company_urls.csv'

puts Company.count
puts "Creating new companies..."

CSV.foreach(company_csv, headers: true) do |row|
url = row['company_url']
ats, company = Url::CreateCompanyFromUrl.new(url).create_company
company_list[ats.name] << company.ats_identifier if company&.persisted?
end

AtsIdentifiers.save(company_list)
puts Company.count
end

def import_greenhouse_urls
company_list = AtsIdentifiers.load

jobs_csv = 'storage/new/grnhse_job_posting_urls.csv'

puts Job.count
puts "Creating new jobs..."

CSV.foreach(jobs_csv, headers: true) do |row|
url = row['posting_url']
ats, company = Url::CreateJobFromUrl.new(url).create_company_then_job
company_list[ats.name] << company.ats_identifier if company&.persisted?
end

AtsIdentifiers.save(company_list)
puts Job.count
end

def import_job_posting_urls
company_list = AtsIdentifiers.load

jobs_csv = 'storage/new/job_posting_urls.csv'

puts Job.count
puts "Creating new jobs..."

CSV.foreach(jobs_csv, headers: true) do |row|
url = row['posting_url']
ats, company = Url::CreateJobFromUrl.new(url).create_company_then_job
company_list[ats.name] << company.ats_identifier if company&.persisted?
end

AtsIdentifiers.save(company_list)
puts Job.count
end
end
end
71 changes: 7 additions & 64 deletions lib/tasks/import_csv.rake
Original file line number Diff line number Diff line change
Expand Up @@ -4,81 +4,24 @@ namespace :import_csv do
Builders::AtsBuilder.new.build
end

# -----------------------------
# Companies
# -----------------------------
desc "Import CSV - Users"
task users: :environment do
Builders::UserBuilder.new.build
end

desc "Import CSV - company_urls"
task company_urls: :environment do
company_list = AtsIdentifiers.load

company_csv = 'storage/new/company_urls.csv'

puts Company.count
puts "Creating new companies..."

CSV.foreach(company_csv, headers: true) do |row|
url = row['company_url']
ats, company = Url::CreateCompanyFromUrl.new(url).create_company
company_list[ats.name] << company.ats_identifier if company&.persisted?
end

AtsIdentifiers.save(company_list)
puts Company.count
Csv::ImportCompanyUrls.new.import
end

# -----------------------------
# Jobs
# -----------------------------

desc "Import CSV - greenhouse urls"
task greenhouse: :environment do
company_list = AtsIdentifiers.load

jobs_csv = 'storage/new/grnhse_job_posting_urls.csv'

puts Job.count
puts "Creating new jobs..."

CSV.foreach(jobs_csv, headers: true) do |row|
url = row['posting_url']
ats, company = Url::CreateJobFromUrl.new(url).create_company_then_job
company_list[ats.name] << company.ats_identifier if company&.persisted?
end

AtsIdentifiers.save(company_list)
puts Job.count
Csv::ImportGreenhouseUrls.new.import
end

# TODO: Complete this task later (required significant additional functionality so paused for now) - NOT FULLY WORKING YET

desc "Import CSV - job_posting_urls"
task job_posting_urls: :environment do
company_list = AtsIdentifiers.load

jobs_csv = 'storage/new/job_posting_urls.csv'

puts Job.count
puts "Creating new jobs..."

CSV.foreach(jobs_csv, headers: true) do |row|
url = row['posting_url']
ats, company = Url::CreateJobFromUrl.new(url).create_company_then_job
company_list[ats.name] << company.ats_identifier if company&.persisted?
end

AtsIdentifiers.save(company_list)
puts Job.count
end

# -----------------------------
# Users
# -----------------------------

desc "Import CSV - Users"
task users: :environment do
user_csv = 'storage/csv/sample_users.csv'
Builders::UserBuilder.new(user_csv).build
puts User.count
Csv::ImportJobPostingUrls.new.import
end
end

0 comments on commit 073cbba

Please sign in to comment.