Commit cdd2eeb9 by Mai Hoang Thai Ha

fixed review part 2

parent a765decd
......@@ -50,38 +50,39 @@ namespace :crawler do
end
# benefits, description, requirement, other_info
job_detail_rows = job_page.css('section.job-detail-content div.detail-row')
benefits, description, requirement, other_info = []
benefits, description, requirement, other_info = ''
job_detail_rows.each do |detail_row|
detail_title = detail_row.css('.detail-title').text.strip
detail_content = detail_row.css(':not(h3.detail-title)')
case detail_title
when 'Phúc lợi'
benefits = detail_row.css(':not(h3.detail-title)').map(&:text).map(&:squish)[1..-1].reject(&:blank?).join('---')
benefits = get_detail_text(detail_content)
when 'Mô tả Công việc'
description = detail_row.css(':not(h3.detail-title)').map(&:text).map(&:squish)[1..-1].reject(&:blank?).join('---')
description = get_detail_text(detail_content)
when 'Yêu Cầu Công Việc'
requirement = detail_row.css(':not(h3.detail-title)').map(&:text).map(&:squish)[1..-1].reject(&:blank?).join('---')
requirement = get_detail_text(detail_content)
when 'Thông tin khác'
other_info = detail_row.css(':not(h3.detail-title)').map(&:text).map(&:squish)[1..-1].reject(&:blank?).join('---')
other_info = get_detail_text(detail_content)
end
end
# Company
company_name = job_page.css('div.job-desc a.job-company-name').text
# Cities
cities = job_page.css('.job-detail-content .detail-box .map p a').map(&:text)
company_object = Company.find_or_create_by(name: company_name)
job_object = Job.create({ title: job_title,
job_type: job_type,
salary: salary,
experience: experience,
position: level,
expiration_date: expiration_date,
description: description,
benefit: benefits,
requirement: requirement,
other_info: other_info,
company_id: company_object.id })
job_object = Job.find_or_create_by({ title: job_title,
job_type: job_type,
salary: salary,
experience: experience,
position: level,
expiration_date: expiration_date,
description: description,
benefit: benefits,
requirement: requirement,
other_info: other_info,
company_id: company_object.id })
industry_objects = industries.map { |industry| Industry.find_or_create_by(name: industry) }
job_object.industries << industry_objects
# Cities
cities = job_page.css('.job-detail-content .detail-box .map p a').map(&:text)
city_objects = cities.map { |city| City.find_or_create_by(name: city) }
job_object.cities << city_objects
rescue URI::InvalidURIError => e
......@@ -112,15 +113,19 @@ namespace :crawler do
list_location = parsed_page.css('div.main-jobs-by-location ul li')
list_location.each do |city|
city_name = city.text
region = City.regions[:international]
region = :international
if city_name.include?('Việc làm tại')
city_name = city_name.remove('Việc làm tại').strip
region = City.regions[:vietnam]
region = :vietnam
end
City.create(
City.find_or_create_by(
name: city_name,
region: region
)
end
end
def get_detail_text(arr)
arr.map(&:text).map(&:squish)[1..-1].reject(&:blank?).join('---')
end
end
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