Commit eeedca0f by thanhnd

delete files and modify rake

parent 09796600
class AppliedJob < ApplicationRecord class AppliedJob < ApplicationRecord
belongs_to :job belongs_to :job
belongs_to :user belongs_to :user
#add_index :applied_jobs, :applied_job_id, unique: true
end end
class City < ApplicationRecord class City < ApplicationRecord
belongs_to :area belongs_to :area
has_many :jobs has_many :jobs
#add_index :cities, [:area_id, :city_id], unique: true validates_presence_of :city_name
validates_presence_of :city_name
end end
class Company < ApplicationRecord class Company < ApplicationRecord
has_many :jobs has_many :jobs
#add_index :companies, [:company_id, :email], unique: true
validates_presence_of :company_name validates_presence_of :company_name
end end
class Industry < ApplicationRecord class Industry < ApplicationRecord
has_many :industry_jobs has_many :industry_jobs
#add_index :industries, :industries_id, unique: true validates_presence_of :industry_name
validates_presence_of :industry_name
end end
class IndustryJob < ApplicationRecord class IndustryJob < ApplicationRecord
belongs_to :industry belongs_to :industry
has_many :jobs has_many :jobs
#add_index :industry_jobs, :industry_job_id, unique: true
end end
...@@ -6,7 +6,5 @@ class Job < ApplicationRecord ...@@ -6,7 +6,5 @@ class Job < ApplicationRecord
belongs_to :area belongs_to :area
belongs_to :city belongs_to :city
belongs_to :company belongs_to :company
#add_index :jobs, [:job_id, :area_id, :city_id, :industry_id, :company_id, :code], unique: true
#validates_presence_of :code
validates_presence_of :job_name validates_presence_of :job_name
end end
class SavedJob < ApplicationRecord class SavedJob < ApplicationRecord
belongs_to :job belongs_to :job
belongs_to :user belongs_to :user
#add_index :saved_jobs, :saved_job_id, unique: true
end end
class User < ApplicationRecord class User < ApplicationRecord
has_many :applied_jobs has_many :applied_jobs
has_and_belongs_to_many :jobs has_and_belongs_to_many :jobs
#add_index :companies, [:user_id, :email], unique: true
validates_presence_of :fname validates_presence_of :fname
validates_presence_of :lname validates_presence_of :lname
end end
...@@ -6,6 +6,6 @@ class CreateCities < ActiveRecord::Migration[6.0] ...@@ -6,6 +6,6 @@ class CreateCities < ActiveRecord::Migration[6.0]
t.column :city_description, :string t.column :city_description, :string
t.timestamps t.timestamps
end end
add_index :cities, [:area_id, :id], unique: true add_index :cities, [:area_id, :id], unique: true
end end
end end
...@@ -9,13 +9,11 @@ class CreateJobs < ActiveRecord::Migration[6.0] ...@@ -9,13 +9,11 @@ class CreateJobs < ActiveRecord::Migration[6.0]
t.column :job_name, :text, :null => false t.column :job_name, :text, :null => false
t.column :salary, :string t.column :salary, :string
t.column :deadline, :Date t.column :deadline, :Date
#t.column :position, :string
t.column :level, :string t.column :level, :string
t.column :experience, :string t.column :experience, :string
t.column :last_updated, :Date t.column :last_updated, :Date
t.column :description, :text t.column :description, :text
t.timestamps t.timestamps
end end
#add_index :jobs, [:id, :area_id, :city_id, :industry_id, :company_id, :code], unique: true
end end
end end
...@@ -14,8 +14,5 @@ class CreateUsers < ActiveRecord::Migration[6.0] ...@@ -14,8 +14,5 @@ class CreateUsers < ActiveRecord::Migration[6.0]
t.column :password_digest, :string t.column :password_digest, :string
t.timestamps t.timestamps
end end
#add_index :companies, [:id, :email], unique: true
#remove_index :companies, [:id, :email], unique: true
end end
end end
...@@ -2,37 +2,15 @@ require 'addressable/uri' ...@@ -2,37 +2,15 @@ require 'addressable/uri'
require 'uri' require 'uri'
namespace :crawler do namespace :crawler do
desc "TODO"
task run: :environment do
end
task crawl: :environment do task crawl: :environment do
#insert_data_area insert_data_area
crawl_data crawl_data
end end
def crawl_data def crawl_data
data_dir ="/opt/careerbuilder"
Dir.mkdir(data_dir) unless File.exists?(data_dir)
base_careerbuilder_url = "https://careerbuilder.vn" base_careerbuilder_url = "https://careerbuilder.vn"
list_url = "#{base_careerbuilder_url}/viec-lam/tat-ca-viec-lam-vi.html" list_url = "#{base_careerbuilder_url}/viec-lam/tat-ca-viec-lam-vi.html"
#HEADERS_HASH = {"User-Agent" => "Ruby/#{RUBY_VERSION}"}
#page = Nokogiri::HTML(open(list_url))
#get all links in one page
#links = page.css('html body.jobseeker_site.A-Bootstrap div#uni_wrapper div#uni_container div.cb-container div.col-sm-12.col-md-9.col-ListJobCate div.gird_standard dl dd.brief span.jobtitle h3.job a')
#print all links:
#links.each{|link| puts "#{link['href']}\n"}
#get link for next page
#np = Nokogiri::HTML(open(list_url))
#nextpage = np.css('html body.jobseeker_site.A-Bootstrap div#uni_wrapper div#uni_container div.cb-container div.col-sm-12.col-md-9.col-ListJobCate div.paginationTwoStatus a.right')
#list_url = nextpage[0]["href"]
while list_url.to_s.length > 0 while list_url.to_s.length > 0
page = Nokogiri::HTML(open(list_url)) page = Nokogiri::HTML(open(list_url))
...@@ -47,10 +25,6 @@ namespace :crawler do ...@@ -47,10 +25,6 @@ namespace :crawler do
area = Area.find(1) area = Area.find(1)
links.each do |link| links.each do |link|
#convert utf-8 to ascii character if has
#url = "https://careerbuilder.vn/vi/tim-viec-lam/hr-executive-%E2%80%93-field-sales.35B39958.html"
#uri = Addressable::URI.parse(url)
url = "#{link['href']}" url = "#{link['href']}"
url.force_encoding('ASCII-8BIT') url.force_encoding('ASCII-8BIT')
uri = URI::encode(url) uri = URI::encode(url)
...@@ -77,7 +51,7 @@ namespace :crawler do ...@@ -77,7 +51,7 @@ namespace :crawler do
#insert data to City table: #insert data to City table:
City.find_or_create_by(area_id: area.id, city_name: "#{location.text.gsub!(",", "")}", city_description: "") City.create(area_id: area.id, city_name: "#{location.text.gsub!(",", "")}", city_description: "")
#insert data to Industry table #insert data to Industry table
Industry.find_or_create_by(industry_name: "#{industry.text}", industry_description: "") Industry.find_or_create_by(industry_name: "#{industry.text}", industry_description: "")
...@@ -99,7 +73,7 @@ end ...@@ -99,7 +73,7 @@ end
def insert_data_area def insert_data_area
Area.find_or_create_by(area_name: "Viet Nam", area_description: "VN") Area.find_or_create_by(area_name: "Viet Nam", area_description: "VN")
Area.find_or_create_by(area_name: "Nuoc Ngoai", area_description: "NN") Area.find_or_create_by(area_name: "Nuoc Ngoai", area_description: "NN")
end end
end end
require "test_helper"
class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
driven_by :selenium, using: :chrome, screen_size: [1400, 1400]
end
require "test_helper"
class ApplicationCable::ConnectionTest < ActionCable::Connection::TestCase
# test "connects with cookies" do
# cookies.signed[:user_id] = 42
#
# connect
#
# assert_equal connection.user_id, "42"
# end
end
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
# This model initially had no columns defined. If you add columns to the
# model remove the '{}' from the fixture names and add the columns immediately
# below each fixture, per the syntax in the comments below
#
one: {}
# column: value
#
two: {}
# column: value
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
# This model initially had no columns defined. If you add columns to the
# model remove the '{}' from the fixture names and add the columns immediately
# below each fixture, per the syntax in the comments below
#
one: {}
# column: value
#
two: {}
# column: value
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
# This model initially had no columns defined. If you add columns to the
# model remove the '{}' from the fixture names and add the columns immediately
# below each fixture, per the syntax in the comments below
#
one: {}
# column: value
#
two: {}
# column: value
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
# This model initially had no columns defined. If you add columns to the
# model remove the '{}' from the fixture names and add the columns immediately
# below each fixture, per the syntax in the comments below
#
one: {}
# column: value
#
two: {}
# column: value
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
# This model initially had no columns defined. If you add columns to the
# model remove the '{}' from the fixture names and add the columns immediately
# below each fixture, per the syntax in the comments below
#
one: {}
# column: value
#
two: {}
# column: value
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
# This model initially had no columns defined. If you add columns to the
# model remove the '{}' from the fixture names and add the columns immediately
# below each fixture, per the syntax in the comments below
#
one: {}
# column: value
#
two: {}
# column: value
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
# This model initially had no columns defined. If you add columns to the
# model remove the '{}' from the fixture names and add the columns immediately
# below each fixture, per the syntax in the comments below
#
one: {}
# column: value
#
two: {}
# column: value
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
# This model initially had no columns defined. If you add columns to the
# model remove the '{}' from the fixture names and add the columns immediately
# below each fixture, per the syntax in the comments below
#
one: {}
# column: value
#
two: {}
# column: value
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
# This model initially had no columns defined. If you add columns to the
# model remove the '{}' from the fixture names and add the columns immediately
# below each fixture, per the syntax in the comments below
#
one: {}
# column: value
#
two: {}
# column: value
require 'test_helper'
class AppliedJobTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
require 'test_helper'
class AreaTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
require 'test_helper'
class CityTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
require 'test_helper'
class CompanyTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
require 'test_helper'
class IndustryJobTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
require 'test_helper'
class IndustryTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
require 'test_helper'
class JobTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
require 'test_helper'
class SavedJobTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
require 'test_helper'
class UserTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
ENV['RAILS_ENV'] ||= 'test'
require_relative '../config/environment'
require 'rails/test_help'
class ActiveSupport::TestCase
# Run tests in parallel with specified workers
parallelize(workers: :number_of_processors)
# Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
fixtures :all
# Add more helper methods to be used by all tests here...
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