Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
V
venjob_nth
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
3
Merge Requests
3
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_nth
Commits
a3ce51ad
Commit
a3ce51ad
authored
Jul 29, 2020
by
Ngô Trung Hưng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix bug
parent
0f57f980
Pipeline
#731
canceled with stages
in 0 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
18 deletions
+21
-18
.gitignore
+1
-0
lib/service/ftp.rb
+17
-15
lib/service/import_data.rb
+3
-3
No files found.
.gitignore
View file @
a3ce51ad
...
@@ -25,3 +25,4 @@
...
@@ -25,3 +25,4 @@
# Ignore master key for decrypting credentials and more.
# Ignore master key for decrypting credentials and more.
/config/master.key
/config/master.key
/lib/csv
lib/service/ftp.rb
View file @
a3ce51ad
...
@@ -10,23 +10,25 @@ class FtpSever
...
@@ -10,23 +10,25 @@ 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'
DIRECTORY_CSV
=
'./jobs.zip'
@logger
||=
Logger
.
new
(
"
#{
Rails
.
root
}
/log/csv.log"
)
def
data_csv
def
self
.
donwload_csv
donwload_csv
Net
::
FTP
.
open
(
CONTENT_SERVER_DOMAIN_NAME
,
CONTENT_SERVER_USER_NAME
,
CONTENT_SERVER_USER_PASSWORD
)
do
|
ftp
|
CSV
.
parse
(
File
.
read
(
'lib/csv/jobs.csv'
),
headers:
true
)
begin
ftp
.
getbinaryfile
(
'jobs.zip'
)
Unzip
.
extract_zip
(
'./jobs.zip'
,
'lib/csv'
)
File
.
delete
(
'./jobs.zip'
)
if
File
.
exist?
(
'./jobs.zip'
)
@logger
.
info
'Donwload & extract success'
rescue
FileNotFound
=>
e
@logger
.
error
"
#{
e
.
message
}
"
end
end
end
end
def
self
.
data_csv
def
logger
donwload_csv
@logger
||=
Logger
.
new
(
"
#{
Rails
.
root
}
/log/csv.log"
)
CSV
.
parse
(
File
.
read
(
'lib/csv/jobs.csv'
),
headers:
true
)
end
private
def
donwload_csv
Net
::
FTP
.
open
(
CONTENT_SERVER_DOMAIN_NAME
,
CONTENT_SERVER_USER_NAME
,
CONTENT_SERVER_USER_PASSWORD
)
do
|
ftp
|
ftp
.
getbinaryfile
(
'jobs.zip'
)
Unzip
.
extract_zip
(
DIRECTORY_CSV
,
'lib/csv'
)
File
.
delete
(
DIRECTORY_CSV
)
if
File
.
exist?
(
DIRECTORY_CSV
)
logger
.
info
'Donwload & extract success'
end
end
end
end
end
lib/service/import_data.rb
View file @
a3ce51ad
...
@@ -8,7 +8,7 @@ class ImportData
...
@@ -8,7 +8,7 @@ class ImportData
COMPANY_SECURITY
=
1
COMPANY_SECURITY
=
1
def
import_data
def
import_data
csv_data
=
FtpSever
.
data_csv
csv_data
=
FtpSever
.
new
.
data_csv
import_industries_from
(
csv_data
)
import_industries_from
(
csv_data
)
import_cities_from
(
csv_data
)
import_cities_from
(
csv_data
)
import_companies_from
(
csv_data
)
import_companies_from
(
csv_data
)
...
@@ -57,10 +57,10 @@ class ImportData
...
@@ -57,10 +57,10 @@ class ImportData
csv
[
'name'
].
each_with_index
do
|
name
,
index
|
csv
[
'name'
].
each_with_index
do
|
name
,
index
|
desc
=
"
#{
csv
[
'requirement'
][
index
]
}
#{
(
csv
[
'description'
][
index
])
}
"
desc
=
"
#{
csv
[
'requirement'
][
index
]
}
#{
(
csv
[
'description'
][
index
])
}
"
company
=
Company
.
find_by
name:
csv
[
'company name'
][
index
].
to_s
.
strip
company
=
Company
.
find_by
name:
csv
[
'company name'
][
index
].
to_s
.
strip
id_company
=
company
.
blank?
?
COMPANY_SECURITY
:
company
.
id
company_id
=
company
.
blank?
?
COMPANY_SECURITY
:
company
.
id
begin
begin
job
=
Job
.
create!
(
name:
name
,
job
=
Job
.
create!
(
name:
name
,
company_id:
id_company
,
company_id:
company_id
,
level:
csv
[
'level'
][
index
],
level:
csv
[
'level'
][
index
],
salary:
csv
[
'salary'
][
index
],
salary:
csv
[
'salary'
][
index
],
create_date:
Time
.
now
,
create_date:
Time
.
now
,
...
...
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