Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
V
venjob
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Huỳnh Thiên Phước
venjob
Commits
15dba6fe
Commit
15dba6fe
authored
Aug 03, 2020
by
Huỳnh Thiên Phước
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix controller, model of city and industry
parent
c002193c
Pipeline
#774
canceled with stages
in 0 seconds
Changes
14
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
91 additions
and
66 deletions
+91
-66
app/assets/stylesheets/top_pages.scss
+25
-4
app/controllers/top_pages_controller.rb
+2
-2
app/models/city.rb
+3
-0
app/models/city_job.rb
+0
-3
app/models/industry.rb
+4
-0
app/views/layouts/_search_bar.html.erb
+25
-22
app/views/layouts/_show_cities.html.erb
+4
-4
app/views/layouts/_show_industries.html.erb
+6
-4
app/views/layouts/_show_jobs.html.erb
+1
-1
app/views/top_pages/index.html.erb
+6
-3
lib/src/crawler.rb
+3
-3
lib/src/csv_importer.rb
+6
-13
lib/src/job_parser.rb
+0
-0
lib/tasks/crawler_import.rake
+6
-7
No files found.
app/assets/stylesheets/top_pages.scss
View file @
15dba6fe
...
...
@@ -78,14 +78,35 @@
background-image
:
linear-gradient
(
160deg
,
black
,
#8c8686
);
color
:
white
;
}
.city-list
:hover
{
.city-list
:hover
,
.industry-list
:hover
{
background-color
:
black
;
.city-name
,
.count-job
{
text-decoration
:
none
;
.city-name
,
.count-job
,
.industry-name
{
color
:
white
;
}
}
.city-name
,
.count-job
{
.city-list
,
.industry-list
{
&
:hover
{
a
{
text-decoration
:
none
;
}
}
}
.city-name
,
.count-job
,
.industry-name
{
text-decoration
:
none
;
color
:
black
;
}
.search-bar
{
padding
:
20px
;
}
.all-city
:hover
,
.all-industry
:hover
{
.all-cities
,
.all-industries
{
color
:
blue
;
}
}
.all-city
,
.all-industry
{
&
:hover
{
a
{
text-decoration
:
none
;
}
}
}
app/controllers/top_pages_controller.rb
View file @
15dba6fe
...
...
@@ -4,7 +4,7 @@ class TopPagesController < ApplicationController
@industries
=
Industry
.
all
@total_jobs
=
Job
.
count
@jobs
=
Job
.
limit
(
5
).
order
(
created_at: :desc
)
@jobs_of_cities
=
City
Job
.
top_city
@jobs_of_industries
=
Industry
Job
.
limit
(
9
).
group
(
'industry_id'
).
order
(
'Count(*) DESC'
).
count
@jobs_of_cities
=
City
.
top_city
@jobs_of_industries
=
Industry
.
top_industry
end
end
app/models/city.rb
View file @
15dba6fe
...
...
@@ -2,4 +2,7 @@ class City < ApplicationRecord
has_many
:city_jobs
has_many
:jobs
,
through: :city_jobs
def
self
.
top_city
joins
(
:jobs
).
group
(
:city_id
).
order
(
'count(job_id) DESC'
).
limit
(
9
)
end
end
app/models/city_job.rb
View file @
15dba6fe
...
...
@@ -2,7 +2,4 @@ class CityJob < ApplicationRecord
belongs_to
:city
belongs_to
:job
def
self
.
top_city
limit
(
9
).
group
(
'city_id'
).
order
(
'Count(*) DESC'
).
count
end
end
app/models/industry.rb
View file @
15dba6fe
class
Industry
<
ApplicationRecord
has_many
:industry_jobs
has_many
:jobs
,
through: :industry_jobs
def
self
.
top_industry
joins
(
:jobs
).
group
(
:industry_id
).
order
(
'count(job_id) DESC'
).
limit
(
9
)
end
end
app/views/layouts/_search_bar.html.erb
View file @
15dba6fe
<div
class=
"search-bar"
>
<div
class=
"row"
>
<div
class=
"col-sm"
>
<input
class=
"form-control mr-sm-2"
type=
"search"
placeholder=
"Search"
aria-label=
"Search"
>
</div>
<div
class=
"col-sm"
>
<select
class=
"form-control"
id=
"exampleFormControlSelect1"
>
<%=
@cities
.
each
do
|
city
|
%>
<option>
<%=
city
.
name
%>
</option>
<%
end
%>
</select>
</div>
<div
class=
"col-sm"
>
<select
class=
"form-control"
id=
"exampleFormControlSelect1"
>
<%=
@industries
.
each
do
|
industry
|
%>
<option>
<%=
industry
.
name
%>
</option>
<%
end
%>
</select>
</div>
<div
class=
"col-2-sm"
>
<button
class=
"btn btn-primary"
type=
"submit"
>
Search
</button>
</div>
</div>
<div
class=
"row"
>
<div
class=
"col-sm"
>
<input
class=
"form-control mr-sm-2"
type=
"search"
placeholder=
"Search"
aria-label=
"Search"
>
</div>
<div
class=
"col-sm"
>
<select
class=
"form-control"
id=
"exampleFormControlSelect1"
>
<option>
--None
</option>
<%=
@cities
.
each
do
|
city
|
%>
<option>
<%=
city
.
name
%>
</option>
<%
end
%>
</select>
</div>
<div
class=
"col-sm"
>
<select
class=
"form-control"
id=
"exampleFormControlSelect1"
>
<option>
--None
</option>
<%=
@industries
.
each
do
|
industry
|
%>
<option>
<%=
industry
.
name
%>
</option>
<%
end
%>
</select>
</div>
<div
class=
"col-2-sm"
>
<button
class=
"btn btn-primary"
type=
"submit"
>
Search
</button>
</div>
</div>
</div>
\ No newline at end of file
app/views/layouts/_show_cities.html.erb
View file @
15dba6fe
<%
@jobs_of_cities
.
each
do
|
city
,
count_job
|
%>
<%
@jobs_of_cities
.
each
do
|
city
|
%>
<div
class=
"col-4"
>
<div
class=
"row-table border border-dark rounded city-list"
>
<%=
link_to
'#'
do
%>
<div
class=
"city-name"
><strong>
<%=
City
.
find
(
city
)
.
name
%>
</strong></div>
<div
class=
"count-job"
>
<%=
c
ount_job
%>
</div>
<%=
link_to
'#'
do
%>
<div
class=
"city-name"
><strong>
<%=
city
.
name
%>
</strong></div>
<div
class=
"count-job"
>
<%=
c
ity
.
jobs
.
count
%>
</div>
<%
end
%>
</div>
</div>
...
...
app/views/layouts/_show_industries.html.erb
View file @
15dba6fe
<%
@jobs_of_industries
.
each
do
|
industry
,
count_job
|
%>
<%
@jobs_of_industries
.
each
do
|
industry
|
%>
<div
class=
"col-4"
>
<div
class=
"row-table border border-dark rounded"
>
<div
class=
"industry-name"
><strong>
<%=
Industry
.
find
(
industry
).
name
%>
</strong></div>
<div
class=
"count-job"
>
<%=
count_job
%>
</div>
<div
class=
"row-table border border-dark rounded industry-list"
>
<%=
link_to
'#'
do
%>
<div
class=
"industry-name"
><strong>
<%=
industry
.
name
%>
</strong></div>
<div
class=
"count-job"
>
<%=
industry
.
jobs
.
count
%>
</div>
<%
end
%>
</div>
</div>
<%
end
%>
app/views/layouts/_show_jobs.html.erb
View file @
15dba6fe
...
...
@@ -4,7 +4,7 @@
<div
class=
"job-details"
>
<div
class=
"title"
><strong>
<%=
job
.
title
%>
</strong></div>
<div>
<%=
job
.
company_name
%>
</div>
<div
class=
"salary"
>
$ Lương
:
<%=
job
.
salary
%>
</div>
<div
class=
"salary"
>
Salary
:
<%=
job
.
salary
%>
</div>
<div>
▼
<%
job
.
cities
.
each
do
|
city
|
%>
<%=
city
.
name
%>
...
...
app/views/top_pages/index.html.erb
View file @
15dba6fe
...
...
@@ -7,18 +7,21 @@
<div
class=
"container"
>
<div
class=
"search-bar"
>
<%=
render
'layouts/search_bar'
%>
</div>
<br>
<div
class=
"job-list"
>
<%=
render
'layouts/show_jobs'
%>
</div>
<div
class=
"city-banner rounded"
>
City
</div>
<div
class=
"row"
>
<%=
render
'layouts/show_cities'
%>
</div>
<div
class=
"all-city"
>
<div
class=
"row-table border border-dark rounded"
><strong>
All Cities
</strong></div>
<%=
link_to
'#'
do
%>
<div
class=
"row-table border border-dark rounded all-cities"
><strong>
All Cities
</strong></div>
<%
end
%>
</div>
<div
class=
"industry-banner rounded"
>
Industry
</div>
<div
class=
"row"
>
<%=
render
'layouts/show_industries'
%>
</div>
<div
class=
"all-industry"
>
<div
class=
"row-table border border-dark rounded"
><strong>
All Industries
</strong></div>
<%=
link_to
'#'
do
%>
<div
class=
"row-table border border-dark rounded all-industries"
><strong>
All Industries
</strong></div>
<%
end
%>
</div>
</div>
...
...
lib/src/crawler.rb
View file @
15dba6fe
...
...
@@ -20,11 +20,11 @@ class Crawler
data_city
.
each
do
|
name_city
|
if
City
.
find_by
(
id:
70
)
city
=
City
.
create!
(
name:
name_city
,
location:
0
)
city
=
City
.
create!
(
name:
name_city
,
location:
0
)
else
city
=
City
.
create!
(
name:
name_city
,
location:
1
)
location:
1
)
end
end
end
...
...
lib/src/csvimporter.rb
→
lib/src/csv
_
importer.rb
View file @
15dba6fe
...
...
@@ -2,7 +2,7 @@ require 'net/ftp'
require
'csv'
require
'zip'
class
CSV
i
mporter
class
CSV
I
mporter
def
initialize
(
logger
)
@logger
=
logger
@NAME_DOMAIN
=
'192.168.1.156'
...
...
@@ -59,22 +59,15 @@ class CSVimporter
industry_name
=
row
[
"category"
]
industries_relationship
=
Industry
.
where
(
name:
industry_name
)
if
industries_relationship
.
blank?
industries_relationship
=
Industry
.
where
(
name:
industry
)
job
.
industries
<<
industries_relationship
else
job
.
industries
<<
industries_relationship
end
next
if
industries_relationship
.
blank?
job
.
industries
<<
industries_relationship
location_data
=
row
[
"work place"
]
location
=
location_data
.
gsub
(
'["'
,
''
).
gsub
(
'"]'
,
''
)
location_relationship
=
City
.
where
(
name:
location
)
if
location_relationship
.
blank?
location_relationship
=
City
.
where
(
name:
city
)
job
.
cities
<<
location_relationship
else
job
.
cities
<<
location_relationship
end
next
if
location_relationship
.
blank?
job
.
cities
<<
location_relationship
rescue
StandardError
=>
e
@logger
.
error
e
.
message
end
...
...
lib/src/jobparser.rb
→
lib/src/job
_
parser.rb
View file @
15dba6fe
File moved
lib/tasks/crawler_import.rake
View file @
15dba6fe
require
'src/crawler.rb'
require
'src/jobparser.rb'
require
'src/csvimporter.rb'
require
'src/job
_
parser.rb'
require
'src/csv
_
importer.rb'
namespace
:import
do
desc
'crawler data'
task
crawler: :environment
do
action
=
Crawler
.
new
(
logger
,
url
)
action
.
crawl_city_industry
action
=
Crawler
.
new
(
logger
,
url
).
crawl_city_industry
end
desc
'Crontab'
task
auto: :environment
do
crontab
=
JobParser
.
new
(
logger
,
url
)
csv
importer
=
CSVi
mporter
.
new
(
logger
)
csv
_importer
=
CSVI
mporter
.
new
(
logger
)
crontab
.
crawl_all
csvimporter
.
import
csv
_
importer
.
import
end
def
logger
Logger
.
new
(
Rails
.
root
.
join
(
'log'
,
'
my
.log'
))
Logger
.
new
(
Rails
.
root
.
join
(
'log'
,
'
crawling
.log'
))
end
def
url
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment