Showing
5 changed files
with
6 additions
and
92 deletions
... | @@ -17,79 +17,7 @@ exports.GetResults=(req,res)=>{ | ... | @@ -17,79 +17,7 @@ exports.GetResults=(req,res)=>{ |
17 | const names = [name1, name2, name3] | 17 | const names = [name1, name2, name3] |
18 | req.session.names = names | 18 | req.session.names = names |
19 | const opponentClass=req.session.opponentClass | 19 | const opponentClass=req.session.opponentClass |
20 | - //덱 ID와 상대 직업 정보 체크 | ||
21 | - const DataCheck=()=>{ | ||
22 | - return new Promise((resolve,reject)=>{ | ||
23 | - if (!deckId || !opponentClass){ | ||
24 | - return reject({ | ||
25 | - code:'query_error', | ||
26 | - message:'query error', | ||
27 | - }) | ||
28 | - } | ||
29 | - resolve() | ||
30 | - }) | ||
31 | - } | ||
32 | - //현재 덱ID를 바탕으로 카드정보 가져오기 | ||
33 | - const GetCardId=()=>{ | ||
34 | - return getCardId.GetCardId(deckId) | ||
35 | - } | ||
36 | - //가져온 카드 정보를 바탕으로, hsreplay.net에서, 덱 검색하기, 검색한 결과의 html을 반환 | ||
37 | 20 | ||
38 | - //검색한 html을 가지고, 검색결과로 부터 덱의 url 파싱 | ||
39 | - const GetDeckHref=(content)=>{ | ||
40 | - return new Promise((resolve,reject)=>{ | ||
41 | - const $=cheerio.load(content) | ||
42 | - let deck=$('#decks-container > main > div.deck-list-wrapper > section > ul > li:nth-child(2) > a') | ||
43 | - const deckHref=$(deck).attr('href') | ||
44 | - console.log(deckHref) | ||
45 | - resolve(deckHref) | ||
46 | - }) | ||
47 | - } | ||
48 | - //덱의 url을 이용, 해당 덱의 정보를 나타내는 페이지 불러온 후 html로 반환 | ||
49 | - const GetDeckContent=(href)=>{ | ||
50 | - return new Promise((resolve,reject)=>{ | ||
51 | - const asyncFunc=async ()=>{ | ||
52 | - const browser=await puppeteer.launch() | ||
53 | - try{ | ||
54 | - const page=await browser.newPage() | ||
55 | - await page.setViewport({width:1366,height:768}) | ||
56 | - await page.goto(`https://hsreplay.net${href}?hl=ko`,{waitUntil: 'networkidle2'}) | ||
57 | - const content=await page.content() | ||
58 | - browser.close() | ||
59 | - return content | ||
60 | - } | ||
61 | - catch(err) | ||
62 | - { | ||
63 | - console.log(err) | ||
64 | - browser.close() | ||
65 | - } | ||
66 | - } | ||
67 | - resolve(asyncFunc()) | ||
68 | - }) | ||
69 | - } | ||
70 | - //받아온 html에서 카드 이름과 멀리건 부분 추출 | ||
71 | - const GetMulligan=(content)=>{ | ||
72 | - return new Promise((resolve,reject)=>{ | ||
73 | - const $=cheerio.load(content) | ||
74 | - let cardNames=$('.card-name') | ||
75 | - let cardWinRates=$('.table-cell') | ||
76 | - let cards=[] | ||
77 | - for(let i=0;i<cardNames.length;i++){ | ||
78 | - let cardName=$(cardNames[i]).text() | ||
79 | - let cardWinRate=$(cardWinRates[6*i]).text() | ||
80 | - //문자 삭제하고, 멀리건의 승률이 숫자로만 나타나도록 | ||
81 | - cardWinRate=cardWinRate.replace('▼','') | ||
82 | - cardWinRate=cardWinRate.replace('▲','') | ||
83 | - cardWinRate=cardWinRate.replace('%','') | ||
84 | - cards.push({cardName:cardName,cardWinRate:cardWinRate}) | ||
85 | - } | ||
86 | - //카드를 멀리건 승률 순서대로 정렬 | ||
87 | - cards.sort((a,b)=>{ | ||
88 | - return a.cardWinRate<b.cardWinRate ? 1:-1 | ||
89 | - }) | ||
90 | - resolve(cards) | ||
91 | - }) | ||
92 | - } | ||
93 | //상대 직업을 가지고 hsreplay.net에서 검색, html로 반환 | 21 | //상대 직업을 가지고 hsreplay.net에서 검색, html로 반환 |
94 | const GetOppContent=()=>{ | 22 | const GetOppContent=()=>{ |
95 | return new Promise((resolve,reject)=>{ | 23 | return new Promise((resolve,reject)=>{ |
... | @@ -130,20 +58,6 @@ exports.GetResults=(req,res)=>{ | ... | @@ -130,20 +58,6 @@ exports.GetResults=(req,res)=>{ |
130 | resolve(decks) | 58 | resolve(decks) |
131 | }) | 59 | }) |
132 | } | 60 | } |
133 | - //DataCheck() | ||
134 | - //.then(GetCardId) | ||
135 | - //.then(CrawlerMulligan) | ||
136 | - /*GetMulContent() | ||
137 | - .then(GetDeckHref) | ||
138 | - .then(GetDeckContent) | ||
139 | - .then(GetMulligan) | ||
140 | - .then((cards)=>{ | ||
141 | - return new Promise((resolve,reject)=>{ | ||
142 | - globalMulligan=cards | ||
143 | - resolve() | ||
144 | - }) | ||
145 | - }) | ||
146 | - .then(GetOppContent)*/ | ||
147 | GetOppContent() | 61 | GetOppContent() |
148 | .then(GetDeckInfo) | 62 | .then(GetDeckInfo) |
149 | .then((decks)=>{ | 63 | .then((decks)=>{ | ... | ... |
... | @@ -7,7 +7,6 @@ const charset=require('charset') | ... | @@ -7,7 +7,6 @@ const charset=require('charset') |
7 | exports.Crawl=(deckCode)=>{ | 7 | exports.Crawl=(deckCode)=>{ |
8 | return new Promise((resolve,reject)=>{ | 8 | return new Promise((resolve,reject)=>{ |
9 | request({ | 9 | request({ |
10 | - //url:`https://deck.codes/${deckCode}`, | ||
11 | url:`https://hs.protolambda.com//${deckCode}`, | 10 | url:`https://hs.protolambda.com//${deckCode}`, |
12 | encoding:null, | 11 | encoding:null, |
13 | method:'GET', | 12 | method:'GET', | ... | ... |
... | @@ -92,12 +92,11 @@ exports.getDeckname=(req,res)=>{ | ... | @@ -92,12 +92,11 @@ exports.getDeckname=(req,res)=>{ |
92 | if(USname[j].name == $(MulNames[i].children[0]).text()) | 92 | if(USname[j].name == $(MulNames[i].children[0]).text()) |
93 | break | 93 | break |
94 | } | 94 | } |
95 | - //$(MulNames[i].children[0]).text() | ||
96 | if(j != USname.length){ | 95 | if(j != USname.length){ |
97 | - if(name1 == KRname[j].name) mulRates[0] = $(MulRates[6*i]).text() | 96 | + if(name1 == KRname[j].name) mulRates[0] = $(MulRates[6*i]).text().substring(1,6) |
98 | - else if(name2 == KRname[j].name) mulRates[1] = $(MulRates[6*i]).text() | 97 | + else if(name2 == KRname[j].name) mulRates[1] = $(MulRates[6*i]).text().substring(1,6) |
99 | - else if(name3 == KRname[j].name) mulRates[2] = $(MulRates[6*i]).text() | 98 | + else if(name3 == KRname[j].name) mulRates[2] = $(MulRates[6*i]).text().substring(1,6) |
100 | - else if(name4 == KRname[j].name) mulRates[3] = $(MulRates[6*i]).text() | 99 | + else if(name4 == KRname[j].name) mulRates[3] = $(MulRates[6*i]).text().substring(1,6) |
101 | } | 100 | } |
102 | } | 101 | } |
103 | req.session.mulwinRate = mulRates | 102 | req.session.mulwinRate = mulRates | ... | ... |
... | @@ -3,6 +3,7 @@ const cheerio=require('cheerio') | ... | @@ -3,6 +3,7 @@ const cheerio=require('cheerio') |
3 | const fs=require('fs') | 3 | const fs=require('fs') |
4 | const ejs=require('ejs') | 4 | const ejs=require('ejs') |
5 | 5 | ||
6 | +//선택한 덱 이름 저장하기 | ||
6 | exports.getDeckname=(req,res)=>{ | 7 | exports.getDeckname=(req,res)=>{ |
7 | const deckname=req.body.value | 8 | const deckname=req.body.value |
8 | const DataCheck=()=>{ | 9 | const DataCheck=()=>{ | ... | ... |
... | @@ -3,6 +3,7 @@ const cheerio=require('cheerio') | ... | @@ -3,6 +3,7 @@ const cheerio=require('cheerio') |
3 | const fs=require('fs') | 3 | const fs=require('fs') |
4 | const ejs=require('ejs') | 4 | const ejs=require('ejs') |
5 | 5 | ||
6 | +//prob_result.ejs를 띄우기 위한 변수들 넘겨주기 | ||
6 | exports.getDeckname=(req,res)=>{ | 7 | exports.getDeckname=(req,res)=>{ |
7 | const deckname=req.session.deckname | 8 | const deckname=req.session.deckname |
8 | const winRate=req.session.winRate | 9 | const winRate=req.session.winRate | ... | ... |
-
Please register or login to post a comment