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 03:38:36 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
91ece03f43ee189794637e123e2352e005db5fa4
91ece03f
1 parent
aba0b389
버그: 연속적으로 checkData를 수행할 경우 발생하는 버그 수정(비동기 함수로 전환)
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
156 additions
and
141 deletions
app.js
app.js
View file @
91ece03
...
...
@@ -8,174 +8,191 @@ const cheerio = require('cheerio');
const
url
=
'http://lol.inven.co.kr/dataninfo/proteam/progamer.php?code=135'
;
const
version
=
'0.1'
;
const
dataFileName
=
'data.json'
;
var
fakerData
=
{};
function
checkData
()
{
async
function
checkData
()
{
try
{
const
dataBuffer
=
fs
.
readFileSync
(
'data.json'
);
console
.
log
(
"데이터 파일이 존재합니다. 데이터를 읽습니다."
);
fakerData
=
JSON
.
parse
(
dataBuffer
.
toString
());
console
.
log
(
fakerData
);
if
(
fakerData
.
version
!=
version
){
if
(
fakerData
.
version
==
version
)
{
console
.
log
(
"이미 데이터가 존재합니다."
);
}
else
if
(
fakerData
.
version
==
undefined
)
{
const
dataBuffer
=
fs
.
readFileSync
(
dataFileName
);
console
.
log
(
"데이터를 읽습니다."
);
fakerData
=
JSON
.
parse
(
dataBuffer
.
toString
());
console
.
log
(
fakerData
);
}
else
{
console
.
log
(
"버전이 다릅니다. 데이터를 크롤링합니다."
);
getData
();
await
getData
();
}
}
catch
(
exception
)
{
console
.
log
(
exception
);
if
(
exception
.
code
==
"ENOENT"
)
{
console
.
log
(
"데이터 파일이 존재하지 않습니다. 데이터를 크롤링합니다."
);
getData
();
await
getData
();
}
else
{
console
.
log
(
exception
);
}
}
return
new
Promise
(
function
(
resolve
,
reject
)
{
resolve
();
});
}
const
getHTML
=
async
()
=>
{
async
function
getHTML
()
{
try
{
return
a
wait
a
xios
.
get
(
url
);
return
axios
.
get
(
url
);
}
catch
(
error
)
{
console
.
error
(
error
);
return
null
;
}
};
function
getData
()
{
getHTML
()
.
then
(
html
=>
{
var
today
=
new
Date
();
var
dateInfo
=
`
${
today
.
getFullYear
()}
/
${
today
.
getMonth
()
+
1
}
/
${
today
.
getDate
()}
`
;
fakerData
[
'date'
]
=
dateInfo
;
async
function
getData
()
{
const
html
=
await
getHTML
();
if
(
html
==
null
)
{
return
;
}
const
$
=
cheerio
.
load
(
html
.
data
);
fakerData
[
'version'
]
=
version
;
var
today
=
new
Date
();
var
dateInfo
=
`
${
today
.
getFullYear
()}
/
${
today
.
getMonth
()
+
1
}
/
${
today
.
getDate
()}
`
;
fakerData
[
'date'
]
=
dateInfo
;
const
$
=
cheerio
.
load
(
html
.
data
);
var
playerName
=
$
(
'div#lolMain h2.block.name'
).
text
().
split
(
' '
);
fakerData
[
'name'
]
=
playerName
[
playerName
.
length
-
1
];
//#region LCK 통산 전적
var
tr
=
$
(
'table.table.log_list.log01 tbody'
).
children
();
var
td
=
tr
.
eq
(
0
).
children
();
fakerData
[
'lCK'
]
=
{
totalGamePlay
:
td
.
eq
(
1
).
text
(),
totalWin
:
td
.
eq
(
2
).
text
(),
totalLose
:
td
.
eq
(
3
).
text
(),
winRate
:
td
.
eq
(
4
).
text
(),
killPerMatch
:
td
.
eq
(
5
).
text
(),
deathPerMatch
:
td
.
eq
(
6
).
text
(),
assistPerMatch
:
td
.
eq
(
7
).
text
(),
kDA
:
td
.
eq
(
8
).
text
(),
kP
:
td
.
eq
(
9
).
text
()
};
//#endregion
//#region 최근 LCK 기록
var
recentLCKInfo
=
$
(
'div.block.scriptorium_box.scriptorium_player_info'
).
children
().
eq
(
2
);
var
mostInfo
=
recentLCKInfo
.
find
(
'div.left ul.block.list'
).
children
();
var
mostList
=
[];
var
indicatorInfo
=
recentLCKInfo
.
find
(
'div.right ul.block.bottom.clearfix'
).
children
();
mostInfo
.
each
(
function
(
i
,
elem
)
{
mostList
[
i
]
=
{
champion
:
$
(
this
).
find
(
'div.name_area p.value b'
).
text
(),
played
:
$
(
this
).
find
(
'div.play_area p.value'
).
text
(),
record
:
$
(
this
).
find
(
'div.log_area p.value'
).
text
(),
kDA
:
$
(
this
).
find
(
'div.kda_area p.value'
).
text
()
};
});
fakerData
[
'recentLCK'
]
=
{
name
:
recentLCKInfo
.
find
(
'h3.block.player_sub_title.clearfix'
).
text
(),
most
:
mostList
,
comparison_WinRate
:
indicatorInfo
.
eq
(
0
).
find
(
'div.progress.left div.text'
).
text
()
.
concat
(
" "
,
indicatorInfo
.
eq
(
0
).
find
(
'div.progress.right div.text'
).
text
()),
comparison_KDA
:
indicatorInfo
.
eq
(
1
).
find
(
'div.progress.left div.text'
).
text
()
.
concat
(
" "
,
indicatorInfo
.
eq
(
1
).
find
(
'div.progress.right div.text'
).
text
()),
comparison_KP
:
indicatorInfo
.
eq
(
2
).
find
(
'div.progress.left div.text'
).
text
()
.
concat
(
" "
,
indicatorInfo
.
eq
(
2
).
find
(
'div.progress.right div.text'
).
text
())
};
//#endregion
//#region 통산 전적
var
td
=
$
(
'div.scriptorium'
).
children
(
'div.listTable'
).
eq
(
1
).
find
(
'table tbody tr'
).
children
();
fakerData
[
'fullCareer'
]
=
{
totalGamePlay
:
td
.
eq
(
0
).
text
(),
totalWin
:
td
.
eq
(
1
).
text
(),
totalLose
:
td
.
eq
(
2
).
text
(),
winRate
:
td
.
eq
(
3
).
text
(),
totalKill
:
td
.
eq
(
4
).
text
(),
totalDeath
:
td
.
eq
(
5
).
text
(),
totalAssist
:
td
.
eq
(
6
).
text
(),
killPerMatch
:
td
.
eq
(
7
).
text
(),
deathPerMatch
:
td
.
eq
(
8
).
text
(),
assistPerMatch
:
td
.
eq
(
9
).
text
(),
kDA
:
td
.
eq
(
10
).
text
(),
kP
:
td
.
eq
(
11
).
text
()
}
//#endregion
var
playerName
=
$
(
'div#lolMain h2.block.name'
).
text
().
split
(
' '
);
fakerData
[
'name'
]
=
playerName
[
playerName
.
length
-
1
];
//#region 대회 별 전적
var
tr
=
$
(
'div.scriptorium'
).
children
(
'div.listTable'
).
eq
(
3
).
find
(
'table tbody'
).
children
();
var
competitionData
=
{};
//#region LCK 통산 전적
var
t
r
=
$
(
'table.table.log_list.log01 tbody'
).
children
();
var
td
=
tr
.
eq
(
0
).
children
(
);
tr
.
each
(
function
(
i
,
elem
)
{
var
t
d
=
$
(
this
).
children
();
var
competitionName
=
td
.
eq
(
0
).
text
().
replace
(
td
.
eq
(
0
).
find
(
'span'
).
text
(),
''
);
fakerData
[
'lCK'
]
=
{
competitionData
[
competitionName
]
=
{
name
:
competitionName
,
totalGamePlay
:
td
.
eq
(
1
).
text
(),
totalWin
:
td
.
eq
(
2
).
text
(),
totalLose
:
td
.
eq
(
3
).
text
(),
winRate
:
td
.
eq
(
4
).
text
(),
killPerMatch
:
td
.
eq
(
5
).
text
(),
deathPerMatch
:
td
.
eq
(
6
).
text
(),
assistPerMatch
:
td
.
eq
(
7
).
text
(),
kDA
:
td
.
eq
(
8
).
text
(),
kP
:
td
.
eq
(
9
).
text
()
};
//#endregion
//#region 최근 LCK 기록
var
recentLCKInfo
=
$
(
'div.block.scriptorium_box.scriptorium_player_info'
).
children
().
eq
(
2
);
var
mostInfo
=
recentLCKInfo
.
find
(
'div.left ul.block.list'
).
children
();
var
mostList
=
[];
var
indicatorInfo
=
recentLCKInfo
.
find
(
'div.right ul.block.bottom.clearfix'
).
children
();
mostInfo
.
each
(
function
(
i
,
elem
)
{
mostList
[
i
]
=
{
champion
:
$
(
this
).
find
(
'div.name_area p.value b'
).
text
(),
played
:
$
(
this
).
find
(
'div.play_area p.value'
).
text
(),
record
:
$
(
this
).
find
(
'div.log_area p.value'
).
text
(),
kDA
:
$
(
this
).
find
(
'div.kda_area p.value'
).
text
()
};
});
fakerData
[
'recentLCK'
]
=
{
name
:
recentLCKInfo
.
find
(
'h3.block.player_sub_title.clearfix'
).
text
(),
most
:
mostList
,
comparison_WinRate
:
indicatorInfo
.
eq
(
0
).
find
(
'div.progress.left div.text'
).
text
()
.
concat
(
" "
,
indicatorInfo
.
eq
(
0
).
find
(
'div.progress.right div.text'
).
text
()),
comparison_KDA
:
indicatorInfo
.
eq
(
1
).
find
(
'div.progress.left div.text'
).
text
()
.
concat
(
" "
,
indicatorInfo
.
eq
(
1
).
find
(
'div.progress.right div.text'
).
text
()),
comparison_KP
:
indicatorInfo
.
eq
(
2
).
find
(
'div.progress.left div.text'
).
text
()
.
concat
(
" "
,
indicatorInfo
.
eq
(
2
).
find
(
'div.progress.right div.text'
).
text
())
totalKill
:
td
.
eq
(
5
).
text
(),
totalDeath
:
td
.
eq
(
6
).
text
(),
totalAssist
:
td
.
eq
(
7
).
text
(),
killPerMatch
:
td
.
eq
(
8
).
text
(),
deathPerMatch
:
td
.
eq
(
9
).
text
(),
assistPerMatch
:
td
.
eq
(
10
).
text
(),
kDA
:
td
.
eq
(
11
).
text
(),
kP
:
td
.
eq
(
12
).
text
()
};
//#endregion
//#region 통산 전적
var
td
=
$
(
'div.scriptorium'
).
children
(
'div.listTable'
).
eq
(
1
).
find
(
'table tbody tr'
).
children
();
fakerData
[
'fullCareer'
]
=
{
totalGamePlay
:
td
.
eq
(
0
).
text
(),
totalWin
:
td
.
eq
(
1
).
text
(),
totalLose
:
td
.
eq
(
2
).
text
(),
winRate
:
td
.
eq
(
3
).
text
(),
totalKill
:
td
.
eq
(
4
).
text
(),
totalDeath
:
td
.
eq
(
5
).
text
(),
totalAssist
:
td
.
eq
(
6
).
text
(),
killPerMatch
:
td
.
eq
(
7
).
text
(),
deathPerMatch
:
td
.
eq
(
8
).
text
(),
assistPerMatch
:
td
.
eq
(
9
).
text
(),
kDA
:
td
.
eq
(
10
).
text
(),
kP
:
td
.
eq
(
11
).
text
()
});
fakerData
[
'competitions'
]
=
competitionData
;
//#endregion
//#region 챔피언 별 전적
var
tr
=
$
(
'div.scriptorium'
).
children
(
'div.listTable'
).
eq
(
4
).
find
(
'table tbody'
).
children
();
var
championData
=
{};
tr
.
each
(
function
(
i
,
elem
)
{
var
td
=
$
(
this
).
children
();
var
championName
=
td
.
eq
(
0
).
text
();
championData
[
championName
]
=
{
name
:
championName
,
totalGamePlay
:
td
.
eq
(
1
).
text
(),
totalWin
:
td
.
eq
(
2
).
text
(),
totalLose
:
td
.
eq
(
3
).
text
(),
winRate
:
td
.
eq
(
4
).
text
(),
totalKill
:
td
.
eq
(
5
).
text
(),
totalDeath
:
td
.
eq
(
6
).
text
(),
totalAssist
:
td
.
eq
(
7
).
text
(),
killPerMatch
:
td
.
eq
(
8
).
text
(),
deathPerMatch
:
td
.
eq
(
9
).
text
(),
assistPerMatch
:
td
.
eq
(
10
).
text
(),
kDA
:
td
.
eq
(
11
).
text
(),
kP
:
td
.
eq
(
12
).
text
()
}
//#endregion
//#region 대회 별 전적
var
tr
=
$
(
'div.scriptorium'
).
children
(
'div.listTable'
).
eq
(
3
).
find
(
'table tbody'
).
children
();
var
competitionData
=
{};
tr
.
each
(
function
(
i
,
elem
)
{
var
td
=
$
(
this
).
children
();
var
competitionName
=
td
.
eq
(
0
).
text
().
replace
(
td
.
eq
(
0
).
find
(
'span'
).
text
(),
''
);
competitionData
[
competitionName
]
=
{
name
:
competitionName
,
totalGamePlay
:
td
.
eq
(
1
).
text
(),
totalWin
:
td
.
eq
(
2
).
text
(),
totalLose
:
td
.
eq
(
3
).
text
(),
winRate
:
td
.
eq
(
4
).
text
(),
totalKill
:
td
.
eq
(
5
).
text
(),
totalDeath
:
td
.
eq
(
6
).
text
(),
totalAssist
:
td
.
eq
(
7
).
text
(),
killPerMatch
:
td
.
eq
(
8
).
text
(),
deathPerMatch
:
td
.
eq
(
9
).
text
(),
assistPerMatch
:
td
.
eq
(
10
).
text
(),
kDA
:
td
.
eq
(
11
).
text
(),
kP
:
td
.
eq
(
12
).
text
()
};
});
fakerData
[
'competitions'
]
=
competitionData
;
//#endregion
//#region 챔피언 별 전적
var
tr
=
$
(
'div.scriptorium'
).
children
(
'div.listTable'
).
eq
(
4
).
find
(
'table tbody'
).
children
();
var
championData
=
{};
tr
.
each
(
function
(
i
,
elem
)
{
var
td
=
$
(
this
).
children
();
var
championName
=
td
.
eq
(
0
).
text
();
championData
[
championName
]
=
{
name
:
championName
,
totalGamePlay
:
td
.
eq
(
1
).
text
(),
totalWin
:
td
.
eq
(
2
).
text
(),
totalLose
:
td
.
eq
(
3
).
text
(),
winRate
:
td
.
eq
(
4
).
text
(),
totalKill
:
td
.
eq
(
5
).
text
(),
totalDeath
:
td
.
eq
(
6
).
text
(),
totalAssist
:
td
.
eq
(
7
).
text
(),
killPerMatch
:
td
.
eq
(
8
).
text
(),
deathPerMatch
:
td
.
eq
(
9
).
text
(),
assistPerMatch
:
td
.
eq
(
10
).
text
(),
kDA
:
td
.
eq
(
11
).
text
(),
kP
:
td
.
eq
(
12
).
text
()
}
});
fakerData
[
'champions'
]
=
championData
;
//#endregion
return
fakerData
;
})
.
then
(
res
=>
{
console
.
log
(
res
)
fs
.
writeFileSync
(
'data.json'
,
JSON
.
stringify
(
res
));
});
fakerData
[
'champions'
]
=
championData
;
//#endregion
console
.
log
(
fakerData
);
fs
.
writeFileSync
(
dataFileName
,
JSON
.
stringify
(
fakerData
));
return
new
Promise
(
function
(
resolve
,
reject
)
{
resolve
();
});
}
...
...
@@ -184,6 +201,4 @@ app.get('/', (req, res) => {
res
.
send
(
'Express Test'
);
});
app
.
listen
(
port
,
()
=>
console
.
log
(
`app listening at http://localhost:
${
port
}
`
));
checkData
();
\ No newline at end of file
app
.
listen
(
port
,
()
=>
console
.
log
(
`app listening at http://localhost:
${
port
}
`
));
\ No newline at end of file
...
...
Please
register
or
login
to post a comment