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
4c82e248
Commit
4c82e248
authored
Aug 05, 2020
by
Huỳnh Thiên Phước
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix csv relationship
parent
52e242c9
Pipeline
#814
canceled with stages
in 0 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
21 deletions
+31
-21
app/models/city.rb
+2
-2
lib/src/crawler.rb
+11
-11
lib/src/csv_importer.rb
+18
-8
No files found.
app/models/city.rb
View file @
4c82e248
...
@@ -3,6 +3,6 @@ class City < ApplicationRecord
...
@@ -3,6 +3,6 @@ class City < ApplicationRecord
has_many
:jobs
,
through: :city_jobs
has_many
:jobs
,
through: :city_jobs
scope
:top_city
,
->
{
joins
(
:jobs
).
group
(
:city_id
).
order
(
'count(job_id) DESC'
).
limit
(
9
)
}
scope
:top_city
,
->
{
joins
(
:jobs
).
group
(
:city_id
).
order
(
'count(job_id) DESC'
).
limit
(
9
)
}
scope
:vietnam
,
->
{
joins
(
:jobs
).
group
(
:city_id
).
order
(
'count(job_id) DESC'
).
where
(
'location = 1'
)
}
scope
:vietnam
,
->
{
joins
(
:jobs
).
group
(
:city_id
).
order
(
'count(job_id) DESC'
).
where
(
location:
1
)
}
scope
:international
,
->
{
joins
(
:jobs
).
group
(
:city_id
).
order
(
'count(job_id) DESC'
).
where
(
'location = 0'
)
}
scope
:international
,
->
{
joins
(
:jobs
).
group
(
:city_id
).
order
(
'count(job_id) DESC'
).
where
(
location:
0
)
}
end
end
lib/src/crawler.rb
View file @
4c82e248
class
Crawler
class
Crawler
def
initialize
(
logger
,
url
)
def
initialize
(
logger
,
url
)
@logger
=
logger
@logger
=
logger
@url
=
url
@url
=
url
...
@@ -17,7 +17,7 @@ class Crawler
...
@@ -17,7 +17,7 @@ class Crawler
page
=
Nokogiri
::
HTML
(
URI
.
open
(
@url
))
page
=
Nokogiri
::
HTML
(
URI
.
open
(
@url
))
get_name
=
page
.
search
(
'select#location'
)
get_name
=
page
.
search
(
'select#location'
)
data_city
=
get_name
.
search
(
'option'
).
map
(
&
:text
).
map
(
&
:strip
)
data_city
=
get_name
.
search
(
'option'
).
map
(
&
:text
).
map
(
&
:strip
)
data_city
.
each
do
|
name_city
|
data_city
.
each
do
|
name_city
|
if
City
.
find_by
(
id:
70
)
if
City
.
find_by
(
id:
70
)
city
=
City
.
create!
(
name:
name_city
,
city
=
City
.
create!
(
name:
name_city
,
...
@@ -78,17 +78,17 @@ class Crawler
...
@@ -78,17 +78,17 @@ class Crawler
info
=
Nokogiri
::
HTML
(
URI
.
open
(
"https://careerbuilder.vn/viec-lam/tat-ca-viec-lam-trang-
#{
n
}
-vi.html"
))
info
=
Nokogiri
::
HTML
(
URI
.
open
(
"https://careerbuilder.vn/viec-lam/tat-ca-viec-lam-trang-
#{
n
}
-vi.html"
))
links
=
info
.
css
(
'div.caption a.company-name'
).
map
{
|
link
|
link
[
'href'
]
}
links
=
info
.
css
(
'div.caption a.company-name'
).
map
{
|
link
|
link
[
'href'
]
}
links
.
each
do
|
link
|
links
.
each
do
|
link
|
next
if
link
==
'javascript:void(0);'
page
=
Nokogiri
::
HTML
(
URI
.
open
(
URI
.
escape
(
link
)))
name
=
page
.
search
(
'p.name'
)
&
.
text
next
if
name
.
blank?
address
=
page
.
css
(
'div.content p'
).
children
[
1
]
&
.
text
introduction
=
page
.
css
(
'div.main-about-us'
).
text
begin
begin
next
if
link
==
'javascript:void(0);'
page
=
Nokogiri
::
HTML
(
URI
.
open
(
URI
.
escape
(
link
)))
name
=
page
.
search
(
'p.name'
)
&
.
text
next
if
name
.
blank?
address
=
page
.
css
(
'div.content p'
).
children
[
1
]
&
.
text
introduction
=
page
.
css
(
'div.main-about-us'
).
text
Company
.
find_or_create_by!
(
name:
name
,
Company
.
find_or_create_by!
(
name:
name
,
address:
address
,
address:
address
,
introduction:
introduction
)
introduction:
introduction
)
rescue
StandardError
=>
e
rescue
StandardError
=>
e
@logger
.
error
e
.
message
@logger
.
error
e
.
message
end
end
...
...
lib/src/csv_importer.rb
View file @
4c82e248
...
@@ -54,21 +54,31 @@ class CSVImporter
...
@@ -54,21 +54,31 @@ class CSVImporter
level
=
row
[
"level"
]
level
=
row
[
"level"
]
salary
=
row
[
"salary"
]
salary
=
row
[
"salary"
]
job
=
Job
.
find_or_create_by!
(
title:
title_job
,
description:
description_job
,
level:
level
,
salary:
salary
,
company_id:
company_id
)
industry_name
=
row
[
"category"
]
industry_name
=
row
[
"category"
]
industries_relationship
=
Industry
.
where
(
name:
industry_name
)
industries_relationship
=
Industry
.
where
(
name:
industry_name
)
next
if
industries_relationship
.
blank?
industry_job_relationship
=
IndustryJob
.
where
(
job_id:
job
.
id
,
industry_id:
industries_relationship
.
ids
)
next
if
industry_job_relationship
.
present?
job
.
industries
<<
industries_relationship
location_data
=
row
[
"work place"
]
location_data
=
row
[
"work place"
]
location
=
location_data
.
gsub
(
'["'
,
''
).
gsub
(
'"]'
,
''
)
location
=
location_data
.
gsub
(
'["'
,
''
).
gsub
(
'"]'
,
''
)
location_relationship
=
City
.
where
(
name:
location
)
location_relationship
=
City
.
where
(
name:
location
)
next
if
location_relationship
.
blank?
location_job_relationship
=
CityJob
.
where
(
job_id:
job
.
id
,
city_id:
location_relationship
.
ids
)
next
if
location_job_relationship
.
present?
job
.
cities
<<
location_relationship
Job
.
find_or_create_by!
(
title:
title_job
,
description:
description_job
,
level:
level
,
salary:
salary
,
company_id:
company_id
)
do
|
job
|
job
.
industries
<<
industries_relationship
job
.
cities
<<
location_relationship
end
rescue
StandardError
=>
e
rescue
StandardError
=>
e
@logger
.
error
e
.
message
@logger
.
error
e
.
message
end
end
...
...
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