Toggle navigation
Toggle navigation
This project
Loading...
Sign in
김동근
/
WhoAreYou
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
김동근
2019-06-07 10:29:59 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
df205655844efc65ed42f66e241efe6525b343df
df205655
1 parent
499ab613
final
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
6 additions
and
92 deletions
api/card/getResultMine.js
api/deck/crawlerDeckCodes.js
api/deck/getdeckname.js
api/deck/getdeckname1.js
api/deck/getdeckname2.js
api/card/getResultMine.js
View file @
df20565
...
...
@@ -17,79 +17,7 @@ exports.GetResults=(req,res)=>{
const
names
=
[
name1
,
name2
,
name3
]
req
.
session
.
names
=
names
const
opponentClass
=
req
.
session
.
opponentClass
//덱 ID와 상대 직업 정보 체크
const
DataCheck
=
()
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
if
(
!
deckId
||
!
opponentClass
){
return
reject
({
code
:
'query_error'
,
message
:
'query error'
,
})
}
resolve
()
})
}
//현재 덱ID를 바탕으로 카드정보 가져오기
const
GetCardId
=
()
=>
{
return
getCardId
.
GetCardId
(
deckId
)
}
//가져온 카드 정보를 바탕으로, hsreplay.net에서, 덱 검색하기, 검색한 결과의 html을 반환
//검색한 html을 가지고, 검색결과로 부터 덱의 url 파싱
const
GetDeckHref
=
(
content
)
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
const
$
=
cheerio
.
load
(
content
)
let
deck
=
$
(
'#decks-container > main > div.deck-list-wrapper > section > ul > li:nth-child(2) > a'
)
const
deckHref
=
$
(
deck
).
attr
(
'href'
)
console
.
log
(
deckHref
)
resolve
(
deckHref
)
})
}
//덱의 url을 이용, 해당 덱의 정보를 나타내는 페이지 불러온 후 html로 반환
const
GetDeckContent
=
(
href
)
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
const
asyncFunc
=
async
()
=>
{
const
browser
=
await
puppeteer
.
launch
()
try
{
const
page
=
await
browser
.
newPage
()
await
page
.
setViewport
({
width
:
1366
,
height
:
768
})
await
page
.
goto
(
`https://hsreplay.net
${
href
}
?hl=ko`
,{
waitUntil
:
'networkidle2'
})
const
content
=
await
page
.
content
()
browser
.
close
()
return
content
}
catch
(
err
)
{
console
.
log
(
err
)
browser
.
close
()
}
}
resolve
(
asyncFunc
())
})
}
//받아온 html에서 카드 이름과 멀리건 부분 추출
const
GetMulligan
=
(
content
)
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
const
$
=
cheerio
.
load
(
content
)
let
cardNames
=
$
(
'.card-name'
)
let
cardWinRates
=
$
(
'.table-cell'
)
let
cards
=
[]
for
(
let
i
=
0
;
i
<
cardNames
.
length
;
i
++
){
let
cardName
=
$
(
cardNames
[
i
]).
text
()
let
cardWinRate
=
$
(
cardWinRates
[
6
*
i
]).
text
()
//문자 삭제하고, 멀리건의 승률이 숫자로만 나타나도록
cardWinRate
=
cardWinRate
.
replace
(
'▼'
,
''
)
cardWinRate
=
cardWinRate
.
replace
(
'▲'
,
''
)
cardWinRate
=
cardWinRate
.
replace
(
'%'
,
''
)
cards
.
push
({
cardName
:
cardName
,
cardWinRate
:
cardWinRate
})
}
//카드를 멀리건 승률 순서대로 정렬
cards
.
sort
((
a
,
b
)
=>
{
return
a
.
cardWinRate
<
b
.
cardWinRate
?
1
:
-
1
})
resolve
(
cards
)
})
}
//상대 직업을 가지고 hsreplay.net에서 검색, html로 반환
const
GetOppContent
=
()
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
...
...
@@ -130,20 +58,6 @@ exports.GetResults=(req,res)=>{
resolve
(
decks
)
})
}
//DataCheck()
//.then(GetCardId)
//.then(CrawlerMulligan)
/*GetMulContent()
.then(GetDeckHref)
.then(GetDeckContent)
.then(GetMulligan)
.then((cards)=>{
return new Promise((resolve,reject)=>{
globalMulligan=cards
resolve()
})
})
.then(GetOppContent)*/
GetOppContent
()
.
then
(
GetDeckInfo
)
.
then
((
decks
)
=>
{
...
...
api/deck/crawlerDeckCodes.js
View file @
df20565
...
...
@@ -7,7 +7,6 @@ const charset=require('charset')
exports
.
Crawl
=
(
deckCode
)
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
request
({
//url:`https://deck.codes/${deckCode}`,
url
:
`https://hs.protolambda.com//
${
deckCode
}
`
,
encoding
:
null
,
method
:
'GET'
,
...
...
api/deck/getdeckname.js
View file @
df20565
...
...
@@ -92,12 +92,11 @@ exports.getDeckname=(req,res)=>{
if
(
USname
[
j
].
name
==
$
(
MulNames
[
i
].
children
[
0
]).
text
())
break
}
//$(MulNames[i].children[0]).text()
if
(
j
!=
USname
.
length
){
if
(
name1
==
KRname
[
j
].
name
)
mulRates
[
0
]
=
$
(
MulRates
[
6
*
i
]).
text
()
else
if
(
name2
==
KRname
[
j
].
name
)
mulRates
[
1
]
=
$
(
MulRates
[
6
*
i
]).
text
()
else
if
(
name3
==
KRname
[
j
].
name
)
mulRates
[
2
]
=
$
(
MulRates
[
6
*
i
]).
text
()
else
if
(
name4
==
KRname
[
j
].
name
)
mulRates
[
3
]
=
$
(
MulRates
[
6
*
i
]).
text
()
if
(
name1
==
KRname
[
j
].
name
)
mulRates
[
0
]
=
$
(
MulRates
[
6
*
i
]).
text
()
.
substring
(
1
,
6
)
else
if
(
name2
==
KRname
[
j
].
name
)
mulRates
[
1
]
=
$
(
MulRates
[
6
*
i
]).
text
()
.
substring
(
1
,
6
)
else
if
(
name3
==
KRname
[
j
].
name
)
mulRates
[
2
]
=
$
(
MulRates
[
6
*
i
]).
text
()
.
substring
(
1
,
6
)
else
if
(
name4
==
KRname
[
j
].
name
)
mulRates
[
3
]
=
$
(
MulRates
[
6
*
i
]).
text
()
.
substring
(
1
,
6
)
}
}
req
.
session
.
mulwinRate
=
mulRates
...
...
api/deck/getdeckname1.js
View file @
df20565
...
...
@@ -3,6 +3,7 @@ const cheerio=require('cheerio')
const
fs
=
require
(
'fs'
)
const
ejs
=
require
(
'ejs'
)
//선택한 덱 이름 저장하기
exports
.
getDeckname
=
(
req
,
res
)
=>
{
const
deckname
=
req
.
body
.
value
const
DataCheck
=
()
=>
{
...
...
api/deck/getdeckname2.js
View file @
df20565
...
...
@@ -3,6 +3,7 @@ const cheerio=require('cheerio')
const
fs
=
require
(
'fs'
)
const
ejs
=
require
(
'ejs'
)
//prob_result.ejs를 띄우기 위한 변수들 넘겨주기
exports
.
getDeckname
=
(
req
,
res
)
=>
{
const
deckname
=
req
.
session
.
deckname
const
winRate
=
req
.
session
.
winRate
...
...
Please
register
or
login
to post a comment