Toggle navigation
Toggle navigation
This project
Loading...
Sign in
김대선
/
Recruitment_Information_chatbot
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
김대선
2021-05-29 16:33:31 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
51f76856e720e8d3eff4e2db1fad8af0bfe98bef
51f76856
1 parent
19ab390d
데이터 저장, 읽기 분리
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
113 additions
and
92 deletions
app.js
functions/dataFunctions.js
function.js → functions/function.js
functions/kakaoFunction.js
functions/naverFunction.js
functions/programmersFunction.js
app.js
View file @
51f7685
const
express
=
require
(
'express'
)
const
schedule
=
require
(
'node-schedule'
)
const
fs
=
require
(
'fs'
)
const
functions
=
require
(
'./function'
)
const
app
=
express
();
const
dataFunctions
=
require
(
'./functions/dataFunctions'
)
const
readData
=
async
()
=>
{
const
data
=
[]
let
title
=
""
let
tags
=
[]
let
url
=
""
const
today
=
new
Date
()
const
string
=
fs
.
readFileSync
(
`./datas/
${
today
.
getFullYear
()}
.
${
today
.
getMonth
()}
.
${
today
.
getDate
()}
`
,
'utf-8'
,
'r'
)
const
stringArray
=
string
.
split
(
'\n'
)
const
size
=
stringArray
.
length
for
(
let
i
=
0
;
i
<
size
;
i
++
){
if
(
i
%
3
==
0
){
title
=
stringArray
[
i
].
replace
(
"title : "
,
""
)
}
else
if
(
i
%
3
==
1
){
tags
=
stringArray
[
i
].
replace
(
"tags : "
,
""
).
split
(
","
)
}
else
if
(
i
%
3
==
2
){
url
=
stringArray
[
i
].
replace
(
"url : "
,
""
)
data
.
push
({
title
:
title
,
tags
:
tags
,
url
:
url
})
}
}
console
.
log
(
data
)
}
const
app
=
express
();
const
save
=
async
()
=>
{
try
{
let
string
=
""
let
data
=
await
functions
.
getKakaoData
()
let
temp
=
""
for
(
let
i
of
data
){
temp
=
"title : "
+
i
.
title
string
=
string
+
temp
+
"\n"
temp
=
"tags : "
+
i
.
tags
.
toString
()
string
=
string
+
temp
+
"\n"
temp
=
"url : "
+
i
.
url
string
=
string
+
temp
+
"\n"
}
data
=
await
functions
.
getNaverFunction
()
temp
=
""
for
(
let
i
of
data
){
temp
=
"title : "
+
i
.
title
string
=
string
+
temp
+
"\n"
if
(
!!
i
.
tags
){
temp
=
"tags : "
+
i
.
tags
.
toString
()
string
=
string
+
temp
+
"\n"
}
temp
=
"url : "
+
i
.
url
string
=
string
+
temp
+
"\n"
}
data
=
await
functions
.
getProgrammersFunction
()
temp
=
""
for
(
let
i
of
data
){
temp
=
"title : "
+
i
.
title
string
=
string
+
temp
+
"\n"
temp
=
"tags : "
+
i
.
tags
.
toString
()
string
=
string
+
temp
+
"\n"
temp
=
"url : "
+
i
.
url
string
=
string
+
temp
+
"\n"
}
const
today
=
new
Date
()
fs
.
writeFile
(
`./datas/
${
today
.
getFullYear
()}
.
${
today
.
getMonth
()}
.
${
today
.
getDate
()}
`
,
string
,
'utf-8'
,
(
err
)
=>
{
if
(
err
){
save
()
}
else
console
.
log
(
"저장완료!"
)
})
}
catch
(
error
)
{
console
.
log
(
error
)
save
()
}
}
// 0초 0분 0시 아무날 아무달 아무년
const
saveData
=
schedule
.
scheduleJob
(
'
0 0 0 * * *'
,
save
)
const
saveData
=
schedule
.
scheduleJob
(
'
55 30 16 * * *'
,
dataFunctions
.
save
)
const
server
=
app
.
listen
(
3000
,()
=>
{
const
host
=
server
.
address
().
address
...
...
@@ -96,5 +20,5 @@ const server = app.listen(3000,()=>{
app
.
get
(
'/'
,
async
(
req
,
res
)
=>
{
res
.
send
(
string
)
res
.
send
(
"hello world"
)
})
\ No newline at end of file
...
...
functions/dataFunctions.js
0 → 100644
View file @
51f7685
const
fs
=
require
(
'fs'
)
const
functions
=
require
(
'./function'
)
const
read
=
async
()
=>
{
const
data
=
[]
let
title
=
""
let
tags
=
[]
let
url
=
""
let
companyName
=
""
const
today
=
new
Date
()
const
string
=
fs
.
readFileSync
(
`./datas/
${
today
.
getFullYear
()}
.
${
today
.
getMonth
()}
.
${
today
.
getDate
()}
`
,
'utf-8'
,
'r'
)
const
stringArray
=
string
.
split
(
'\n'
)
const
size
=
stringArray
.
length
for
(
let
i
=
0
;
i
<
size
;
i
++
){
if
(
i
%
4
==
0
){
title
=
stringArray
[
i
].
replace
(
"title : "
,
""
)
}
else
if
(
i
%
4
==
1
){
tags
=
stringArray
[
i
].
replace
(
"tags : "
,
""
).
split
(
","
)
}
else
if
(
i
%
4
==
2
){
tags
=
stringArray
[
i
].
replace
(
"url : "
,
""
)
}
else
if
(
i
%
4
==
3
){
companyName
=
stringArray
[
i
].
replace
(
"company : "
,
""
)
data
.
push
({
title
:
title
,
tags
:
tags
,
url
:
url
,
companyName
:
companyName
})
}
}
console
.
log
(
data
)
}
const
save
=
async
()
=>
{
try
{
let
string
=
""
let
data
=
await
functions
.
getKakaoData
()
let
temp
=
""
for
(
let
i
of
data
){
temp
=
"title : "
+
i
.
title
string
=
string
+
temp
+
"\n"
temp
=
"tags : "
+
i
.
tags
.
toString
()
string
=
string
+
temp
+
"\n"
temp
=
"url : "
+
i
.
url
string
=
string
+
temp
+
"\n"
temp
=
"companyName : "
+
i
.
companyName
string
=
string
+
temp
+
"\n"
}
data
=
await
functions
.
getNaverFunction
()
temp
=
""
for
(
let
i
of
data
){
temp
=
"title : "
+
i
.
title
string
=
string
+
temp
+
"\n"
temp
=
"tags : "
+
i
.
tags
.
toString
()
string
=
string
+
temp
+
"\n"
temp
=
"url : "
+
i
.
url
string
=
string
+
temp
+
"\n"
temp
=
"companyName : "
+
i
.
companyName
string
=
string
+
temp
+
"\n"
}
data
=
await
functions
.
getProgrammersFunction
()
temp
=
""
for
(
let
i
of
data
){
temp
=
"title : "
+
i
.
title
string
=
string
+
temp
+
"\n"
temp
=
"tags : "
+
i
.
tags
.
toString
()
string
=
string
+
temp
+
"\n"
temp
=
"url : "
+
i
.
url
string
=
string
+
temp
+
"\n"
temp
=
"companyName : "
+
i
.
companyName
string
=
string
+
temp
+
"\n"
}
const
today
=
new
Date
()
fs
.
writeFile
(
`./datas/
${
today
.
getFullYear
()}
.
${
today
.
getMonth
()}
.
${
today
.
getDate
()}
`
,
string
,
'utf-8'
,
(
err
)
=>
{
if
(
err
){
console
.
log
(
err
)
save
()
}
else
console
.
log
(
"저장완료!"
)
})
}
catch
(
error
)
{
console
.
log
(
error
)
save
()
}
}
module
.
exports
=
{
save
:
save
,
read
:
read
}
\ No newline at end of file
function.js
→
function
s/function
.js
View file @
51f7685
const
kakaoFunction
=
require
(
"./
functions/
kakaoFunction"
);
const
naverFunction
=
require
(
"./
functions/
naverFunction"
);
const
programmersFunction
=
require
(
"./
functions/
programmersFunction"
)
const
kakaoFunction
=
require
(
"./kakaoFunction"
);
const
naverFunction
=
require
(
"./naverFunction"
);
const
programmersFunction
=
require
(
"./programmersFunction"
)
module
.
exports
=
{
...
...
functions/kakaoFunction.js
View file @
51f7685
...
...
@@ -20,7 +20,8 @@ const makeObject = (array)=>{
result
.
push
({
title
:
tempData
[
0
],
tags
:
[],
url
:
tempData
[
tempData
.
length
-
1
]
url
:
tempData
[
tempData
.
length
-
1
],
companyName
:
"kakao"
})
for
(
let
j
of
tempData
){
if
(
j
[
0
]
==
'#'
){
...
...
@@ -50,7 +51,6 @@ const getData = async ()=>{
let
content
=
await
page
.
content
()
while
(
true
){
if
(
temp
==
content
){
console
.
log
(
"finish"
,
result
.
length
)
break
;
}
let
$
=
cheerio
.
load
(
content
,
{
decodeEntities
:
true
})
...
...
@@ -68,7 +68,6 @@ const getData = async ()=>{
temp
=
content
content
=
await
moveNextPage
(
page
)
}
console
.
log
(
result
)
return
result
}
...
...
functions/naverFunction.js
View file @
51f7685
...
...
@@ -21,14 +21,16 @@ const makeObject = (array)=>{
result
.
push
({
title
:
tempData
[
0
],
tags
:
tempData
[
3
].
split
(
'#'
).
filter
((
ele
)
=>
ele
!=
''
),
url
:
tempData
[
4
]
url
:
tempData
[
4
],
companyName
:
"naver"
})
}
else
if
(
tempData
.
length
==
4
){
result
.
push
({
title
:
tempData
[
0
],
url
:
tempData
[
3
],
tags
:
[]
tags
:
[],
companyName
:
"naver"
})
}
}
...
...
@@ -64,7 +66,6 @@ const getData = async ()=>{
})
resArr
=
result
.
split
(
'</li><li>'
)
result
=
makeObject
(
resArr
)
console
.
log
(
result
)
return
result
;
}
...
...
functions/programmersFunction.js
View file @
51f7685
...
...
@@ -20,7 +20,8 @@ const makeObject = (array)=>{
result
.
push
({
title
:
tempData
[
0
],
tags
:
[],
url
:
tempData
[
tempData
.
length
-
1
]
url
:
tempData
[
tempData
.
length
-
1
],
companyName
:
tempData
[
1
]
})
for
(
let
j
=
6
;
j
<
tempData
.
length
-
1
;
j
++
){
result
[
result
.
length
-
1
].
tags
.
push
(
tempData
[
j
])
...
...
@@ -72,11 +73,12 @@ const getData = async ()=>{
temp
=
content
content
=
await
moveNextPage
(
page
)
}
console
.
log
(
result
)
return
result
}
module
.
exports
=
{
getData
:
getData
}
\ No newline at end of file
}
getData
()
\ No newline at end of file
...
...
Please
register
or
login
to post a comment