Commit 2cc5b542 by Hoang Nam Nguyen

finish "top_page"

parent 99d75d8a
......@@ -5,9 +5,12 @@ git_source(:github) do |repo_name|
"https://github.com/#{repo_name}.git"
end
gem 'will_paginate', '3.1.5'
gem 'bootstrap-will_paginate', '1.0.0'
gem 'rubyzip', '>= 1.0.0' # will load new rubyzip version
gem 'zip-zip' # will load compatibility for old rubyzip API.
gem 'nokogiri'
gem 'whenever', :require => false
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.1.3'
# Use mysql as the database for Active Record
......
......@@ -42,6 +42,8 @@ GEM
public_suffix (>= 2.0.2, < 4.0)
arel (8.0.0)
bindex (0.5.0)
bootstrap-will_paginate (1.0.0)
will_paginate
builder (3.2.3)
byebug (9.1.0)
capybara (2.15.1)
......@@ -53,6 +55,7 @@ GEM
xpath (~> 2.0)
childprocess (0.7.1)
ffi (~> 1.0, >= 1.0.11)
chronic (0.10.2)
coderay (1.1.1)
coffee-rails (4.2.2)
coffee-script (>= 2.2.0)
......@@ -177,6 +180,9 @@ GEM
websocket-driver (0.6.5)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.2)
whenever (0.9.7)
chronic (>= 0.6.3)
will_paginate (3.1.5)
xpath (2.1.0)
nokogiri (~> 1.3)
zip-zip (0.3)
......@@ -186,6 +192,7 @@ PLATFORMS
ruby
DEPENDENCIES
bootstrap-will_paginate (= 1.0.0)
byebug
capybara (~> 2.13)
coffee-rails (~> 4.2)
......@@ -206,6 +213,8 @@ DEPENDENCIES
tzinfo-data
uglifier (>= 1.3.0)
web-console (>= 3.3.0)
whenever
will_paginate (= 3.1.5)
zip-zip
BUNDLED WITH
......
......@@ -12,4 +12,5 @@
//
//= require rails-ujs
//= require turbolinks
//= require jquery-3.2.1.min
//= require_tree .
This source diff could not be displayed because it is too large. You can view the blob instead.
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
This source diff could not be displayed because it is too large. You can view the blob instead.
/* header */
#logo {
width: 230px;
height: 120px;
}
#distance {
border-width: 3px;
margin-top: 5px;
width: 120px;
border-radius: 25px;
}
#slidebar {
padding-right: 100px;
}
#slide {
padding-left: 600px;
}
.container-fluid {
background-color: white;
}
/* content */
input[type=text] {
width: 130px;
-webkit-transition: width 0.4s ease-in-out;
transition: width 0.4s ease-in-out;
}
input[type=text]:focus {
width: 100%;
}
#image_height {
padding-left: 5px;
width: 1835px;
height: 430px;
}
#fontwords {
margin-top: 30px;
padding-left: 341px;
}
#search_button {
margin-top: 30px;
margin-left: 50px;
}
#search_box {
width: 1000px;
margin-top: 30px;
}
.line_job {
margin-left: -190px;
margin-top: 30px;
font-size: 35px;
}
.jobs {
margin-top: 20px;
width: 10000px;
margin-left: 11px;
}
.detail_description {
font-size: 13px;
}
.cities {
margin-top: 10px;
margin-left: 10px;
width: 1126px;
border: 1px solid rgba(0, 0, 0, 0.125);
}
.titlejob{
width: 1116px;
margin-left: -2px;
height: 550px;
}
.total_jobs {
margin-top: -10px;
margin-bottom: 5px;
font-size: 14px;
}
.column_set {
text-align: center;
}
#cities_button {
margin-left: 955px;
margin-bottom: 37px;
margin-top: 30px;
}
\ No newline at end of file
// Place all the styles related to the TopPages controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
def hello
render html: "hello, world"
end
end
class TopPagesController < ApplicationController
def cities
end
def industries
end
def toppage
@jobs = Job.limit(5)
@cities = City.limit(9)
@total_job = Job.count
@industries = Industry.limit(9)
end
def show
@job = Job.find(params[:id])
@city = City.find(params)
end
def index
end
end
module TopPagesHelper
end
class City < ApplicationRecord
has_many :job_cities
has_many :jobs, through: :job_cities
end
class Job < ApplicationRecord
has_many :job_cities
has_many :cities, through: :job_cities
end
class JobCity < ApplicationRecord
belongs_to :job
belongs_to :city
end
<footer class="blockquote-footer">
<nav>
ZiGExN VeNtura 2017
</nav>
\ No newline at end of file
<nav class="navbar navbar-light bg-faded">
<div class="container-fluid">
<div class="navbar-header">
<img src="http://news.zigexn.co.jp/wp-content/uploads/img_pgpfb.png" class="navbar-brand" id="logo" href="zigexn.vn">
</div>
<ul class="nav navbar-nav" id="slide">
<li><button type="button" class="btn btn-info" id="distance">Login</button></li>
<li><button type="button" class="btn btn-info" id="distance">Favorite</button></li>
</ul>
<ul class="nav navbar-nav navbar-right" id="slidebar">
<li><button type="button" class="btn btn-info" id="distance">Register</button></li>
<li><button type="button" class="btn btn-info" id="distance">History</button></li>
</ul>
</div>
</nav>
<!DOCTYPE html>
<html>
<head>
<title>VenJob</title>
<title>Top page</title>
<%= csrf_meta_tags %>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
</head>
<body>
<%= render 'layouts/header' %>
<img src="https://images.careerbuilder.vn/background/chubb_1440x430_2017_08_25_orange_1503979439.jpg" id="image_height">
<div class="container">
<%= yield %>
<%= render 'layouts/footer' %>
</div>
</body>
</html>
<% @cities.each do |city| %>
<div class="col-md-4 column_set">
<a href="#" class="titlejob">
<p>
<%= city.location %>
</p>
</a>
<li class="total_jobs">
<%= city.jobs.count %> Jobs
</li>
</div>
<% end %>
<div>
<button type="button" class="btn btn-success" id="cities_button">All Cities</button>
</div>
\ No newline at end of file
<div class="jobs list-group-item">
<% @jobs.each do |job| %>
<a href="#">
<p>
<%= job.job_title %>
</p>
</a>
<li class="detail_description"> <%= truncate job.short_description,length: 160 %>
<%= link_to 'read more', '#' %> </li>
<li class="detail_description"> <%= job.salary %> </li>
<% job.cities.each do |city| %>
<li class="detail_description"> <%= city.location %> </li>
<% end %>
<% end %>
</div>
\ No newline at end of file
<% @industries.each do |industry| %>
<div class="col-md-4 column_set">
<a href="#" class="titlejob">
<p>
<%= industry.industry_name %>
</p>
</a>
</div>
<% end %>
<div>
<button type="button" class="btn btn-success" id="cities_button">All Industry</button>
</div>
\ No newline at end of file
<h1>TopPages#cities</h1>
<p>Find me in app/views/top_pages/cities.html.erb</p>
<h1>TopPages#industries</h1>
<p>Find me in app/views/top_pages/industries.html.erb</p>
<div class="row">
<div class="col">
<h1 id="fontwords">Total jobs: <em> <%= @total_job %> </em>job</h1>
</div>
</div>
<div class="row">
<input type="text" name="search" placeholder="Search...." id="search_box">
<button type="button" class="btn btn-success" id="search_button">Search</button>
</div>
<p class="text-success line_job"> Latest Jobs</p>
<div class="row">
<%= render 'index' %>
</div>
<p class="text-success line_job">Top Cities</p>
<div class="row cities">
<%= render 'cities' %>
</div>
<p class="text-success line_job">Top Industry</p>
<div class="row cities">
<%= render 'industry' %>
</div>
Rails.application.routes.draw do
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
get 'top_pages/cities'
get 'top_pages/industries'
get 'top_pages/toppage'
get 'top_pages/job'
root 'top_pages#toppage'# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
end
every 1.day, :at => '8:30 am' do
rake "crawl:job"
end
\ No newline at end of file
......@@ -8,7 +8,6 @@ class CreateJobs < ActiveRecord::Migration[5.1]
t.string :level
t.string :expiry_date
t.integer :company_id
t.integer :city_id
t.integer :industry_id
t.timestamps
......
class AddShortDescriptionToJob < ActiveRecord::Migration[5.1]
def change
add_column :jobs, :short_description, :text
end
end
class CreateJobCities < ActiveRecord::Migration[5.1]
def change
create_table :job_cities do |t|
t.belongs_to :city
t.belongs_to :job
t.timestamps
end
end
end
......@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20170906075139) do
ActiveRecord::Schema.define(version: 20170911032843) do
create_table "cities", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
t.string "location"
......@@ -32,6 +32,15 @@ ActiveRecord::Schema.define(version: 20170906075139) do
t.datetime "updated_at", null: false
end
create_table "job_cities", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
t.bigint "city_id"
t.bigint "job_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["city_id"], name: "index_job_cities_on_city_id"
t.index ["job_id"], name: "index_job_cities_on_job_id"
end
create_table "jobs", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
t.string "job_title"
t.text "descripton"
......@@ -40,12 +49,12 @@ ActiveRecord::Schema.define(version: 20170906075139) do
t.string "level"
t.string "expiry_date"
t.integer "company_id"
t.integer "city_id"
t.integer "industry_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "experence"
t.text "benefit"
t.text "short_description"
end
end
......@@ -7,29 +7,36 @@ i = 1
last_page = 20
namespace :crawl do
task :job => :environment do
#get locationwork and save database
url_cities = "http://careerbuilder.vn/viec-lam/tat-ca-viec-lam-vi.html"
home_page = Nokogiri::HTML(open(url_cities))
cities = home_page.css('div.box_multiSelect_location select option')
cities.each do |city|
next if city.text == 'Tất cả địa điểm'
area = City.find_or_create_by(location: city.text)
end
while i <= last_page do
url= "http://careerbuilder.vn/viec-lam/tat-ca-viec-lam-trang-#{i}-vi.html"
page = Nokogiri::HTML(open(url))
p = page.css('.jobtitle h3.job a')
p.each do |detail|
begin
each_page = Nokogiri::HTML(open(detail['href']))
each_page = Nokogiri::HTML(open(Addressable::URI.parse(detail['href']).normalize.to_s).read)
#get name_company, address_company, descipton company save database
name_company = each_page.css('.tit_company').text
title_address = each_page.css('.TitleDetailNew label[itemprop="address"]').text
detail_company = each_page.xpath("//*[@id='emp_collapse']").text.strip
company = Company.find_or_create_by(company_name: name_company, company_address: title_address,company_descripton: detail_company)
company = Company.find_or_create_by!(company_name: name_company, company_address: title_address,company_descripton: detail_company)
#get industry name and save database
industry_name = each_page.css('.fl_left a[itemprop="industry"]').text
industryname = Industry.find_or_create_by(industry_name: industry_name)
#get locationwork and save database
location_work = each_page.css('p.fl_left b[itemprop="jobLocation"]').text
locationwork = City.find_or_create_by(location: location_work)
#get jobtitle update level experence salary detail_work expiry_date and save datapase
location_works = each_page.css('p.fl_left b[itemprop="jobLocation"]').text
job_title = each_page.css('h1[itemprop="title"]').text
date_post = each_page.css('.datepost').text
level = each_page.css('label[itemprop="occupationalCategory"]').text
......@@ -38,13 +45,22 @@ namespace :crawl do
detail_work = each_page.css('.MarBot20').text
benefits = each_page.css('.list-benefits').text.delete("\t").split("\n").map(&:strip).reject(&:blank?).join(',')
time_off = each_page.xpath("//ul[@class='DetailJobNew']/li/p[span/text()='Hết hạn nộp: ']/text()").text.strip
Job.find_or_create_by(job_title: job_title, update_job: date_post, level: level, expiry_date: time_off,
company_id: company.id, city_id: locationwork.id, industry_id: industryname.id,
descripton: detail_work,experence: experence,salary: salary,benefit: benefits)
short_des = each_page.css('.desc_company #emp_more').text
job_params = { job_title: job_title,
update_job: date_post, level: level, expiry_date: time_off,
company_id: company.id, industry_id: industryname.id,
descripton: detail_work,experence: experence, salary: salary, benefit: benefits,
short_description: short_des }
job = Job.create!(job_params)
location_works = location_works.split(',').map(&:strip)
location_works.each do |string|
city = City.find_by(location: string).jobs << job
end
#show pages on console screen
puts "#{detail['href']} - Page #{i}/#{last_page}"
rescue => e
p e
p "#{e} - Job URL: #{detail['href']} - Job ID: #{job.id} - Locations: #{location_works}"
end
end
i+=1
......
......@@ -44,7 +44,8 @@ namespace :import do
descripton_work = "#{row[7]} + #{row[10]} + #{row[12]}"
job = Job.find_or_create_by(benefit: row[0], descripton: descripton_work, level: row[8],
job_title: row[9], salary: row[11], industry_id: category.id,
city_id: city.id, company_id: company.id)
company_id: company.id)
job.cities << city
p "[Success] job ##{job.id}"
rescue => e
p e
......
require 'test_helper'
class TopPagesControllerTest < ActionDispatch::IntegrationTest
test "should get cities" do
get top_pages_cities_url
assert_response :success
end
test "should get industries" do
get top_pages_industries_url
assert_response :success
end
test "should get toppage" do
get top_pages_toppage_url
assert_response :success
end
end
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
city_id: 1
job_id: 1
two:
city_id: 1
job_id: 1
require 'test_helper'
class JobCityTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# 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