이재용

have to slove dependency

Showing 1 changed file with 125 additions and 0 deletions
var request = require("request");
var express = require('express');
var puuid_url_list=[]
var events=require('events')
var key = "RGAPI-78e43419-9016-45e3-8300-1e5febc8ef54" // LOL API key
var app = express();
var eventEmitter=new events.EventEmitter();
var bodyParser = require('body-parser');
let puuid
let option
let checking=1
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
var name_list=[] // 유저의 아이디와 매칭되는 고유번호
var puuid_list=[] // puuid 저장을 위한 리스트
app.get('/', function (req, res) {
res.send("My galaxy") // 버튼 구현 (은하계(맵) 으로 이루어진 버튼들) => 버튼 클릭시 해당 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"])
}
eventEmitter.emit('name_done')
}); //request1 END
eventEmitter.on('name_done',function() //url 설정
{
for (i=0;i<name_list.length;i++)
{
puuid_url_list.push("https://kr.api.riotgames.com/tft/summoner/v1/summoners/"+name_list[i])
}
eventEmitter.emit("setting_done")
});//setting end
eventEmitter.on("setting_done",function() //puuid 가져오기
{
if (checking==1)
{
option={
url:puuid_url_list[0],
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}
}
eventEmitter.emit("run_request") //for 문 마다 run_request를 한다.
}
else
{
for (i=1;i<name_list.length;i++)
{
eventEmitter.emit("run_request")
eventEmitter.on('run_request2',function(){
option={
url:puuid_url_list[i],
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}
}
//for 문 마다 run_request를 한다.
});
}
}
eventEmitter.emit('data_received')
});//event-setting done end
eventEmitter.on('run_request',function()//자료 가져오기 (puuid)
{
request(option,function(err,res,body)
{
puuid = JSON.parse(body)
puuid=puuid["puuid"]
puuid_list.push(puuid)
if (checking==1)
{
checking=2
eventEmitter.emit("setting_done")
}
else
{
eventEmitter.emit("run_request2")
}
});
}); //run_request end
});// app end
var server = app.listen(80);
eventEmitter.on('data_received',function(){
console.log(name_list);
console.log(puuid_list)
});
\ No newline at end of file