Toggle navigation
Toggle navigation
This project
Loading...
Sign in
전세계
/
FakerQuiz
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
1
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
전세계
2020-06-14 00:50:11 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
68a2a4fa9aa688b1686096bd9a57fd0350b9a26d
68a2a4fa
1 parent
c6b0cfbc
기능: data.json이 존재하는지 확인하고 데이터를 읽거나 크롤링
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
2 deletions
app.js
app.js
View file @
68a2a4f
...
...
@@ -9,6 +9,21 @@ const url = 'http://lol.inven.co.kr/dataninfo/proteam/progamer.php?code=135';
var
fakerData
=
{};
function
checkData
()
{
try
{
const
dataBuffer
=
fs
.
readFileSync
(
'data.json'
);
fakerData
=
dataBuffer
.
toJSON
();
console
.
log
(
fakerData
);
}
catch
(
exception
)
{
console
.
log
(
exception
);
if
(
exception
.
code
==
"ENOENT"
)
{
console
.
log
(
"데이터 파일이 존재하지 않습니다. 데이터를 크롤링합니다."
);
getData
();
}
}
}
const
getHTML
=
async
()
=>
{
try
{
return
await
axios
.
get
(
url
);
...
...
@@ -17,7 +32,8 @@ const getHTML = async () => {
}
};
getHTML
()
function
getData
()
{
getHTML
()
.
then
(
html
=>
{
var
today
=
new
Date
();
var
dateInfo
=
`
${
today
.
getFullYear
()}
/
${
today
.
getMonth
()
+
1
}
/
${
today
.
getDate
()}
`
;
...
...
@@ -150,9 +166,13 @@ getHTML()
console
.
log
(
res
)
fs
.
writeFileSync
(
'data.json'
,
JSON
.
stringify
(
res
));
});
}
app
.
get
(
'/'
,
(
req
,
res
)
=>
{
res
.
send
(
'Express Test'
);
});
app
.
listen
(
port
,
()
=>
console
.
log
(
`app listening at http://localhost:
${
port
}
`
));
\ No newline at end of file
app
.
listen
(
port
,
()
=>
console
.
log
(
`app listening at http://localhost:
${
port
}
`
));
checkData
();
\ No newline at end of file
...
...
Please
register
or
login
to post a comment