Commit 9604a13f by Thanh Hung Pham

Check data exits to update

parent 5646d137
......@@ -82,12 +82,15 @@ class Careerbuilder
def detail(doc, _link)
# Company Information
company = Company.new
company_name = doc.xpath("//div[@class='tit_company']").text.strip # Company name
company_address = doc.xpath("//div[@class='box1Detail']/p[@class='TitleDetailNew']/label[@itemprop='address']/label[@itemprop='addressLocality']").text.strip # Company Address
company_description = doc.xpath("//div[@class='desc_company content_fck']").text.strip # Company description
company = Company.find_or_create_by(name: company_name)
company.name = company_name
company.address = doc.xpath("//div[@class='box1Detail']/p[@class='TitleDetailNew']/label[@itemprop='address']/label[@itemprop='addressLocality']").text.strip # Company Address
company.description = doc.xpath("//div[@class='desc_company content_fck']").text.strip # Company description
company.save if Company.where(name: company_name).blank?
company.address = company_address
company.description = company_description
company.save
# Job Information
job_name = doc.xpath("//div[@class='LeftJobCB']/div[@class='top-job']/div[@class='top-job-info']/h1").text.strip # Job name
......@@ -108,21 +111,18 @@ class Careerbuilder
city = City.find_by_name(job_location)
job = Job.new
job.name = job_name
job = Job.find_or_create_by(name: job_name, city: city, company: company)
job.description = job_description
job.salary = job_salary
job.city = city
job.company = company
job.level = job_level
job.experience = job_experience
job.status = 0
job.expiry_date = job_expiry_date.to_datetime
job.save if Job.where(name: job_name, city: city, company: company).blank?
job.save
job_category.split(',').each do |category|
category = Category.find_by_name(category)
JobCategory.new(job: job, category: category).save if JobCategory.where(job: job, category: category).blank?
JobCategory.find_or_create_by(job: job, category: category)
end
end
......@@ -130,7 +130,7 @@ class Careerbuilder
categories = doc.xpath("//div[@class='s-home2']/div[@id='NewSearchJob3']/form/div[@class='search-horizontal']/div[@class='ui-widget box_multiSelect_industry']/select/option")
categories = categories.drop(1)
categories.each do |category|
Category.new(name: category.text.strip).save if Category.where(name: category.text.strip).blank?
Category.find_or_create_by(name: category.text.strip)
end
rescue StandardError => e
logger.error("[method: ] #{import_category}")
......@@ -143,7 +143,7 @@ class Careerbuilder
area = Area.find_by_name('Viet Nam')
cities.each do |city|
area = Area.find_by_name('International') if city.text == 'Angola'
City.new(name: city.text.strip, area: area).save if City.where(name: city.text.strip).blank?
City.find_or_create_by(name: city.text.strip, area: area)
end
rescue StandardError => e
logger.error("[method: ] #{import_city}")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment