Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
V
Venjob_HungNT
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
Ngô Trung Hưng
Venjob_HungNT
Commits
737397ba
Commit
737397ba
authored
Jul 27, 2020
by
Ngô Trung Hưng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix convention
parent
faeb5274
Pipeline
#703
failed with stages
in 0 seconds
Changes
17
Pipelines
1
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
104 additions
and
47 deletions
+104
-47
.vscode/settings.json
+6
-0
cron.log
+0
-0
db/migrate/20200715013048_create_companies.rb
+4
-1
db/migrate/20200715013408_create_cities.rb
+4
-1
db/migrate/20200715013616_create_industries.rb
+4
-1
db/migrate/20200715014316_create_jobs.rb
+4
-1
db/migrate/20200715014925_create_histories.rb
+4
-1
db/migrate/20200715015048_create_favorites.rb
+4
-1
db/migrate/20200715015203_create_users.rb
+4
-1
db/migrate/20200715022917_create_city_jobs.rb
+4
-1
db/migrate/20200715024652_create_industry_jobs.rb
+4
-1
db/migrate/20200715025243_create_applied_jobs.rb
+4
-1
db/migrate/20200715090747_change_datatype_to_table_companies.rb
+4
-1
db/migrate/20200720035021_add_column_newdata_to_table_jobs.rb
+3
-0
error.log
+11
-0
lib/src/ftp.rb
+31
-31
lib/src/interface_web.rb
+9
-5
No files found.
.vscode/settings.json
0 → 100644
View file @
737397ba
{
"emmet.excludeLanguages"
:
[
"markdown"
]
}
\ No newline at end of file
cron.log
View file @
737397ba
This diff is collapsed.
Click to expand it.
db/migrate/20200715013048_create_companies.rb
View file @
737397ba
# frozen_string_literal: true
# Description/Explanation of Person class
class
CreateCompanies
<
ActiveRecord
::
Migration
[
5.2
]
class
CreateCompanies
<
ActiveRecord
::
Migration
[
5.2
]
def
change
def
change
create_table
:companies
,
:options
=>
'COLLATE=utf8_general_ci'
do
|
t
|
create_table
:companies
,
options:
'COLLATE=utf8_general_ci'
do
|
t
|
t
.
string
:name
t
.
string
:name
t
.
string
:address
t
.
string
:address
t
.
string
:short_description
t
.
string
:short_description
...
...
db/migrate/20200715013408_create_cities.rb
View file @
737397ba
# frozen_string_literal: true
# Description/Explanation of Person class
class
CreateCities
<
ActiveRecord
::
Migration
[
5.2
]
class
CreateCities
<
ActiveRecord
::
Migration
[
5.2
]
def
change
def
change
create_table
:cities
,
:options
=>
'COLLATE=utf8_general_ci'
do
|
t
|
create_table
:cities
,
options:
'COLLATE=utf8_general_ci'
do
|
t
|
t
.
string
:name
t
.
string
:name
t
.
boolean
:area
t
.
boolean
:area
t
.
timestamps
t
.
timestamps
...
...
db/migrate/20200715013616_create_industries.rb
View file @
737397ba
# frozen_string_literal: true
# Description/Explanation of Person class
class
CreateIndustries
<
ActiveRecord
::
Migration
[
5.2
]
class
CreateIndustries
<
ActiveRecord
::
Migration
[
5.2
]
def
change
def
change
create_table
:industries
,
:options
=>
'COLLATE=utf8_general_ci'
do
|
t
|
create_table
:industries
,
options:
'COLLATE=utf8_general_ci'
do
|
t
|
t
.
string
:name
t
.
string
:name
t
.
timestamps
t
.
timestamps
end
end
...
...
db/migrate/20200715014316_create_jobs.rb
View file @
737397ba
# frozen_string_literal: true
# Description/Explanation of Person class
class
CreateJobs
<
ActiveRecord
::
Migration
[
5.2
]
class
CreateJobs
<
ActiveRecord
::
Migration
[
5.2
]
def
change
def
change
create_table
:jobs
,
:options
=>
'COLLATE=utf8_general_ci'
do
|
t
|
create_table
:jobs
,
options:
'COLLATE=utf8_general_ci'
do
|
t
|
t
.
string
:name
t
.
string
:name
t
.
integer
:company_id
t
.
integer
:company_id
t
.
string
:level
t
.
string
:level
...
...
db/migrate/20200715014925_create_histories.rb
View file @
737397ba
# frozen_string_literal: true
# Description/Explanation of Person class
class
CreateHistories
<
ActiveRecord
::
Migration
[
5.2
]
class
CreateHistories
<
ActiveRecord
::
Migration
[
5.2
]
def
change
def
change
create_table
:histories
,
:options
=>
'COLLATE=utf8_general_ci'
do
|
t
|
create_table
:histories
,
options:
'COLLATE=utf8_general_ci'
do
|
t
|
t
.
integer
:user_id
t
.
integer
:user_id
t
.
integer
:job_id
t
.
integer
:job_id
t
.
timestamps
t
.
timestamps
...
...
db/migrate/20200715015048_create_favorites.rb
View file @
737397ba
# frozen_string_literal: true
# Description/Explanation of Person class
class
CreateFavorites
<
ActiveRecord
::
Migration
[
5.2
]
class
CreateFavorites
<
ActiveRecord
::
Migration
[
5.2
]
def
change
def
change
create_table
:favorites
,
:options
=>
'COLLATE=utf8_general_ci'
do
|
t
|
create_table
:favorites
,
options:
'COLLATE=utf8_general_ci'
do
|
t
|
t
.
integer
:user_id
t
.
integer
:user_id
t
.
integer
:job_id
t
.
integer
:job_id
t
.
timestamps
t
.
timestamps
...
...
db/migrate/20200715015203_create_users.rb
View file @
737397ba
# frozen_string_literal: true
# Description/Explanation of Person class
class
CreateUsers
<
ActiveRecord
::
Migration
[
5.2
]
class
CreateUsers
<
ActiveRecord
::
Migration
[
5.2
]
def
change
def
change
create_table
:users
,
:options
=>
'COLLATE=utf8_general_ci'
do
|
t
|
create_table
:users
,
options:
'COLLATE=utf8_general_ci'
do
|
t
|
t
.
string
:email
t
.
string
:email
t
.
string
:name
t
.
string
:name
t
.
string
:password_digest
t
.
string
:password_digest
...
...
db/migrate/20200715022917_create_city_jobs.rb
View file @
737397ba
# frozen_string_literal: true
# Description/Explanation of Person class
class
CreateCityJobs
<
ActiveRecord
::
Migration
[
5.2
]
class
CreateCityJobs
<
ActiveRecord
::
Migration
[
5.2
]
def
change
def
change
create_table
:city_jobs
,
:options
=>
'COLLATE=utf8_general_ci'
do
|
t
|
create_table
:city_jobs
,
options:
'COLLATE=utf8_general_ci'
do
|
t
|
# t.belongs_to :city, class_name: "city", foreign_key: "city_id"
# t.belongs_to :city, class_name: "city", foreign_key: "city_id"
# t.belongs_to :job, class_name: "job", foreign_key: "job_id"
# t.belongs_to :job, class_name: "job", foreign_key: "job_id"
t
.
references
:job
t
.
references
:job
...
...
db/migrate/20200715024652_create_industry_jobs.rb
View file @
737397ba
# frozen_string_literal: true
# Description/Explanation of Person class
class
CreateIndustryJobs
<
ActiveRecord
::
Migration
[
5.2
]
class
CreateIndustryJobs
<
ActiveRecord
::
Migration
[
5.2
]
def
change
def
change
create_table
:industry_jobs
,
:options
=>
'COLLATE=utf8_general_ci'
do
|
t
|
create_table
:industry_jobs
,
options:
'COLLATE=utf8_general_ci'
do
|
t
|
t
.
references
:industry
t
.
references
:industry
t
.
references
:job
t
.
references
:job
t
.
timestamps
t
.
timestamps
...
...
db/migrate/20200715025243_create_applied_jobs.rb
View file @
737397ba
# frozen_string_literal: true
# Description/Explanation of Person class
class
CreateAppliedJobs
<
ActiveRecord
::
Migration
[
5.2
]
class
CreateAppliedJobs
<
ActiveRecord
::
Migration
[
5.2
]
def
change
def
change
create_table
:applied_jobs
,
:options
=>
'COLLATE=utf8_general_ci'
do
|
t
|
create_table
:applied_jobs
,
options:
'COLLATE=utf8_general_ci'
do
|
t
|
t
.
references
:user
t
.
references
:user
t
.
references
:job
t
.
references
:job
t
.
string
:name
t
.
string
:name
...
...
db/migrate/20200715090747_change_datatype_to_table_companies.rb
View file @
737397ba
# frozen_string_literal: true
# Description/Explanation of Person class
class
ChangeDatatypeToTableCompanies
<
ActiveRecord
::
Migration
[
5.2
]
class
ChangeDatatypeToTableCompanies
<
ActiveRecord
::
Migration
[
5.2
]
def
change
def
change
change_column
:companies
,
:short_description
,
:text
change_column
:companies
,
:short_description
,
:text
#Ex:- change_column("admin_users", "email", :string, :limit =>25)
#
Ex:- change_column("admin_users", "email", :string, :limit =>25)
end
end
end
end
db/migrate/20200720035021_add_column_newdata_to_table_jobs.rb
View file @
737397ba
# frozen_string_literal: true
# Description/Explanation of Person class
class
AddColumnNewdataToTableJobs
<
ActiveRecord
::
Migration
[
5.2
]
class
AddColumnNewdataToTableJobs
<
ActiveRecord
::
Migration
[
5.2
]
def
change
def
change
add_column
:jobs
,
:newdata
,
:boolean
add_column
:jobs
,
:newdata
,
:boolean
...
...
error.log
View file @
737397ba
...
@@ -159,3 +159,14 @@ SyntaxError: /home/hungnt/hungnt_venjob/config/routes.rb:9: syntax error, unexpe
...
@@ -159,3 +159,14 @@ SyntaxError: /home/hungnt/hungnt_venjob/config/routes.rb:9: syntax error, unexpe
/home/hungnt/.rbenv/versions/2.6.6/bin/bundle:23:in `<main>'
/home/hungnt/.rbenv/versions/2.6.6/bin/bundle:23:in `<main>'
Tasks: TOP => crawler:populate => environment
Tasks: TOP => crawler:populate => environment
(See full trace by running task with --trace)
(See full trace by running task with --trace)
rake aborted!
TypeError: no implicit conversion of URI::Generic into String
/home/hungnt/hungnt_venjob/lib/src/interface_web.rb:225:in `block in make_data'
/home/hungnt/hungnt_venjob/lib/src/interface_web.rb:224:in `each'
/home/hungnt/hungnt_venjob/lib/src/interface_web.rb:224:in `each_with_index'
/home/hungnt/hungnt_venjob/lib/src/interface_web.rb:224:in `make_data'
/home/hungnt/hungnt_venjob/lib/tasks/crawler.rake:9:in `block (2 levels) in <main>'
/home/hungnt/.rbenv/versions/2.6.6/bin/bundle:23:in `load'
/home/hungnt/.rbenv/versions/2.6.6/bin/bundle:23:in `<main>'
Tasks: TOP => crawler:populate
(See full trace by running task with --trace)
lib/src/ftp.rb
View file @
737397ba
# frozen_string_literal: true
require
'net/ftp'
require
'net/ftp'
require
'src/unzip'
require
'src/unzip'
require
'csv'
require
'csv'
# Description/Explanation of Person class
class
FtpSever
class
FtpSever
CONTENT_SERVER_DOMAIN_NAME
=
'192.168.1.156'
CONTENT_SERVER_DOMAIN_NAME
=
'192.168.1.156'
CONTENT_SERVER_USER_NAME
=
'training'
CONTENT_SERVER_USER_NAME
=
'training'
CONTENT_SERVER_USER_PASSWORD
=
'training'
CONTENT_SERVER_USER_PASSWORD
=
'training'
def
self
.
donwload_csv
def
self
.
donwload_csv
Net
::
FTP
.
open
(
CONTENT_SERVER_DOMAIN_NAME
,
CONTENT_SERVER_USER_NAME
,
CONTENT_SERVER_USER_PASSWORD
)
do
|
ftp
|
Net
::
FTP
.
open
(
CONTENT_SERVER_DOMAIN_NAME
,
CONTENT_SERVER_USER_NAME
,
CONTENT_SERVER_USER_PASSWORD
)
do
|
ftp
|
ftp
.
getbinaryfile
(
'jobs.zip'
)
ftp
.
getbinaryfile
(
'jobs.zip'
)
begin
begin
extract_zip
(
'./jobs.zip'
,
'lib/csv'
)
extract_zip
(
'./jobs.zip'
,
'lib/csv'
)
File
.
delete
(
'./jobs.zip'
)
if
File
.
exist?
(
'./jobs.zip'
)
File
.
delete
(
'./jobs.zip'
)
if
File
.
exist?
(
'./jobs.zip'
)
puts
"Extract file done"
puts
'Extract file done'
rescue
rescue
StandardError
=>
e
puts
"File not found"
puts
"
#{
e
}
File not found"
end
end
end
end
end
end
def
self
.
data_csv
def
self
.
data_csv
# donwload_csv()
# donwload_csv()
table
=
CSV
.
parse
(
File
.
read
(
"lib/csv/jobs.csv"
),
headers:
true
)
CSV
.
parse
(
File
.
read
(
'lib/csv/jobs.csv'
),
headers:
true
)
end
end
def
self
.
parse_csv_industries
(
data
)
def
self
.
parse_csv_industries
(
data
)
...
@@ -30,8 +32,8 @@ class FtpSever
...
@@ -30,8 +32,8 @@ class FtpSever
industries
=
[]
industries
=
[]
industries
+=
data
[
'category'
].
map
(
&
:strip
)
industries
+=
data
[
'category'
].
map
(
&
:strip
)
industries
.
each
do
|
val
|
industries
.
each
do
|
val
|
val
.
gsub!
(
','
,
'/'
)
if
val
.
include?
(
','
)
val
.
gsub!
(
','
,
'/'
)
if
val
.
include?
(
','
)
val
.
gsub!
(
'/'
,
' / '
)
val
.
gsub!
(
'/'
,
' / '
)
Industry
.
find_or_create_by
(
name:
val
)
{
|
industry
|
industry
.
name
=
val
}
Industry
.
find_or_create_by
(
name:
val
)
{
|
industry
|
industry
.
name
=
val
}
end
end
puts
'Done parse csv industries'
puts
'Done parse csv industries'
...
@@ -39,31 +41,29 @@ class FtpSever
...
@@ -39,31 +41,29 @@ class FtpSever
def
self
.
parse_csv_cities
(
data
)
def
self
.
parse_csv_cities
(
data
)
puts
'Import data cities . . .'
puts
'Import data cities . . .'
cities
=
data
[
'work place'
].
uniq
.
select
{
|
val
|
val
.
present?
}
cities
=
data
[
'work place'
].
uniq
.
select
(
&
:present?
)
cities
=
cities
.
map
{
|
val
|
val
.
delete
(
"[]
\"
"
)
}
cities
=
cities
.
map
{
|
val
|
val
.
delete
(
'[]\"'
)
}
cities
.
each
do
|
val
|
cities
.
each
do
|
val
|
if
!
val
.
blank?
next
if
val
.
blank?
City
.
find_or_create_by
(
name:
val
)
do
|
city
|
City
.
find_or_create_by
(
name:
val
)
do
|
city
|
city
.
name
=
val
city
.
name
=
val
city
.
area
=
1
city
.
area
=
1
end
end
end
end
end
end
end
def
self
.
parse_csv_companies
(
data
)
def
self
.
parse_csv_companies
(
data
)
puts
'Import data companies . . .'
puts
'Import data companies . . .'
data
[
'company name'
].
each_with_index
do
|
name
,
index
|
data
[
'company name'
].
each_with_index
do
|
name
,
index
|
begin
Company
.
find_or_create_by
(
name:
name
.
strip
)
do
|
company
|
Company
.
find_or_create_by
(
name:
name
.
strip
)
do
|
company
|
company
.
name
=
name
.
strip
company
.
name
=
name
.
strip
company
.
address
=
data
[
'company address'
][
index
]
company
.
address
=
data
[
'company address'
][
index
]
company
.
short_description
=
data
[
'benefit'
][
index
]
company
.
short_description
=
data
[
'benefit'
][
index
]
end
end
puts
index
puts
index
rescue
=>
exception
rescue
StandardError
=>
e
puts
'---'
puts
e
end
end
end
puts
'Done import data companies'
puts
'Done import data companies'
end
end
...
@@ -75,44 +75,44 @@ class FtpSever
...
@@ -75,44 +75,44 @@ class FtpSever
id_company
=
Company
.
find_by
name:
data
[
'company name'
][
index
].
to_s
.
strip
id_company
=
Company
.
find_by
name:
data
[
'company name'
][
index
].
to_s
.
strip
id_company
=
id_company
.
blank?
?
1
:
id_company
.
id
id_company
=
id_company
.
blank?
?
1
:
id_company
.
id
begin
begin
id_job
=
Job
.
create!
(
name:
name
,
id_job
=
Job
.
create!
(
name:
name
,
company_id:
id_company
,
company_id:
id_company
,
level:
data
[
'level'
][
index
],
level:
data
[
'level'
][
index
],
experience:
""
,
experience:
''
,
salary:
data
[
'salary'
][
index
],
salary:
data
[
'salary'
][
index
],
create_date:
Time
.
now
,
create_date:
Time
.
now
,
expiration_date:
""
,
expiration_date:
''
,
description:
desc
,
description:
desc
,
newdata:
1
)
newdata:
1
)
make_foreign_cities_table
(
data
[
'work place'
][
index
],
id_job
.
id
)
make_foreign_cities_table
(
data
[
'work place'
][
index
],
id_job
.
id
)
make_foreign_industries_table
(
data
[
'category'
][
index
],
id_job
.
id
)
make_foreign_industries_table
(
data
[
'category'
][
index
],
id_job
.
id
)
puts
index
puts
index
rescue
=>
exception
rescue
StandardError
=>
e
puts
'---------'
puts
e
end
end
end
end
end
end
def
self
.
make_foreign_cities_table
(
data
,
id_job
)
def
self
.
make_foreign_cities_table
(
data
,
id_job
)
data
=
data
.
to_s
.
delete
(
"[]
\"
"
)
data
=
data
.
to_s
.
delete
(
'[]\"'
)
id_city
=
City
.
find_by
name:
data
.
strip
id_city
=
City
.
find_by
name:
data
.
strip
id_city
=
id_city
.
blank?
?
City
.
create!
(
name:
data
.
strip
,
area:
1
).
id
:
id_city
.
id
id_city
=
id_city
.
blank?
?
City
.
create!
(
name:
data
.
strip
,
area:
1
).
id
:
id_city
.
id
CityJob
.
create!
(
job_id:
id_job
,
city_id:
id_city
)
CityJob
.
create!
(
job_id:
id_job
,
city_id:
id_city
)
end
end
def
self
.
make_foreign_industries_table
(
data
,
id_job
)
def
self
.
make_foreign_industries_table
(
data
,
id_job
)
data
=
data
.
to_s
.
gsub
(
','
,
'/'
).
gsub
(
'/'
,
' / '
)
data
=
data
.
to_s
.
gsub
(
','
,
'/'
).
gsub
(
'/'
,
' / '
)
id_industry
=
Industry
.
find_by
name:
(
data
.
strip
)
data
=
data
.
strip
id_industry
=
Industry
.
find_by
name:
data
id_industry
=
id_industry
.
blank?
?
Industry
.
create!
(
name:
data
.
strip
).
id
:
id_industry
.
id
id_industry
=
id_industry
.
blank?
?
Industry
.
create!
(
name:
data
.
strip
).
id
:
id_industry
.
id
IndustryJob
.
create!
(
industry_id:
id_industry
,
job_id:
id_job
)
IndustryJob
.
create!
(
industry_id:
id_industry
,
job_id:
id_job
)
end
end
def
self
.
import_data_from_csv
def
self
.
import_data_from_csv
data
=
data_csv
()
data
=
data_csv
parse_csv_industries
(
data
)
parse_csv_industries
(
data
)
parse_csv_cities
(
data
)
parse_csv_cities
(
data
)
parse_csv_companies
(
data
)
parse_csv_companies
(
data
)
parse_csv_jobs
(
data
)
parse_csv_jobs
(
data
)
end
end
end
end
lib/src/interface_web.rb
View file @
737397ba
# frozen_string_literal: true
require
'open-uri'
require
'open-uri'
# Description/Explanation of Person class
class
InterfaceWeb
class
InterfaceWeb
def
self
.
crawl_link_for_companies_jobs
(
page
)
def
self
.
crawl_link_for_companies_jobs
(
page
)
...
@@ -217,13 +221,13 @@ class InterfaceWeb
...
@@ -217,13 +221,13 @@ class InterfaceWeb
break
if
@@stop_crawl
==
val
break
if
@@stop_crawl
==
val
arr_link
<<
val
arr_link
<<
val
end
end
arr_link
.
reverse!
.
each_with_index
do
|
path
,
i
|
arr_link
.
reverse!
.
each_with_index
do
|
path
,
i
|
page
=
Nokogiri
::
HTML
(
URI
.
open
(
URI
.
parse
(
URI
.
escape
(
path
))))
page
=
Nokogiri
::
HTML
(
URI
.
open
(
URI
.
parse
(
CGI
.
escape
(
path
))))
if
page
.
search
(
".item-blue .detail-box:nth-child(1) ul li:nth-child(1) p"
)[
0
]
!=
nil
if
!
page
.
search
(
'.item-blue .detail-box:nth-child(1) ul li:nth-child(1) p'
)[
0
].
nil?
crawl_data_jobs_interface_1
(
page
)
crawl_data_jobs_interface_1
(
page
)
elsif
page
.
search
(
"section .template-200"
).
text
!=
""
elsif
page
.
search
(
'section .template-200'
).
text
!=
''
crawl_data_jobs_interface_2
(
page
)
crawl_data_jobs_interface_2
(
page
)
elsif
(
page
.
search
(
".DetailJobNew ul li"
).
size
==
10
&&
!
page
.
search
(
'.right-col ul li'
).
text
.
include?
(
'Độ tuổi'
)
)
elsif
page
.
search
(
'.DetailJobNew ul li'
).
size
==
10
&&
!
page
.
search
(
'.right-col ul li'
).
text
.
include?
(
'Độ tuổi'
)
crawl_data_jobs_interface_5
(
page
)
crawl_data_jobs_interface_5
(
page
)
end
end
puts
"
#{
i
}
-
#{
path
}
"
puts
"
#{
i
}
-
#{
path
}
"
...
...
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