Page
-
closed
Toggle commit list -
reopened
Toggle commit list -
-
-
closed
Toggle commit list -
reopened
Toggle commit list -
added 3 commits
Toggle commit list -
Toggle commit list
-
Toggle commit list
-
app/controllers/top_pages_controller.rb 0 → 100644
1 class TopPagesController < ApplicationController 2 def index 3 @total = Job.ids 4 end 5 def show 6 @job = Job.all.order(created_at: :desc) -
@job=>@jobs -
-
-
app/controllers/top_pages_controller.rb 0 → 100644
1 class TopPagesController < ApplicationController 2 def index 3 @total = Job.ids 4 end 5 def show 6 @job = Job.all.order(created_at: :desc) 7 @company = Company.all -
@company=>@companies -
-
-
app/views/top_pages/show.html.erb 0 → 100644
1 <% provide(:title, 'All jobs') %> 2 <% @job.each do |job| %> 3 <% if !job.cities.blank? %> -
if job.cities.present? -
-
-
lib/src/crontab.rb 0 → 100644
1 class Crontab 2 def initialize(logger) 3 @mylogger = logger 4 end 5 6 def find_company 7 company_info = Nokogiri::HTML(URI.open("https://careerbuilder.vn/viec-lam/tat-ca-viec-lam-trang-1-vi.html")) 8 company_link = company_info.css('div.caption a.company-name').map { |link| link['href'] } -
company_links -
-
-
lib/src/crontab.rb 0 → 100644
1 class Crontab 2 def initialize(logger) 3 @mylogger = logger 4 end 5 6 def find_company 7 company_info = Nokogiri::HTML(URI.open("https://careerbuilder.vn/viec-lam/tat-ca-viec-lam-trang-1-vi.html")) 8 company_link = company_info.css('div.caption a.company-name').map { |link| link['href'] } 9 company_link.each do |link| 10 next if link == 'javascript:void(0);' 11 if link != 'https://careerbuilder.vn/vi/nha-tuyen-dung/hr-vietnam\xE2\x80\x99s-ess-client.35A4EFBA.html' 12 company_page = Nokogiri::HTML(URI.open(URI.parse(URI.escape(link)))) 13 unless (company_page.search('p.name').text).nil? -
if company_page.search('p.name').text.present? -
-
-
lib/src/crontab.rb 0 → 100644
22 introduction: introduction_company) 23 end 24 rescue StandardError => e 25 @mylogger.error "#{e.message}" 26 end 27 end 28 end 29 end 30 end 31 def find_job 32 page_access = Nokogiri::HTML(URI.open("https://careerbuilder.vn/viec-lam/tat-ca-viec-lam-vi.html")) 33 get_link = page_access.css('a.job_link').map { |link| link['href'] } 34 get_link.each do |link| 35 page_job = Nokogiri::HTML(URI.open(URI.parse(URI.escape(link)))) 36 get_row = page_job.search('div.bg-blue div.row') 37 if get_row != "" -
if get_row.present? -
-
-
lib/src/crontab.rb 0 → 100644
34 get_link.each do |link| 35 page_job = Nokogiri::HTML(URI.open(URI.parse(URI.escape(link)))) 36 get_row = page_job.search('div.bg-blue div.row') 37 if get_row != "" 38 begin 39 get_name_company = page_job.search('div.job-desc a.job-company-name').text.strip 40 company_table = Company.find_by(name: get_name_company) 41 title_job = page_job.search('div.job-desc p').text 42 description = page_job.search('div.detail-row') 43 next if company_table.nil? 44 job_check = Job.find_by(title: title_job, company_id: company_table.id) 45 salary = get_row.at_xpath('//li[./strong/i[contains(@class, "fa fa-usd")]]/p').text.strip 46 experience = get_row.at_xpath('//li[./strong/i[contains(@class, "fa fa-briefcase")]]/p').text.strip 47 level = get_row.at_xpath('//li[./strong/i[contains(@class, "mdi mdi-account")]]/p').text.strip 48 expiration_date = get_row.at_xpath('//li[./strong/i[contains(@class, "mdi mdi-calendar-check")]]/p').text.strip 49 if job_check.nil? -
if job_check.blank? -
-
-
lib/src/crontab.rb 0 → 100644
45 salary = get_row.at_xpath('//li[./strong/i[contains(@class, "fa fa-usd")]]/p').text.strip 46 experience = get_row.at_xpath('//li[./strong/i[contains(@class, "fa fa-briefcase")]]/p').text.strip 47 level = get_row.at_xpath('//li[./strong/i[contains(@class, "mdi mdi-account")]]/p').text.strip 48 expiration_date = get_row.at_xpath('//li[./strong/i[contains(@class, "mdi mdi-calendar-check")]]/p').text.strip 49 if job_check.nil? 50 job = Job.create!(title: title_job, 51 level: level, 52 salary: salary, 53 experience: experience, 54 expiration_date: expiration_date, 55 description: description, 56 company_id: company_table.id) 57 end 58 find_job = Job.find_by(title: title_job, company_id: company_table.id) 59 puts find_job.title 60 unless find_job.nil? -
if find_job.present? -
-
-
10 15 action.crawl_industry 11 16 action.crawl_company 12 17 action.crawl_job_relationships 13 18 end 14 desc "get file CSV from server" 15 task csv_get: :environment do 19 desc 'Crontab' 20 task auto: :environment do 21 action = Crawler.new(logger) 22 crontab = Crontab.new(logger) 23 crontab.find_company 24 crontab.find_job 16 25 action.get_file_csv 17 action.extract_zip('./jobs.zip','.') 26 action.extract_zip('./jobs.zip', 'lib/csv') 27 action.import_file_csv('lib/csv/jobs.csv') -
Đường dẫn đến file nên sử dụng
Rails.root.joinRails.root.join('lib', 'csv', 'jobs.csv') -
Master
dạ ok a, e fix lại
-
-
-
lib/src/crontab.rb 0 → 100644
57 end 58 find_job = Job.find_by(title: title_job, company_id: company_table.id) 59 puts find_job.title 60 unless find_job.nil? 61 location_rel = get_row.css('div.map p a').children.map { |location| location.text.strip } 62 location_rel.each do |loc| 63 city_table = City.find_by(name: loc) 64 if CityJob.find_by(job_id: find_job.id, city_id: city_table.id).nil? 65 puts "Created City: #{find_job.id} - #{city_table.id}.#{loc}" 66 city_jobs = CityJob.create!(job_id: find_job.id, city_id: city_table.id) 67 end 68 end 69 industry_rel = get_row.css('li a').children.map { |industry| industry.text.strip } 70 industry_rel.each do |ind| 71 industry_table = Industry.find_by(name: ind) 72 if IndustryJob.find_by(job_id: find_job.id, industry_id: industry_table.id).nil? -
unless IndustryJob.exists?(job_id: find_job.id, industry_id: industry_table.id) -
-
-
lib/src/crontab.rb 0 → 100644
56 company_id: company_table.id) 57 end 58 find_job = Job.find_by(title: title_job, company_id: company_table.id) 59 puts find_job.title 60 unless find_job.nil? 61 location_rel = get_row.css('div.map p a').children.map { |location| location.text.strip } 62 location_rel.each do |loc| 63 city_table = City.find_by(name: loc) 64 if CityJob.find_by(job_id: find_job.id, city_id: city_table.id).nil? 65 puts "Created City: #{find_job.id} - #{city_table.id}.#{loc}" 66 city_jobs = CityJob.create!(job_id: find_job.id, city_id: city_table.id) 67 end 68 end 69 industry_rel = get_row.css('li a').children.map { |industry| industry.text.strip } 70 industry_rel.each do |ind| 71 industry_table = Industry.find_by(name: ind) -
Nên kiểm tra nếu giá trị này bị
nil -
-
-
added 2 commits
Toggle commit list -
-
-
-
app/views/layouts/_show_cities.html.erb 0 → 100644
1 <% @jobs_of_cities.each do |city, count_job| %> 2 <% @index += 1 %> 3 <% if @index % 3 == 0 %> -
-
Master
dạ ko a ơi cái này e làm chia cột, cứ tới vị trí cột thứ 3 thì xuống row khác
-
-
-
app/views/layouts/_show_cities.html.erb 0 → 100644
1 <% @jobs_of_cities.each do |city, count_job| %> 2 <% @index += 1 %> -
Sao index lại cần là instance variable ?
Có thể dùng local variable được không ?
-
Master
e dùng local variable k truyền được a nên e dùng instance variable
-
-
-
app/views/layouts/_show_industries.html.erb 0 → 100644
1 <% @jobs_of_industries.each do |industry, count_job| %> 2 <% @index += 1 %> 3 <% if @index % 3 == 0 %> 4 <td class="row-table"> 5 <div class="industry-name"><strong><%= Industry.find(industry).name %></strong></div> 6 <div class="count-job"><%= count_job %></div> 7 </td> 8 </tr> -
-
Master
à e mới mở với đóng lại a ơi, nãy chắc e xóa nhầm @@
-
-
-
-
1 1 class JobsController < ApplicationController 2 2 def index 3 -
-
1 1 class JobsController < ApplicationController 2 2 def index 3 -
Master
dạ ok a
-
-
app/controllers/top_pages_controller.rb 0 → 100644
1 class TopPagesController < ApplicationController 2 def index 3 @total_jobs = Job.all -
app/views/layouts/_show_cities.html.erb 0 → 100644
1 <% @jobs_of_cities.each do |city, count_job| %> -
Master
e xài bootstrap chia cột nên e sửa lại rồi a
-
-
Toggle commit list
-
-
-
Toggle commit list
-
-
-
app/controllers/top_pages_controller.rb 0 → 100644
1 class TopPagesController < ApplicationController 2 def index 3 @total_jobs = Job.ids -
Master
dạ tính total jobs a ơi
-
-
lib/src/crontab.rb 0 → 100644
25 address = page.css('div.content p').children[1]&.text 26 introduction = page.css('div.main-about-us').text 27 begin 28 puts name 29 Company.find_or_create_by!(name: name, 30 address: address, 31 introduction: introduction) 32 rescue StandardError => e 33 @mylogger.error e.message 34 end 35 end 36 end 37 38 def create_city_rel(row, info_job) 39 location_rel = row.css('div.map p a').children.map { |name_city| name_city.text.strip } 40 city_table = City.where(name: location_rel) -
Master
rename city_table => cities
-
-
-
lib/src/crontab.rb 0 → 100644
33 @mylogger.error e.message 34 end 35 end 36 end 37 38 def create_city_rel(row, info_job) 39 location_rel = row.css('div.map p a').children.map { |name_city| name_city.text.strip } 40 city_table = City.where(name: location_rel) 41 42 puts "#{info_job.cities << city_table}" 43 info_job.cities << city_table 44 end 45 46 def create_industry_rel(row, info_job) 47 industry_rel = row.css('li a').children.map { |name_industry| name_industry.text.strip } 48 industry_table = Industry.where(name: industry_rel) -
Master
rename industry => industries
-
-
-
lib/src/crontab.rb 0 → 100644
46 def create_industry_rel(row, info_job) 47 industry_rel = row.css('li a').children.map { |name_industry| name_industry.text.strip } 48 industry_table = Industry.where(name: industry_rel) 49 50 puts "#{info_job.industries << industry_table}" 51 info_job.industries << industry_table 52 end 53 54 def create_job(title, link_page, row, company_table) 55 description = link_page.search('div.detail-row').to_s 56 salary = row.at_xpath('//li[./strong/i[contains(@class, "fa fa-usd")]]/p').text.strip 57 experience = row.at_xpath('//li[./strong/i[contains(@class, "fa fa-briefcase")]]/p')&.text&.strip 58 level = row.at_xpath('//li[./strong/i[contains(@class, "mdi mdi-account")]]/p').text.strip 59 expiration_date = row.at_xpath('//li[./strong/i[contains(@class, "mdi mdi-calendar-check")]]/p').text.strip 60 61 info_job = Job.find_or_create_by!(title: title, -
Master
infor_job => job company_table => company
-
-
-
23 24 def url 25 'https://careerbuilder.vn/viec-lam/tat-ca-viec-lam-trang-1-vi.html' -
Toggle commit list
-
-
app/controllers/top_pages_controller.rb 0 → 100644
1 class TopPagesController < ApplicationController 2 def index 3 @cities = City.all 4 @industries = Industry.all 5 @total_jobs = Job.count 6 @jobs = Job.limit(5).order(created_at: :desc) 7 @jobs_of_cities = CityJob.top_city 8 @jobs_of_industries = IndustryJob.limit(9).group('industry_id').order('Count(*) DESC').count -
lib/src/crontab.rb 0 → 100644
13 find_job 14 end 15 16 def find_company 17 info = Nokogiri::HTML(URI.open(@url)) 18 links = info.css('div.caption a.company-name').map { |link| link['href'] } 19 links.each do |link| 20 next if link == 'javascript:void(0);' 21 page = Nokogiri::HTML(URI.open(URI.escape(link))) 22 name = page.search('p.name')&.text 23 return if name.blank? 24 25 address = page.css('div.content p').children[1]&.text 26 introduction = page.css('div.main-about-us').text 27 begin 28 puts name -
lib/src/crontab.rb 0 → 100644
24 25 address = page.css('div.content p').children[1]&.text 26 introduction = page.css('div.main-about-us').text 27 begin 28 puts name 29 Company.find_or_create_by!(name: name, 30 address: address, 31 introduction: introduction) 32 rescue StandardError => e 33 @mylogger.error e.message 34 end 35 end 36 end 37 38 def create_city_rel(row, info_job) 39 location_rel = row.css('div.map p a').children.map { |name_city| name_city.text.strip } -
app/views/layouts/_show_cities.html.erb 0 → 100644
1 <% @jobs_of_cities.each do |city, count_job| %> 2 <div class="col-4"> 3 <div class="row-table border border-dark rounded city-list"> 4 <%= link_to '#' do%> 5 <div class="city-name"><strong><%= City.find(city).name %></strong></div> -
Master
h e mới đang fix trong controller a ơi, e đang tìm cách.
-
-
lib/src/csvimporter.rb 0 → 100644
1 require 'net/ftp' 2 require 'csv' 3 require 'zip' 4 5 class CSVimporter 6 def initialize(logger) 7 @logger = logger 8 @NAME_DOMAIN = '192.168.1.156' -
Master
dạ đúng rồi a
-
MasterEdited by Van Hau Le
@phuocht https://www.rubyguides.com/2017/07/ruby-constants/
NAME_DOMAIN = '192.168.1.156'.freeze USERNAME_FTP = 'training'.freeze PASSWORD_FTP = 'training'.freezeVầy là đủ nha em! Lưu ý declare 1 constant là kiểu string thì freeze nó!
-
-
15 task csv_get: :environment do 16 action.get_file_csv 17 action.extract_zip('./jobs.zip','.') 11 desc 'Crontab' 12 task auto: :environment do 13 crontab = JobParser.new(logger, url) 14 csvimporter = CSVimporter.new(logger) 15 crontab.crawl_all 16 csvimporter.import 18 17 end 19 desc "Import data from CSV" 20 task data_csv: :environment do 21 action.import_file_csv 18 19 def logger 20 Logger.new(Rails.root.join('log','my.log')) -
8 7 task crawler: :environment do 9 action.crawl_city 10 action.crawl_industry 11 action.crawl_company 12 action.crawl_job_relationships 8 action = Crawler.new(logger, url) 9 action.crawl_city_industry 13 10 end 14 desc "get file CSV from server" 15 task csv_get: :environment do 16 action.get_file_csv 17 action.extract_zip('./jobs.zip','.') 11 desc 'Crontab' 12 task auto: :environment do 13 crontab = JobParser.new(logger, url) 14 csvimporter = CSVimporter.new(logger) -
Master
-
-
-
10 action.crawl_industry 11 action.crawl_company 12 action.crawl_job_relationships 8 action = Crawler.new(logger, url) 9 action.crawl_city_industry 13 10 end 14 desc "get file CSV from server" 15 task csv_get: :environment do 16 action.get_file_csv 17 action.extract_zip('./jobs.zip','.') 11 desc 'Crontab' 12 task auto: :environment do 13 crontab = JobParser.new(logger, url) 14 csvimporter = CSVimporter.new(logger) 15 crontab.crawl_all 16 csvimporter.import -
3 require 'csv' 4 require 'zip' 5 action = Crawler.new 2 require 'src/jobparser.rb' 3 require 'src/csvimporter.rb' 4 6 5 namespace :import do 7 desc "crawler data" 6 desc 'crawler data' 8 7 task crawler: :environment do 9 action.crawl_city 10 action.crawl_industry 11 action.crawl_company 12 action.crawl_job_relationships 8 action = Crawler.new(logger, url) 9 action.crawl_city_industry -
Master
action = Crawler.new(logger, url) action.crawl_city_industryNếu chỉ call 1 action, không lấy kết qủa trả về, ko xử lý tiếp theo =>
Crawler.new(logger, url).crawl_city_industry -
Master
dạ ok a để e sửa lại
-
-
-
app/views/layouts/_search_bar.html.erb 0 → 100644
1 <div class="search-bar"> 2 <div class="row"> 3 <div class="col-sm"> 4 <input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search"> 5 </div> 6 <div class="col-sm"> 7 <select class="form-control" id="exampleFormControlSelect1"> 8 <%= @cities.each do |city| %> 9 <option><%= city.name %></option> -
Toggle commit list
-
-
-
-
-
Toggle commit list
-
Toggle commit list
-
lib/src/csv_importer.rb 0 → 100644
1 require 'net/ftp' 2 require 'csv' 3 require 'zip' 4 5 class CSVImporter 6 def initialize(logger) 7 @logger = logger 8 NAME_DOMAIN = '192.168.1.156'.freeze 9 USERNAME_FTP = 'training'.freeze -
Master
dạ ok a để e đổi lại
-
-
Toggle commit list
-
lib/src/job_parser.rb 0 → 100644
3 def initialize(logger, url) 4 @logger = logger 5 @url = url 6 end 7 8 def crawl_all 9 find_company 10 find_job 11 end 12 13 def find_company 14 info = Nokogiri::HTML(URI.open(@url)) 15 links = info.css('div.caption a.company-name').map { |link| link['href'] } 16 links.each do |link| 17 next if link == 'javascript:void(0);' 18 page = Nokogiri::HTML(URI.open(URI.escape(link))) -
-
-
merged
Toggle commit list