이재용

Delete app.js

Showing 1 changed file with 0 additions and 123 deletions
var request = require("request");
var express = require('express');
var fs=require('fs');
var puuid_url_list=[]
var events=require('events')
var key = "RGAPI-82f68b2b-8db9-4b3d-951a-7684fbb49a4c" // LOL API key
var app = express();
var eventEmitter=new events.EventEmitter();
var bodyParser = require('body-parser');
let puuid
let option
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
var name_list=[] // 유저의 아이디와 매칭되는 고유번호
var puuid_list=[] // puuid 저장을 위한 리스트
eventEmitter.setMaxListeners(200)
app.get('/', function (req, res) {
});
// 버튼 구현 (은하계(맵) 으로 이루어진 버튼들) => 버튼 클릭시 해당 url로 get 하여 데이터 획득
app.get('/galaxy',function(req,res)
{
name_url="https://kr.api.riotgames.com/tft/league/v1/challenger?api_key="+key
request(name_url,function(err,res,body)
{
let json = JSON.parse(body) //json으로 파싱
var name=json['entries']
for (var value in name)
{
name_list.push(name[value]["summonerId"])
console.log(name_list.length)
if(name_list.length==200)
{
eventEmitter.emit('name_done')
console.log("!")
}
}
}); //request1 END
eventEmitter.on("name_done",function()
{
console.log(name_list.length)
for (i=0; i<name_list.length;i++)
{
console.log("https://kr.api.riotgames.com/tft/summoner/v1/summoners/"+name_list[i])
puuid_url_list.push("https://kr.api.riotgames.com/tft/summoner/v1/summoners/"+name_list[i])
console.log(puuid_url_list)
if (puuid_url_list.length==200)
{
eventEmitter.emit("puuid_url_done")
break
}
}
});//name_done => puuid_url 설정 완료
eventEmitter.on("puuid_url_done",function(){ //puuid 가져오기
console.log(puuid_url_list)
function delay(option) {
return new Promise(resolve => //option=> request hedear 가 설정되기 전에 request를 해버리는 문제 해결하기위해 promise 사용
setTimeout(() => {
request(option,function(err,res,body)
{
puuid = JSON.parse(body)
console.log(puuid)
puuid=puuid["puuid"]
puuid_list.push(puuid)
console.log(puuid_list)
console.log(puuid_list.length)
if(puuid_list.length==200) //puuid 를 100개는 잘가져오고 100개는 못가져오는 문제 생김
{
eventEmitter.emit("puuid_find_done")
}
});
resolve(); },400) );
}
async function loop(puuid_url_list) {
{
for (i=0;i<puuid_url_list.length;i++)
{
option={
url:puuid_url_list[i], //url 값 설정은 확인 완료
method: 'GET',
headers:{
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36",
"Accept-Language": "ko-KR,ko;q=0.9,en-US;q=0.8,en;q=0.7",
"Accept-Charset": "application/x-www-form-urlencoded; charset=UTF-8",
"Origin": "https://developer.riotgames.com",
"X-Riot-Token": key}
}
await delay(option);
}
}
}
loop(puuid_url_list);
});
eventEmitter.on("puuid_find_done",function(){
res.send(puuid_list)
});
});// app end
var server = app.listen(80);
console.log("run!")