app.js
3.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
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)
});