Append condition in crawl City

parent cdfa6137
Pipeline #864 failed with stages
in 0 seconds
class Crawler class Crawler
VIETNAM = 0
FOREIGN = 1
def initialize(logger, url) def initialize(logger, url)
@logger = logger @logger = logger
@url = url @url = url
...@@ -20,11 +22,13 @@ class Crawler ...@@ -20,11 +22,13 @@ class Crawler
data_city.each do |name_city| data_city.each do |name_city|
if City.find_by(id: 70) if City.find_by(id: 70)
city = City.create!(name: name_city, city = City.find_or_create_by!(name: name_city) do
location: 0) city.update!(location: VIETNAM)
end
else else
city = City.create!(name: name_city, city = City.find_or_create_by!(name: name_city) do
location: 1) city.update!(location: FOREIGN)
end
end end
end end
end end
...@@ -35,7 +39,7 @@ class Crawler ...@@ -35,7 +39,7 @@ class Crawler
data_industry = get_name.search('option').map { |p| p.text.strip } data_industry = get_name.search('option').map { |p| p.text.strip }
data_industry.each do |name_industry| data_industry.each do |name_industry|
industry = Industry.create!(name: name_industry) industry = Industry.find_or_create_by!(name: name_industry)
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