Commit 3254574e by Ngô Trung Hưng

fix bug

parent 658c19e7
...@@ -47,12 +47,11 @@ class Clawler ...@@ -47,12 +47,11 @@ class Clawler
address: "Vui lòng xem trong mô tả công việc", address: "Vui lòng xem trong mô tả công việc",
short_description: "Vui lòng xem trong mô tả công việc") short_description: "Vui lòng xem trong mô tả công việc")
@data = Interface_web.craw_data_companies() @data = Interface_web.craw_data_companies()
puts 'Save info companies to database . . .'
i = @data[:name].length i = @data[:name].length
i.times do |n| i.times do |n|
name = @data[:name][n] name = @data[:name][n]
if Company.find_by("name = ?", name) unless Company.find_by(name: name).present?
next
else
address = @data[:address][n] address = @data[:address][n]
short_description = @data[:description][n] short_description = @data[:description][n]
Company.create!(name: name, Company.create!(name: name,
...@@ -65,6 +64,7 @@ class Clawler ...@@ -65,6 +64,7 @@ class Clawler
def self.make_jobs def self.make_jobs
Job.update_all(newdata: 0) Job.update_all(newdata: 0)
@data_jobs = Interface_web.make_data() @data_jobs = Interface_web.make_data()
puts 'Save to database . . .'
i = @data_jobs[:name].length i = @data_jobs[:name].length
i.times do |n| i.times do |n|
name = @data_jobs[:name][n].to_s name = @data_jobs[:name][n].to_s
......
...@@ -36,7 +36,8 @@ class Interface_web ...@@ -36,7 +36,8 @@ class Interface_web
@data_companies_name = [] @data_companies_name = []
@data_companies_address = [] @data_companies_address = []
@data_companies_description = [] @data_companies_description = []
puts 'Crawl data companies'
@current_company = 0
link_crawl[0].each do |url| link_crawl[0].each do |url|
page = base_link(url) page = base_link(url)
name = '' name = ''
...@@ -56,7 +57,9 @@ class Interface_web ...@@ -56,7 +57,9 @@ class Interface_web
@data_companies_name << name.to_s.rstrip @data_companies_name << name.to_s.rstrip
@data_companies_address << address.to_s.rstrip @data_companies_address << address.to_s.rstrip
@data_companies_description << desc @data_companies_description << desc
@current_company += 1
end end
puts "Crawling #{@current_company}"
end end
@data_companies[:name] = @data_companies_name @data_companies[:name] = @data_companies_name
@data_companies[:address] = @data_companies_address @data_companies[:address] = @data_companies_address
......
...@@ -4,6 +4,6 @@ namespace :db do ...@@ -4,6 +4,6 @@ namespace :db do
# Clawler.make_industries # Clawler.make_industries
# Clawler.make_cities # Clawler.make_cities
Clawler.make_companies Clawler.make_companies
Clawler.make_jobs # Clawler.make_jobs
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