Commit a765decd by Mai Hoang Thai Ha

fixed review

parent 9e051c4d
class City < ApplicationRecord class City < ApplicationRecord
has_and_belongs_to_many :jobs has_and_belongs_to_many :jobs
enum region: { vietnam: 0, international: 1 }
end end
...@@ -79,17 +79,11 @@ namespace :crawler do ...@@ -79,17 +79,11 @@ namespace :crawler do
benefit: benefits, benefit: benefits,
requirement: requirement, requirement: requirement,
other_info: other_info, other_info: other_info,
company_id: company_object.id, company_id: company_object.id })
created_at: update_at, industry_objects = industries.map { |industry| Industry.find_or_create_by(name: industry) }
updated_at: update_at }) job_object.industries << industry_objects
industries.map do |industry| city_objects = cities.map { |city| City.find_or_create_by(name: city) }
industry_objects = Industry.find_or_create_by(name: industry) job_object.cities << city_objects
job_object.industries << industry_objects
end
cities.map do |city|
city_objects = City.find_or_create_by(name: city)
job_object.cities << city_objects
end
rescue URI::InvalidURIError => e rescue URI::InvalidURIError => e
puts "[Error] #{e.message}" puts "[Error] #{e.message}"
encode_url = CGI.escape(url.remove('https://careerbuilder.vn/vi/tim-viec-lam/')) encode_url = CGI.escape(url.remove('https://careerbuilder.vn/vi/tim-viec-lam/'))
...@@ -116,20 +110,16 @@ namespace :crawler do ...@@ -116,20 +110,16 @@ namespace :crawler do
task cities: :environment do task cities: :environment do
parsed_page ||= Nokogiri::HTML(HTTParty.get('https://careerbuilder.vn/tim-viec-lam.html').body) parsed_page ||= Nokogiri::HTML(HTTParty.get('https://careerbuilder.vn/tim-viec-lam.html').body)
list_location = parsed_page.css('div.main-jobs-by-location ul li') list_location = parsed_page.css('div.main-jobs-by-location ul li')
list_location.each do |part| list_location.each do |city|
city_name = part.text city_name = city.text
region = 1 region = City.regions[:international]
if city_name.include?(key = 'Việc làm tại') if city_name.include?('Việc làm tại')
city_name = city_name.remove(key).strip city_name = city_name.remove('Việc làm tại').strip
region = 0 region = City.regions[:vietnam]
end end
city = { City.create(
name: city_name, name: city_name,
region: region region: region
}
City.create(
name: city[:name],
region: city[:region]
) )
end end
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