서주원

Delete some unused files

......@@ -26,7 +26,6 @@ exports.AddCards=(deckId,cards)=>{
let cardId = 0
for (let i = 0; i < cardEnUS.length; i++) {
if (cardEnUS[i].name === cardName) {
console.log(cardEnUS[i].dbfId)
cardId = cardEnUS[i].dbfId
cardName=cardName.replace('\'','\'\'')
break
......
const puppeteer=require('puppeteer');
const cheerio=require('cheerio');
exports.getDecks=(cardIds)=>{
console.log('cardIds in crawlerMulligan ',cardIds)
cardIds=JSON.stringify(cardIds)
cardIds=JSON.parse(cardIds)
console.log('stringified cardIds in crawlerMulligan ',cardIds)
console.log(cardIds[0])
let idInQuery=cardIds[0].cardId
for(let i=1;i<cardIds.length && i<10;i++){
idInQuery+= '%2C'+cardIds[i].cardId
}
console.log('idInQuery in crawlerMulligan ',idInQuery)
const getContent=()=>{
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/decks/#timeRange=LAST_30_DAYS&includedCards=${idInQuery}`,{waitUntil: 'networkidle2'})
const content=await page.content()
browser.close()
return content
}
catch(err)
{
console.log(err)
browser.close()
}
}
resolve(asyncFunc())
})
}
const getDeckHref=(content)=>{
return new Promise((resolve,reject)=>{
const $=cheerio.load(content)
let deck=$('#decks-container > div > main > div.deck-list > ul > li:nth-child(2)').find('a')
const deckHref=$(deck).attr('href')
console.log('deckHref in crawlerMulligan :',deckHref)
resolve(deckHref)
})
}
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())
})
}
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
})
console.log(cards)
resolve(cards)
})
}
getContent()
.then(getDeckHref)
.then(getDeckContent)
.then(getMulligan)
}
const puppeteer=require('puppeteer');
const cheerio=require('cheerio');
exports.getDecks=(opponentClass)=>{
const getContent=()=>{
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/decks/#timeRange=LAST_30_DAYS&playerClasses=${opponentClass}?hl=ko`,{waitUntil: 'networkidle2'})
const content=await page.content()
browser.close()
return content
}
catch(err)
{
console.log(err)
browser.close()
}
}
resolve(asyncFunc())
})
}
const getDeckInfo=(content)=>{
return new Promise((resolve,reject)=>{
const $=cheerio.load(content)
let deckNames=$('.deck-name')
let deckGames=$('.game-count')
let decks=[]
for(let i=0;i<3;i++){
let deckName=$(deckNames[i]).text()
let deckGame=$(deckGames[i]).text()
decks.push({deckTitle:deckName,deckGame:deckGame})
}
console.log(decks)
resolve(decks)
})
}
getContent()
.then(getDeckInfo)
}
const crawler=require('./crawlerMulligan')
const getCardId=require('./getCardId')
const puppeteer=require('puppeteer')
const cheerio=require('cheerio')
exports.GetMulligan=(req,res)=>{
const deckId=req.session.deckId || 113
console.log('deckId in getMulligan',deckId)
const opponentClass=req.session.opponentClass || 'PALADIN'
console.log('opponentClass in getMulligan',opponentClass)
const DataCheck=()=>{
return new Promise((resolve,reject)=>{
if (!deckId || !opponentClass){
return reject({
code:'query_error',
message:'query error',
})
}
resolve()
})
}
const GetCardId=()=>{
return getCardId.GetCardId(deckId)
}
const CrawlerMulligan=(cardIds)=>{
return crawler.getDecks(cardIds)
}
const GetContent=(cardIds)=>{
cardIds=JSON.stringify(cardIds)
cardIds=JSON.parse(cardIds)
let idInQuery=cardIds[0].cardId
for(let i=1;i<cardIds.length ;i++){
idInQuery+= '%2C'+cardIds[i].cardId
}
console.log('idInQuery in crawlerMulligan ',idInQuery)
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/decks/#timeRange=LAST_30_DAYS&includedCards=${idInQuery}`,{waitUntil: 'networkidle2'})
const content=await page.content()
browser.close()
return content
}
catch(err)
{
console.log(err)
browser.close()
}
}
resolve(asyncFunc())
})
}
const GetDeckHref=(content)=>{
return new Promise((resolve,reject)=>{
const $=cheerio.load(content)
let deck=$('#decks-container > div > main > div.deck-list > ul > li:nth-child(2)').find('a')
const deckHref=$(deck).attr('href')
console.log('deckHref in crawlerMulligan :',deckHref)
resolve(deckHref)
})
}
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())
})
}
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
})
console.log(cards)
resolve(cards)
})
}
DataCheck()
.then(GetCardId)
//.then(CrawlerMulligan)
.then(GetContent)
.then(GetDeckHref)
.then(GetDeckContent)
.then(GetMulligan)
.then((cards)=>{
return new Promise((resolve,reject)=>{
console.log('cards in getMulligan : ',cards)
resolve(cards)
})
})
.catch((err)=>{
console.log(err)
})
}
\ No newline at end of file
const crawler=require('./crawlerOpponent')
const puppeteer=require('puppeteer')
const cheerio=require('cheerio')
exports.GetOpponent=(req,res)=>{
const opponentClass=req.session.opponentClass
const DataCheck=()=>{
return new Promise((resolve,reject)=>{
if(!opponentClass){
return reject({
code:'query_error',
message:'query_error'
})
}
resolve()
})
}
const CrawlerOpponent=()=>{
return crawler.getDecks(opponentClass)
}
const GetContent=()=>{
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/decks/#timeRange=LAST_30_DAYS&playerClasses=${opponentClass}?hl=ko`,{waitUntil: 'networkidle2'})
const content=await page.content()
browser.close()
return content
}
catch(err)
{
console.log(err)
browser.close()
}
}
resolve(asyncFunc())
})
}
const GetDeckInfo=(content)=>{
return new Promise((resolve,reject)=>{
const $=cheerio.load(content)
let deckNames=$('.deck-name')
let deckGames=$('.game-count')
let decks=[]
for(let i=0;i<3;i++){
let deckName=$(deckNames[i]).text()
let deckGame=$(deckGames[i]).text()
decks.push({deckTitle:deckName,deckGame:deckGame})
}
console.log(decks)
resolve(decks)
})
}
DataCheck()
//.then(CrawlerOpponent)
.then(GetContent)
.then(GetDeckInfo)
.then((decks)=>{
return new Promise((resolve,reject)=>{
console.log('decks in getOpponent: ',decks)
resolve(decks)
})
})
.catch((err)=>{
console.log(err)
})
}
\ No newline at end of file
const crawler=require('./crawlerMulligan')
const getCardId=require('./getCardId')
const puppeteer=require('puppeteer')
const cheerio=require('cheerio')
......@@ -7,10 +6,8 @@ const ejs=require('ejs')
let globalMulligan
let globalDecks
exports.GetResult=(req,res)=>{
const deckId=req.session.deckId || 113
console.log('deckId in getMulligan',deckId)
const opponentClass=req.session.opponentClass || 'PALADIN'
console.log('opponentClass in getMulligan',opponentClass)
const deckId=req.session.deckId
const opponentClass=req.session.opponentClass
const DataCheck=()=>{
return new Promise((resolve,reject)=>{
if (!deckId || !opponentClass){
......@@ -33,7 +30,6 @@ exports.GetResult=(req,res)=>{
for(let i=1;i<cardIds.length ;i++){
idInQuery+= '%2C'+cardIds[i].cardId
}
console.log('idInQuery in crawlerMulligan ',idInQuery)
return new Promise((resolve,reject)=>{
const asyncFunc=async ()=>{
const browser=await puppeteer.launch()
......@@ -60,7 +56,7 @@ exports.GetResult=(req,res)=>{
const $=cheerio.load(content)
let deck=$('#decks-container > div > main > div.deck-list > ul > li:nth-child(2)').find('a')
const deckHref=$(deck).attr('href')
console.log('deckHref in crawlerMulligan :',deckHref)
console.log(deckHref)
resolve(deckHref)
})
}
......@@ -145,7 +141,6 @@ exports.GetResult=(req,res)=>{
decks.push({deckTitle:deckName,deckGame:deckGame})
}
}
console.log(decks)
resolve(decks)
})
}
......@@ -179,7 +174,6 @@ exports.GetResult=(req,res)=>{
})
})
.then((result)=>{
console.log('result: ',result)
fs.readFile('./views/ejs/result.ejs','utf-8',(err,data)=>{
res.writeHead(200,{'Content-Type':'text/html'})
res.end(ejs.render(data,{
......
const express=require('express')
const router=express.Router()
const getMulligan=require('./getMulligan')
const getOpponent=require('./getOpponent')
const setOpponentClass=require('./setOpponentClass')
router.get('/getmulligan',getMulligan.GetMulligan)
router.get('/getopponent',getOpponent.GetOpponent)
router.post('/setopponentclass',setOpponentClass.SetOpponentClass)
module.exports=router
\ No newline at end of file
......
const mysql=require('../mysql')
let deckId
const mysql=require('../../database/mysql')
exports.AddDeck=(deckOwner,deckTitle,deckCode)=>{
return new Promise((resolve,reject)=> {
......
const mysql=require('../../database/mysql')
exports.GetDeck=(res,req)=>{
const userId='test'
const getDeck=()=>{
return new Promise((resolve,reject)=>{
mysql.getConnection((err,connection)=>{
if (err) throw err
connection.query(`select id,deckTitle from deck where deckOwner=\'${userId}\'`,(err,results,fields)=>{
if (err) throw err
console.log(JSON.stringify(results))
resolve(JSON.stringify(results))
})
connection.release()
})
})
}
getDeck()
.then((results)=>{
return res.status(200).json(results)
})
.catch((err)=>{
//return res.status(500).json(err||err.message)
})
}
\ No newline at end of file
const mysql=require('../mysql')
const mysql=require('../../database/mysql')
exports.GetDeckId=(deckOwner,deckTitle)=>{
return new Promise((resolve,reject)=>{
......
......@@ -2,9 +2,7 @@ const express=require('express')
const router=express.Router()
const newDeck=require('./newDeck')
const getDeck=require('./getDeck')
router.post('/newdeck',newDeck.NewDeck)
router.get('/getdeck',getDeck.GetDeck)
module.exports=router
\ No newline at end of file
......
const crawler=require('./crawlerDeckCodes')
const cheerio=require('cheerio')
const addCards=require('../card/addCards')
const addDeck=require('../../database/deck/addDeck')
const getDeckId=require('../../database/deck/getDeckId')
let deckId=-1
const addDeck=require('./addDeck')
const getDeckId=require('./getDeckId')
exports.NewDeck=(req,res)=>{
const deckOwner=req.session.sid || 'test'
const deckOwner=req.session.sid
const deckTitle=req.body.deckTitle || new Date()
let deckCode=req.body.deckCode
let cards=[]
console.log(deckOwner,deckTitle,deckCode)
const DataCheck=()=>{
return new Promise((resolve,reject)=>{
......@@ -62,7 +60,6 @@ exports.NewDeck=(req,res)=>{
const asyncGetDeckId=async ()=>{
try{
const results=await getDeckId.GetDeckId(deckOwner,deckTitle)
console.log(results)
return results
}
catch (err){
......@@ -72,7 +69,6 @@ exports.NewDeck=(req,res)=>{
return asyncGetDeckId()
}
const AddCards=(deckId)=>{
console.log(`deckid in AddCards : ${deckId}`)
return addCards.AddCards(deckId,cards)
}
......
const mysql=require('../mysql')
const mysql=require('../../database/mysql')
exports.findById=(userId)=>{
return new Promise((resolve,reject)=>{
......@@ -18,7 +18,6 @@ exports.findById=(userId)=>{
}
else{
connection.release()
console.log('result in findById ',result)
resolve(result)
}
})
......
const findById=require('../../database/user/findById')
const findById=require('./findById')
const bcrypt=require('bcrypt-nodejs')
exports.Login=(req,res)=>{
......@@ -39,7 +39,6 @@ exports.Login=(req,res)=>{
})
}
if(bcrypt.compareSync(password,user[0].password)){
console.log(`Login : ${userId}`)
req.session.sid=userId
req.session.save(()=>{
res.status(200).json({userId:userId})
......
'use strict'
const express=require('express')
const session=require('express-session')
const findById=require('../../database/user/findById')
const findById=require('./findById')
const mysql=require('../../database/mysql')
const bcrypt=require('bcrypt-nodejs')
......@@ -25,7 +21,6 @@ exports.SignUp=(req,res)=>{
const findUser=async ()=>{
try{
user= await findById.findById(userId)
console.log(`user in UserCheck : ${JSON.stringify(user)}`)
return user
}
catch(err){
......
......@@ -3,10 +3,7 @@ const bodyParser=require('body-parser')
const fs=require('fs')
const session=require('express-session')
const path=require('path')
const bcrypt=require('bcrypt-nodejs')
const rp=require('request-promise')
const morgan=require('morgan')
const cheerio=require('cheerio')
const mysqlApostrophe=require('mysql-apostrophe')
const ejs=require('ejs')
const mysql=require('./database/mysql')
......@@ -65,7 +62,6 @@ app.get('/login',(req,res)=>{
})
app.post('/logout',(req,res)=>{
console.log('logout')
delete req.session.deckId
delete req.session.sid
res.status(200).json({result:'Logout Successful'})
......@@ -80,8 +76,6 @@ app.get('/decklist',(req,res)=>{
connection.query(`select id,deckTitle from deck where deckOwner=\'${req.session.sid}\'`,(err,results,fields)=>{
if (err) throw err
else{
console.log(results)
console.log('length : '+results.length)
fs.readFile('./views/ejs/decklist.ejs','utf-8',(err,data)=>{
res.writeHead(200,{'Content-Type':'text/html'})
res.end(ejs.render(data,{
......@@ -120,53 +114,15 @@ app.get('/newdeck',(req,res)=>{
}
})
const getMulligan=require('./api/card/getMulligan')
const getOpponent=require('./api/card/getOpponent')
const getResult=require('./api/card/getResult')
app.get('/result',(req,res)=>{
if(!req.session.sid)
res.redirect('/login')
else{
let mulligan
let opponentDecks;
(async ()=>{
const result=await getResult.GetResult(req,res)
console.log('hsreplay.net에서 받아오는 중')
/*setTimeout(function(){
console.log('result: ',result)
fs.readFile('./views/html/result.ejs',(err,data)=>{
res.writeHead(200,{'Content-Type':'text/html'})
res.end(ejs.render(data,{
cards:result.cards || [],
decks:result.decks || [],
}))
})
},30000)*/
await getResult.GetResult(req,res)
})()
const GetInfo=async ()=>{
return getResult.GetResult(req,res)
}
const GetCards=()=>{
return getMulligan.GetMulligan(req,res)
}
const GetDecks=(cards)=>{
mulligan=cards
return getOpponent.GetOpponent(req,res)
}
const Render=async (result)=>{
mulligan=result.cards
opponentDecks=result.decks
setTimeout(function(){
fs.readFile('./views/html/result.ejs',(err,data)=>{
res.writeHead(200,{'Content-Type':'text/html'})
res.end(ejs.render(data,{
cards:mulligan || [],
decks:opponentDecks || [],
}))
})
},1000)
}
}
})
......
const express=require('express')
const router=express.Router()
module.exports=router
\ No newline at end of file
const express=require('express')
const router=express.Router()
module.exports=router
\ No newline at end of file
const express=require('express')
const router=express.Router()
router.use('/user',require('./user'))
router.use('/deck',require('./deck'))
router.use('/card',require('./card'))
module.exports=router
\ No newline at end of file
const express=require('express')
const router=express.Router()
app.get
module.exports=router
\ No newline at end of file
......@@ -24,7 +24,7 @@
url:'/logout',
success:function(result){
alert('로그아웃 성공!')
window.location.href='/main'
window.location.href='/'
},
error:function(result){
alert('로그아웃 실패!')
......@@ -110,6 +110,7 @@
<input class="btn btn-lg btn-primary btn-block" type="button" id="backToSelectOpponent" value="상대편 직업 선택으로 돌아가기"/>
</div>
</div>
<div class="padding" style="width:100px"></div>
</div>
<!-- jQuery (부트스트랩의 자바스크립트 플러그인을 위해 필요합니다) -->
......
......@@ -151,6 +151,7 @@
</div>
<div class="col-md-5"></div>
</div>
<div class="padding" style="width:100px"></div>
</div>
<!-- jQuery (부트스트랩의 자바스크립트 플러그인을 위해 필요합니다) -->
......
......@@ -17,6 +17,12 @@
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
function onEnterLogin(event) {
var keyCode = event.keyCode;
if (keyCode == 13) {
$('#loginButton').trigger('click')
}
}
$(document).ready(function(){
$('#loginButton').click(function(){
var data=new Object()
......@@ -75,9 +81,9 @@
<form class="form-signin" id="loginForm">
<h3 class="form-signin-heading">로그인</h3>
<label class="sr-only" for="userId">아이디</label>
<input class="form-control" id="userId" autofocus="" required="" type="text" placeholder="아이디" name="userId">
<input class="form-control" id="userId" autofocus="" required="" type="text" placeholder="아이디" name="userId" >
<label class="sr-only" for="password">비밀번호</label>
<input class="form-control" id="password" required="" type="password" placeholder="비밀번호" name="password">
<input class="form-control" id="password" required="" type="password" placeholder="비밀번호" name="password" onkeydown="javascript:onEnterLogin(event)">
<br>
<div class="col-md-6">
<input class="btn btn-lg btn-primary btn-block" type="button" id="loginButton" value="로그인" />
......
......@@ -37,7 +37,6 @@
data.deckTitle=$('#deckTitle').val()
data.deckCode=$('#deckCode').val()
const stringData=JSON.stringify(data)
console.log(stringData)
alert('잠시 기다리시겠습니까?')
$.ajax({
type:'POST',
......@@ -90,7 +89,7 @@
<label class="sr-only" for="deckTitle">덱 이름</label>
<input class="form-control" id="deckTitle" autofocus="" required="" type="text" placeholder="덱 이름" name="deckTitle">
<label class="sr-only" for="deckCode">덱 코드</label>
<textarea class="form-control" id="deckCode" required="" placeholder="덱 코드" style="resize:none;height:150px;" name="deckCode"></textarea>
<textarea class="form-control" id="deckCode" required="" placeholder="#으로 시작하는 문장은 제외한 덱 코드만 입력해 주세요." style="resize:none;height:150px;" name="deckCode"></textarea>
</form>
<input type="button" class="btn btn-primary btn-block" id="newDeckButton" value="확인" />
</div>
......
......@@ -28,7 +28,6 @@
data.userId=$('#userId').val()
data.password=$('#password').val()
const stringData=JSON.stringify(data)
console.log(stringData)
$.ajax({
type:'POST',
url:'api/user/signup',
......