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
cde1c3b4
Commit
cde1c3b4
authored
Jul 29, 2020
by
Ngô Trung Hưng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix -part4
parent
a3ce51ad
Pipeline
#732
failed with stages
in 0 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
10 deletions
+10
-10
lib/service/ftp.rb
+6
-6
lib/service/import_data.rb
+4
-4
No files found.
lib/service/ftp.rb
View file @
cde1c3b4
...
...
@@ -10,24 +10,24 @@ class FtpSever
CONTENT_SERVER_DOMAIN_NAME
=
'192.168.1.156'
CONTENT_SERVER_USER_NAME
=
'training'
CONTENT_SERVER_USER_PASSWORD
=
'training'
DIRECTORY_CSV
=
'./
jobs.zip'
NAME_CSV
=
'
jobs.zip'
def
data_csv
donwload_csv
CSV
.
parse
(
File
.
read
(
'lib/csv/jobs.csv'
),
headers:
true
)
CSV
.
parse
(
File
.
read
(
'lib/csv/jobs.csv'
),
headers:
true
)
end
def
logger
@logger
||=
Logger
.
new
(
"
#{
Rails
.
root
}
/log/csv.log"
)
@logger
||=
Logger
.
new
(
Rails
.
root
.
join
(
'log'
,
'csv.log'
)
)
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
)
ftp
.
getbinaryfile
(
NAME_CSV
)
Unzip
.
extract_zip
(
Rails
.
root
.
join
(
NAME_CSV
),
Rails
.
root
.
join
(
'lib'
,
'csv'
)
)
File
.
delete
(
Rails
.
root
.
join
(
NAME_CSV
))
if
File
.
exist?
(
Rails
.
root
.
join
(
NAME_CSV
)
)
logger
.
info
'Donwload & extract success'
end
end
...
...
lib/service/import_data.rb
View file @
cde1c3b4
...
...
@@ -78,13 +78,13 @@ class ImportData
data
=
data
.
to_s
.
delete
(
'[]\"'
)
city
=
City
.
find_or_create_by
(
name:
data
.
strip
)
{
|
record
|
record
.
area
=
DOMESTIC
}
city_id
=
city
.
id
CityJob
.
create
!
(
job_id:
id_job
,
city_id:
city_id
)
CityJob
.
create
(
job_id:
id_job
,
city_id:
city_id
)
end
def
make_foreign_industries_table
(
data
,
id_job
)
data
=
data
.
to_s
.
gsub
(
','
,
'/'
).
gsub
(
'/'
,
' / '
)
industry
=
Industry
.
find_or_create_by
(
name:
data
.
strip
)
industry_name
=
data
.
to_s
.
gsub
(
','
,
'/'
).
gsub
(
'/'
,
' / '
)
industry
=
Industry
.
find_or_create_by
(
name:
industry_name
.
strip
)
industry_id
=
industry
.
id
IndustryJob
.
create
!
(
industry_id:
industry_id
,
job_id:
id_job
)
IndustryJob
.
create
(
industry_id:
industry_id
,
job_id:
id_job
)
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