index.js
15.7 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
module.exports = function (app) {
var express = require('express');
var request = require("request");
var urlencode = require('urlencode');
var apikey = "RGAPI-3aeb21da-5555-4fa8-906a-2497942cd52e"; //매일 API 바꿔주기!!
var id; //소환사ID
var accountId; //계정ID
var puuid; //특정ID
var name; //소환사이름
var profileIconId; //소환사아이콘ID
var summonerLevel; //소환사 레벨
var revisionDate; //수정날짜
var winning_rate; //승률
var leagueId = 0; //리그ID
var tier = ""; //티어
var rank = "Unranked"; //랭크
var wins = 0; //이긴 수
var losses = 0; //진 수
var leaguePoints = 0; //티어 포인트
var temp_t = new Array();
var temp_traits = new Array();
var temp_traits_num = new Array();
var temp_traits_png = new Array();
var temp_units = new Array();
var temp_units_tier = new Array();
var temp_units_items = new Array();
var temp_units_png = new Array();
var temp_all = new Array();
var temp_all_traits = new Array();
var temp_all_units = new Array();
var temp_all_units_items = new Array();
var img_tier;
var participants; //참가자
var placement; //참가자 순위
var time_eliminated; //참가자 참여시간
var traits = new Array(); //시너지
var traits_num = new Array(); //시너지갯수
var traits_png = new Array(); //시너지 PNG
var units = new Array(); //챔피언
var units_tier = new Array(); //챔피언 레벨
var units_items = new Array(); //챔피언 아이템
var units_png = new Array(); //챔피언 PNG
app.get('/', function (req, res) {
res.render('main', { title: 'Chess' });
});
app.post('/', function(req,res){
console.log('post');
name =req.body.name;
res.redirect('/search');
})
app.get('/search', function (req, res) {
name = req.query.summoner;
console.log('get');
if (res.statusCode == 200) {
console.log(name);
var summonerUrl = "https://kr.api.riotgames.com/tft/summoner/v1/summoners/by-name/" + urlencode(name) + '?api_key=' + apikey;
request(summonerUrl, function (err1, res1, body1) {
//console.log(res.statusCode);
if (res.statusCode == 200) {
var summoner_json = JSON.parse(body1);
id = summoner_json['id'];
//console.log(id);
accountId = summoner_json['accountId'];
puuid = summoner_json['puuid'];
profileIconId = summoner_json['profileIconId'];
summonerLevel = summoner_json['summonerLevel'];
revisionDate = summoner_json['revisionDate'];
profileIconId = "http://ddragon.leagueoflegends.com/cdn/10.11.1/img/profileicon/" + urlencode(profileIconId) + '.png'
var leagueUrl = "https://kr.api.riotgames.com/tft/league/v1/entries/by-summoner/" + urlencode(id) + '?api_key=' + apikey;
request(leagueUrl, function (err2, res2, body2) {
//console.log(res.statusCode);
// if (res.statusCode != 200) {
// console.log("Error ", res.statusCode);
// res.setEncoding();
// return;
// }
var league_json = JSON.parse(body2);
if (league_json[0] != null) {
leagueId = league_json[0]['leagueId'];
tier = league_json[0]['tier'];
rank = league_json[0]['rank'];
wins = league_json[0]['wins'];
losses = league_json[0]['losses'];
leaguePoints = league_json[0]['leaguePoints'];
winning_rate = Math.round((wins / (wins + losses)) * 100);
if (tier == "CHALLENGER") {
img_tier = 'images/Emblem/Challenger_Emblem.png';
} else if (tier == "GRANDMASTER") {
img_tier = 'images/Emblem/Grandmaster_Emblem.png';
} else if (tier == "MASTER") {
img_tier = 'images/Emblem/Master_Emblem.png';
} else if (tier == "DIAMOND") {
img_tier = 'images/Emblem/Diamond_Emblem.png';
} else if (tier == "PLATINUM") {
img_tier = 'images/Emblem/Platinum_Emblem.png';
} else if (tier == "GLOD") {
img_tier = 'images/Emblem/Glod_Emblem.png';
} else if (tier == "SILVER") {
img_tier = 'images/Emblem/Silver_Emblem.png';
} else if (tier == "BRONZE") {
img_tier = 'images/Emblem/Bronze_Emblem.png';
} else if (tier == "IRON") {
img_tier = 'images/Emblem/Iron_Emblem.png';
} else {
img_tier = 'images/Emblem/Unranked.png';
}
}
//console.log(img_tier);
var matchUrl = "https://asia.api.riotgames.com/tft/match/v1/matches/by-puuid/" + urlencode(puuid) + "/ids?count=10&api_key=" + apikey;
request(matchUrl, function (err3, res3, body3) {
//console.log(res.statusCode);
if (res3.statusCode == 200) {
var match_json = String(body3).replace('[', '').replace(/"/gi, '').replace(']', '').split(',');;
//console.log(match_json);
var match_info_Url = "https://asia.api.riotgames.com/tft/match/v1/matches/" + urlencode(match_json[0]) + "?api_key=" + apikey;
request(match_info_Url, function (err4, res4, body4) {
//console.log(res.statusCode);
if (res.statusCode == 200) {
// console.log("Error ", res.statusCode);
// res.setEncoding();
// return;
// }
var match_info_json = JSON.parse(body4);
for (var i = 0; i < match_info_json['metadata']['participants'].length; i++) {
if (match_info_json['info']['participants'][i]['puuid'] == puuid) {
//participants = match_info_json['metadata']['participants'][i];
placement = match_info_json['info']['participants'][i]['placement'];
//time_eliminated = Math.round(match_info_json['info']['participants'][i]['time_eliminated']);
}
}
for (var i = 0; i < match_info_json['metadata']['participants'].length; i++) {
if (match_info_json['info']['participants'][i]['puuid'] == puuid) {
var traits_array = match_info_json['info']['participants'][i]['traits'];
var count = 0;
for (var j = 0; j < traits_array.length; j++) {
if (traits_array[j]['style'] != 0) {
temp_t[count] = traits_array[j]; //trait_array에는 잘 들어감
count++;
}
}
//console.log(temp_t);
for (var j = 0; j < temp_t.length; j++) {
temp_traits.push(temp_t[j]['name']);
temp_traits_num.push(temp_t[j]['num_units']);
traits_png[j] = ("/images/traits/" + urlencode(temp_t[j]['name']) + ".png");
}
traits.push(temp_traits);
traits_num.push(temp_traits_num)
//traits_png.push(temp_traits_png);
var units_array = match_info_json['info']['participants'][i]['units'];
for (var j = 0; j < units_array.length; j++) {
temp_units.push(match_info_json['info']['participants'][i]['units'][j]['character_id']);
temp_units_tier.push(match_info_json['info']['participants'][i]['units'][j]['tier']);
temp_units_items.push(String(match_info_json['info']['participants'][i]['units'][j]['items']).replace('[', '').replace(/"/gi, '').replace(']', '').split(','));
units_png[j] = ("/images/champions/" + urlencode(match_info_json['info']['participants'][i]['units'][j]['character_id']) + ".png");
}
units.push(temp_units);
units_tier.push(temp_units_tier);
units_items.push(temp_units_items);
//units_png.push(temp_units_png);
}
// console.log(participants);
// console.log('--------------------------------------');
// console.log(placement);
// console.log('--------------------------------------');
// console.log(time_eliminated);
// console.log('--------------------------------------');
// console.log(traits);
// console.log('--------------------------------------');
// console.log(traits_num);
// console.log('--------------------------------------');
// console.log(traits_png);
// console.log('--------------------------------------');
// console.log(units);
// console.log('--------------------------------------');
// console.log(units_tier);
// console.log('--------------------------------------');
// console.log(units_items);
// console.log('--------------------------------------');
// console.log(units_png);
//temp_all.push(participants);
//temp_all.push(placement);
//temp_all.push(time_eliminated);
// temp_all_traits.push(traits);
// temp_all_traits.push(traits_num);
temp_all_traits.push(traits_png);
// temp_all_units.push(units);
// temp_all_units.push(units_tier);
// temp_all_units_items.push(units_items);
temp_all_units.push(units_png);
}
// console.log(id);
// console.log(accountId);
// console.log(puuid);
// console.log(name);
// console.log(profileIconId);
// console.log(summonerLevel);
// console.log(revisionDate);
// console.log(winning_rate);
// console.log(leagueId);
// console.log(tier);
// console.log(img_tier);
// console.log(rank);
// console.log(wins);
// console.log(losses);
// console.log(leaguePoints);
//console.log(placement);
//console.log(traits_png);
// console.log(temp_all_units);
//console.log(units_png);
res.render('index', {
title: req.params.username,
c_id: id,
c_accountId: accountId,
c_puuid: puuid,
c_name: name,
c_profileIconId: profileIconId,
c_summonerLevel: summonerLevel,
c_revisionDate: revisionDate,
c_winning_rate: winning_rate,
c_leagueId: leagueId,
c_tier: tier,
c_imgtier: img_tier,
c_rank: rank,
c_wins: wins,
c_losses: losses,
c_leaguePoints: leaguePoints,
c_temp_all: placement,
c_temp_all_traits: traits_png,
c_temp_all_units: units_png
});
}
});
}
// console.log(participants);
// console.log(placement);
// console.log(time_eliminated);
// console.log(traits_png);
// console.log(units_png);
});
});
}
});
}
});
}