황성연

반복문 처리

1 -module.exports = function(app){ 1 +module.exports = function (app) {
2 - 2 +
3 - var request = require("request"); 3 + var request = require("request");
4 - var urlenconde = require('urlencode'); 4 + var urlenconde = require('urlencode');
5 - var apikey = "RGAPI-b69c36b5-e5c6-4698-af93-4be17fc8a7e4"//api 5 + var apikey = "RGAPI-b69c36b5-e5c6-4698-af93-4be17fc8a7e4"//api
6 - 6 +
7 - var profileIconId; //아이콘 번호 7 + var profileIconId; //아이콘 번호
8 - var revisionDate; //수정날짜 8 + var revisionDate; //수정날짜
9 - var id; //소환사ID 9 + var id; //소환사ID
10 - var accountId; //계정Id 10 + var accountId; //계정Id
11 - var name; //소환사 이름 11 + var name; //소환사 이름
12 - var summonerLevel; //소환사 12 + var summonerLevel; //소환사
13 - var rotation_champ = new Array(); 13 + var rotation_champ = new Array();
14 - var rotation_champ_newbie = new Array(); 14 + var rotation_champ_newbie = new Array();
15 - 15 + var champion;
16 - app.get('/', function(req, res) { 16 + var champ_count = 0;
17 - res.render('main', { title: 'LOL INFO' }); 17 + var spell;
18 - }); 18 + var match;
19 - 19 +
20 - app.get('/search/:username/', function(req, res, next){ 20 + app.get('/', function (req, res) {
21 - //롤 api url 21 + var rotation_name = new Array();
22 - name = req.params.username; 22 + var rotation_name_newbie = new Array();
23 - var nameUrl = "https://kr.api.riotgames.com/lol/summoner/v4/summoners/by-name/" + urlenconde(name)+"?api_key="+ apikey; 23 + var rotation_pic = new Array();
24 - request(nameUrl,function(error,response,body){ 24 + var rotation_pic_newbie = new Array();
25 - 25 +
26 - // 요청에 대한 응답이 성공적으로 왔는지 검사. 26 + var rotationUrl = "https://kr.api.riotgames.com/lol/platform/v3/champion-rotations?api_key=" + apikey;
27 - // status code가 200이 아니면 오류가 있었던 것으로 간주하고 함수 종료. 27 + request(rotationUrl, function (error, response, body) {
28 - console.log('response code ', response.statusCode); 28 + var info_rotation = JSON.parse(body);
29 - if (response.statusCode != 200) { 29 + var keys = Object.keys(info_rotation);
30 - console.log('Error with response code22 ', response.statusCode); 30 + for (var k = 0; k < info_rotation[keys[0]].length; k++)
31 - res.end(); 31 + rotation_champ[k] = info_rotation[keys[0]][k];
32 - return; 32 + for (var k = 0; k < info_rotation[keys[1]].length; k++)
33 - } 33 + rotation_champ_newbie[k] = info_rotation[keys[1]][k];
34 - 34 +
35 - var info_summoner_json = JSON.parse(body); 35 +
36 - 36 + var staticUrl = "http://ddragon.leagueoflegends.com/cdn/10.11.1/data/en_US/champion.json";
37 - accountId = info_summoner_json["accountId"]; 37 + request(staticUrl, function (error, response, body) {
38 - id = info_summoner_json["id"]; 38 + var info_static_champ_json = JSON.parse(body);
39 - summoner = info_summoner_json["name"]; 39 + champion = info_static_champ_json["data"];
40 - profileIconId = info_summoner_json["profileIconId"]; 40 +
41 - summonerLevel = info_summoner_json["summonerLevel"]; 41 + for (var name in champion) {
42 - revisionDate = info_summoner_json["revisionDate"]; 42 + if (champion.hasOwnProperty(name)) {
43 - console.log(info_summoner_json); 43 + champ_count++;
44 - 44 + }
45 - var champUrl = "https://kr.api.riotgames.com/lol/champion-mastery/v4/champion-masteries/by-summoner/" + urlenconde(id) + "?api_key=" + apikey; 45 + }
46 - request(champUrl,function(error,response,body){ 46 +
47 - var info_champ_json = JSON.parse(body); 47 + for (var i = 0; i < champ_count; i++) {
48 - var champ_point = new Array(); 48 + for (js in champion) {
49 - var champ_id = new Array(); 49 + for (j in champion[js]) {
50 - var champ_name = new Array(); 50 + if (champion[js]["key"] == rotation_champ[i]) {
51 - var rotation_name = new Array(); 51 + rotation_name[i] = champion[js]["id"];
52 - var rotation_name_newbie = new Array(); 52 + rotation_pic[i] = "http://ddragon.leagueoflegends.com/cdn/10.11.1/img/champion/" + rotation_name[i] + ".png";
53 - var champ_pic = new Array(); 53 + }
54 - var rotation_pic =new Array(); 54 + if (champion[js]["key"] == rotation_champ_newbie[i]) {
55 - var rotation_pic_newbie = new Array(); 55 + rotation_name_newbie[i] = champion[js]["id"]
56 - var champions_length = Object.keys(info_champ_json).length; 56 + rotation_pic_newbie[i] = "http://ddragon.leagueoflegends.com/cdn/10.11.1/img/champion/" + rotation_name_newbie[i] + ".png";
57 - 57 + }
58 - // status code가 200이 아니면 종료.
59 - if (info_champ_json["status"] != undefined) {
60 - if (info_champ_json["status"]["status_code"] != 200) {
61 - console.log('Error with response code11 ', info_champ_json["status"]["status_code"]);
62 - res.end();
63 - return;
64 - }
65 } 58 }
66 - 59 + }
67 - for(var i=0; i < champions_length; i++){ 60 + }
68 - champ_point[i] = (info_champ_json[i]["championPoints"]); 61 + res.render('main', {
69 - champ_id[i] = info_champ_json[i]["championId"]; 62 + title: 'LOL INFO',
63 + c_rotation: rotation_pic,
64 + c_rotation_newbie: rotation_pic_newbie
65 + });
66 + });
67 + });
68 + });
69 +
70 +
71 + app.get('/search/:username/', function (req, res, next) {
72 + //롤 api url
73 + name = req.params.username;
74 + var nameUrl = "https://kr.api.riotgames.com/lol/summoner/v4/summoners/by-name/" + urlenconde(name) + "?api_key=" + apikey;
75 + request(nameUrl, function (error, response, body) {
76 +
77 + // 요청에 대한 응답이 성공적으로 왔는지 검사.
78 + // status code가 200이 아니면 오류가 있었던 것으로 간주하고 함수 종료.
79 + console.log('response code ', response.statusCode);
80 + if (response.statusCode != 200) {
81 + console.log('Error with response code22 ', response.statusCode);
82 + res.end();
83 + return;
84 + }
85 +
86 + var info_summoner_json = JSON.parse(body);
87 +
88 + accountId = info_summoner_json["accountId"];
89 + id = info_summoner_json["id"];
90 + summoner = info_summoner_json["name"];
91 + profileIconId = info_summoner_json["profileIconId"];
92 + summonerLevel = info_summoner_json["summonerLevel"];
93 + revisionDate = info_summoner_json["revisionDate"];
94 + console.log(info_summoner_json);
95 +
96 +
97 + var spellUrl = "http://ddragon.leagueoflegends.com/cdn/10.12.1/data/en_US/summoner.json";
98 + request(spellUrl, function (error, response, body) {
99 + spell = (JSON.parse(body)).data;
100 +
101 +
102 + var userLeagueUrl = "https://kr.api.riotgames.com/lol/league/v4/entries/by-summoner/" + urlenconde(id) + "?api_key=" + apikey;
103 + request(userLeagueUrl, function (error, response, body) {
104 + var info_user_league_json = JSON.parse(body);
105 + if (info_user_league_json[0] != null) {
106 + var wins = info_user_league_json[0]["wins"];
107 + var losses = info_user_league_json[0]["losses"];
108 + var tier = info_user_league_json[0]["tier"];
109 + var rank = info_user_league_json[0]["rank"];
110 + var leaguePoints = info_user_league_json[0]["leaguePoints"];
111 + var img_tier;
112 + if (tier == "MASTER") {
113 + img_tier = "/ranked-emblems/Emblem_Master.png";
114 + } else if (tier == "CHALLENGER") {
115 + img_tier = "/ranked-emblems/Emblem_Challenger.png";
116 + } else if (tier == "DIAMOND") {
117 + img_tier = "/ranked-emblems/Emblem_Diamond.png"
118 + } else if (tier == "PLATINUM") {
119 + img_tier = "/ranked-emblems/Emblem_Platinum.png"
120 + } else if (tier == "GRANDMASTER") {
121 + img_tier = "/ranked-emblems/Emblem_Grandmaster.png"
122 + } else if (tier == "GOLD") {
123 + img_tier = "/ranked-emblems/Emblem_Gold.png"
124 + } else if (tier == "SILVER") {
125 + img_tier = "/ranked-emblems/Emblem_Silver.png"
126 + } else if (tier == "BRONZE") {
127 + img_tier = "/ranked-emblems/Emblem_Bronze.png"
128 + } else {
129 + img_tier = "/ranked-emblems/Emblem_Iron.png"
70 } 130 }
71 - var rotationUrl = "https://kr.api.riotgames.com/lol/platform/v3/champion-rotations?api_key="+apikey; 131 + res.render('userinfo', {
72 - request(rotationUrl,function(error,response,body){ 132 + title: req.params.username,
73 - var info_rotation = JSON.parse(body); 133 + c_summoner: summoner,
74 - var keys = Object.keys(info_rotation); 134 + c_wins: wins,
75 - for(var k =0; k < info_rotation[keys[0]].length;k++) 135 + c_losses: losses,
76 - rotation_champ[k] = info_rotation[keys[0]][k]; 136 + c_tier: tier,
77 - for(var k =0; k < info_rotation[keys[1]].length;k++) 137 + c_imgtier: img_tier,
78 - rotation_champ_newbie[k] = info_rotation[keys[1]][k]; 138 + c_rank: rank,
79 - 139 + c_leaguePoint: leaguePoints
80 - 140 + });
81 - 141 + }
82 - 142 +
83 -
84 - var staticUrl = "http://ddragon.leagueoflegends.com/cdn/10.11.1/data/en_US/champion.json";
85 - request(staticUrl,function(error,response,body) {
86 - var info_static_champ_json = JSON.parse(body);
87 - console.log(info_static_champ_json.data);
88 - var champion = info_static_champ_json["data"];
89 - var champ_count = 0;
90 -
91 - for(var name in champion) {
92 - if(champion.hasOwnProperty(name)) {
93 - champ_count++;
94 - }
95 - }
96 143
97 - for(var i=0; i < champ_count; i++){ 144 + });
98 - for(js in champion) { 145 + });
99 - for(j in champion[js]) { 146 + });
100 - if(champion[js]["key"] == champ_id[i]){ 147 + });
101 - champ_name[i] = champion[js]["id"]; 148 +
102 - champ_pic[i] = "http://ddragon.leagueoflegends.com/cdn/10.11.1/img/champion/"+champ_name[i]+".png"; 149 +
103 - 150 + app.get('/search/:username/spectator', function (req, res, next) {
104 - } 151 + if (true) {
105 - } 152 + console.log(id);
106 - } 153 + var spectatorUrl = "https://kr.api.riotgames.com/lol/spectator/v4/active-games/by-summoner/" + urlenconde(id) + "?api_key=" + apikey;
154 + request(spectatorUrl, function (error, response, body) {
155 + var flag = true; // 실시간 경기 여부
156 +
157 + if (response.statusCode != 200)
158 + flag = false;
159 +
160 + var spectator;
161 + if (flag) { // 실시간 경기 진행중이면
162 + var spectator_json = JSON.parse(body);
163 + console.log(spectator_json);
164 + var spec_bannedChamp = spectator_json.bannedChampions;
165 + var spec_gameId = spectator_json.gameId;
166 + var spec_gameLength = spectator_json.gameLength;
167 + var spec_gameMode = spectator_json.gameMode;
168 + var spec_QueueId = spectator_json.gameQueueConfigId;
169 + var spec_mapId = spectator_json.mapId;
170 + var spec_participants = spectator_json.participants;
171 +
172 + var spec_bannedChamp_image = new Array();
173 + var spec_selectedChamp_image = new Array();
174 + var spec_summonerName = new Array();
175 + var spec_spellId = new Array();
176 + var spec_spell_image = new Array();
177 + for (var i = 0; i < 10; i++) {
178 + spec_summonerName.push(spec_participants[i].summonerName);
179 + spec_spellId.push(spec_participants[i].spell1Id);
180 + spec_spellId.push(spec_participants[i].spell2Id);
181 + }
182 +
183 + for (var i = 0; i < 10; i++) {
184 + for (key in champion) {
185 + if (champion.hasOwnProperty(key) && champion[key].key == spec_bannedChamp[i].championId) {
186 + spec_bannedChamp_image.push("http://ddragon.leagueoflegends.com/cdn/10.11.1/img/champion/" + champion[key].id + ".png");
107 } 187 }
108 - for(var i=0; i < champ_count; i++){ 188 + if (champion.hasOwnProperty(key) && champion[key].key == spec_participants[i].championId) {
109 - for(js in champion){ 189 + spec_selectedChamp_image.push("http://ddragon.leagueoflegends.com/cdn/10.11.1/img/champion/" + champion[key].id + ".png");
110 - for(j in champion[js]){
111 - if(champion[js]["key"] == rotation_champ[i]){
112 - rotation_name[i] = champion[js]["id"];
113 - rotation_pic[i] = "http://ddragon.leagueoflegends.com/cdn/10.11.1/img/champion/"+rotation_name[i]+".png";
114 - }
115 - if(champion[js]["key"] == rotation_champ_newbie[i]){
116 - rotation_name_newbie[i] = champion[js]["id"]
117 - rotation_pic_newbie[i] = "http://ddragon.leagueoflegends.com/cdn/10.11.1/img/champion/"+rotation_name_newbie[i]+".png";
118 - }
119 - }
120 - }
121 } 190 }
122 - 191 + }
123 - var userLeagueUrl = "https://kr.api.riotgames.com/lol/league/v4/entries/by-summoner/"+ urlenconde(id)+"?api_key=" + apikey; 192 + }
124 - request(userLeagueUrl,function(error,response,body){
125 - var info_user_league_json = JSON.parse(body);
126 - //console.log("userLeagueUrl:", userLeagueUrl);
127 - if(info_user_league_json[0] != null){
128 - var leagueId = info_user_league_json[0]["leagueId"];
129 - var wins = info_user_league_json[0]["wins"];
130 - var losses = info_user_league_json[0]["losses"];
131 - var leagueName = info_user_league_json[0]["leagueName"]
132 - var tier = info_user_league_json[0]["tier"];
133 - var rank = info_user_league_json[0]["rank"];
134 - var leaguePoints = info_user_league_json[0]["leaguePoints"];
135 - var img_tier;
136 - if(tier == "MASTER"){
137 - img_tier = "/ranked-emblems/Emblem_Master.png";
138 - }else if(tier == "CHALLENGER"){
139 - img_tier = "/ranked-emblems/Emblem_Challenger.png";
140 - }else if(tier == "DIAMOND"){
141 - img_tier = "/ranked-emblems/Emblem_Diamond.png"
142 - }else if(tier == "PLATINUM"){
143 - img_tier = "/ranked-emblems/Emblem_Platinum.png"
144 - }else if(tier == "GRANDMASTER"){
145 - img_tier = "/ranked-emblems/Emblem_Grandmaster.png"
146 - }else if(tier == "GOLD"){
147 - img_tier = "/ranked-emblems/Emblem_Gold.png"
148 - }else if(tier == "SILVER"){
149 - img_tier = "/ranked-emblems/Emblem_Silver.png"
150 - }else if(tier == "BRONZE"){
151 - img_tier ="/ranked-emblems/Emblem_Bronze.png"
152 - }else{
153 - img_tier = "/ranked-emblems/Emblem_Iron.png"
154 - }
155 -
156 193
194 + for (var i = 0; i < 20; i++) {
195 + for (key in spell) {
196 + if (spell.hasOwnProperty(key) && spell[key].key == spec_spellId[i]) {
197 + spec_spell_image.push("http://ddragon.leagueoflegends.com/cdn/10.12.1/img/spell/" + spell[key].id + ".png");
198 + }
199 + }
200 + }
201 +
202 + spectator = {
203 + "summonerName": spec_summonerName,
204 + "selectedChamp_image": spec_selectedChamp_image,
205 + "bannedChamp_image": spec_bannedChamp_image,
206 + "spell_image": spec_spell_image
207 + };
208 + }
209 + console.log(flag);
210 + console.log(spectator);
211 + res.render('main', {
212 + flag: flag,
213 + spectator: spectator
214 + });
215 + });
216 + }
217 + else {
218 + res.send();
219 + }
220 + });
221 +
222 + app.get('/search/:username/match', function (req, res, next) {
223 + // 게임정보 불러오기
224 + var matchUrl = "https://kr.api.riotgames.com/lol/match/v4/matchlists/by-account/" + accountId + "?api_key=" + apikey;
225 + request(matchUrl, function (error, response, body) {
226 + var match_json = JSON.parse(body).matches;
227 +
228 + var match_gameId = new Array();
229 + var match_mychamp = new Array();
230 +
231 + var count = 0, idx = 0;
232 + while (count < 5) {
233 + // 420 : 5x5 솔로랭크, 440 : 5x5 자유랭크
234 + if (match_json[idx].queue == 420 || match_json[idx].queue == 440) {
235 + match_gameId.push(match_json[idx].gameId);
236 + match_mychamp.push(match_json[idx].champion);
237 + count++;
238 + }
239 + idx++;
240 + }
241 +
242 + match = new Array();
243 +
244 +
245 + for (var i = 0; i < 5; i++) {
246 + // teamId: 100 = Blue , teamId:200 = Red
247 + var match1Url = "https://kr.api.riotgames.com/lol/match/v4/matches/" + match_gameId[i] + "?api_key=" + apikey;
248 + request(match1Url, function (error, response, body) {
249 + var match1_json = JSON.parse(body);
250 + var match1_gameLength = match_json.gameDuration;
251 + var match1_teams = match1_json.teams;
252 + var match1_participants = match1_json.participants;
253 + var match1_participantIdentities = match1_json.participantIdentities;
254 +
255 + var match1_bannedChamp = new Array();
256 + var match1_selectedChamp = new Array();
257 + var match1_spellId = new Array();
258 + var match1_summonerName = new Array();
259 + var match1_kda = new Array();
260 +
261 + var match1_bannedChamp_image = new Array();
262 + var match1_selectedChamp_image = new Array();
263 + var match1_spell_image = new Array();
264 +
265 + for (var i = 0; i < 2; i++) {
266 + var temp = match1_teams[i].bans;
267 + for (var j = 0; j < 5; j++) {
268 + match1_bannedChamp.push(temp[j].championId);
157 } 269 }
158 - 270 + }
159 - var spellUrl = "http://ddragon.leagueoflegends.com/cdn/10.12.1/data/en_US/summoner.json"; 271 +
160 - request(spellUrl,function(error,response,body){ 272 + for (var i = 0; i < 10; i++) {
161 - var spell = (JSON.parse(body)).data; 273 + match1_selectedChamp.push(match1_participants[i].championId);
162 - console.log(spell); 274 + match1_spellId.push(match1_participants[i].spell1Id);
163 - 275 + match1_spellId.push(match1_participants[i].spell2Id);
164 - 276 + match1_summonerName.push((match1_participantIdentities[i].player).summonerName);
165 - var spectatorUrl = "https://kr.api.riotgames.com/lol/spectator/v4/active-games/by-summoner/" + urlenconde(id) + "?api_key=" + apikey; 277 + var obj = {
166 - request(spectatorUrl,function(error,response,body) { 278 + 'k': (match1_participants[i].stats).kills,
167 - var flag = true; // 실시간 경기 여부 279 + 'd': (match1_participants[i].stats).deaths,
168 - 280 + 'a': (match1_participants[i].stats).assists
169 - if(response.statusCode != 200) 281 + };
170 - flag = false; 282 + match1_kda.push(obj);
171 - 283 + }
172 - if(flag) { // 실시간 경기 진행중이면 284 +
173 - var spectator_json = JSON.parse(body); 285 + for (var i = 0; i < 10; i++) {
174 - console.log(spectator_json); 286 + for (key in champion) {
175 - var spec_bannedChamp = spectator_json.bannedChampions; 287 + if (champion.hasOwnProperty(key) && champion[key].key == match1_bannedChamp[i]) {
176 - var spec_gameId = spectator_json.gameId; 288 + match1_bannedChamp_image.push("http://ddragon.leagueoflegends.com/cdn/10.11.1/img/champion/" + champion[key].id + ".png");
177 - var spec_gameLength = spectator_json.gameLength;
178 - var spec_gameMode = spectator_json.gameMode;
179 - var spec_QueueId = spectator_json.gameQueueConfigId;
180 - var spec_mapId = spectator_json.mapId;
181 - var spec_participants = spectator_json.participants;
182 -
183 - var spec_bannedChamp_image = new Array();
184 - var spec_selectedChamp_image = new Array();
185 - var spec_summonerName = new Array();
186 - var spec_spellId = new Array();
187 - var spec_spell_image = new Array();
188 - for(var i=0; i<10; i++){
189 - spec_summonerName.push(spec_participants[i].summonerName);
190 - spec_spellId.push(spec_participants[i].spell1Id);
191 - spec_spellId.push(spec_participants[i].spell2Id);
192 - }
193 -
194 - for(var i=0; i<10; i++) {
195 - for(key in champion) {
196 - if(champion.hasOwnProperty(key) && champion[key].key == spec_bannedChamp[i].championId) {
197 - spec_bannedChamp_image.push("http://ddragon.leagueoflegends.com/cdn/10.11.1/img/champion/"+champion[key].id+".png");
198 - }
199 - if(champion.hasOwnProperty(key) && champion[key].key == spec_participants[i].championId) {
200 - spec_selectedChamp_image.push("http://ddragon.leagueoflegends.com/cdn/10.11.1/img/champion/"+champion[key].id+".png");
201 - }
202 - }
203 - }
204 -
205 - for(var i=0; i<20; i++) {
206 - for(key in spell){
207 - if(spell.hasOwnProperty(key) && spell[key].key == spec_spellId[i]){
208 - spec_spell_image.push("http://ddragon.leagueoflegends.com/cdn/10.12.1/img/spell/"+spell[key].id+".png");
209 - }
210 - }
211 - }
212 -
213 - var spectator = {
214 - "summonerName" : spec_summonerName,
215 - "selectedChamp_image" : spec_selectedChamp_image,
216 - "bannedChamp_image" : spec_bannedChamp_image,
217 - "spell_image" : spec_spell_image
218 - };
219 } 289 }
290 + if (champion.hasOwnProperty(key) && champion[key].key == match1_selectedChamp[i]) {
291 + match1_selectedChamp_image.push("http://ddragon.leagueoflegends.com/cdn/10.11.1/img/champion/" + champion[key].id + ".png");
292 + }
293 + }
294 + }
220 295
296 + for (var i = 0; i < 20; i++) {
297 + for (key in spell) {
298 + if (spell.hasOwnProperty(key) && spell[key].key == match1_spellId[i]) {
299 + match1_spell_image.push("http://ddragon.leagueoflegends.com/cdn/10.12.1/img/spell/" + spell[key].id + ".png");
300 + }
301 + }
302 + }
221 303
222 - // 게임정보 불러오기 304 + var match_temp = {
223 - var matchUrl = "https://kr.api.riotgames.com/lol/match/v4/matchlists/by-account/" + accountId + "?api_key=" + apikey; 305 + "summonerName": match1_summonerName,
224 - request(matchUrl,function(error,response,body) { 306 + "selectedChamp_image": match1_selectedChamp_image,
225 - var match_json = JSON.parse(body).matches; 307 + "bannedChamp_image": match1_bannedChamp_image,
226 - console.log(match_json); 308 + "spell_image": match1_spell_image,
227 - 309 + "kda": match1_kda
228 - var match_gameId = new Array(); 310 + };
229 - var match_mychamp = new Array(); 311 +
230 - 312 + match.push(match_temp);
231 - var count=0 , idx=0;
232 - while(count<5){
233 - // 420 : 5x5 솔로랭크, 440 : 5x5 자유랭크
234 - if(match_json[idx].queue == 420 || match_json[idx].queue == 440){
235 - match_gameId.push(match_json[idx].gameId);
236 - match_mychamp.push(match_json[idx].champion);
237 - count++;
238 - }
239 - idx++;
240 - }
241 -
242 - // teamId: 100 = Blue , teamId:200 = Red
243 - var match1Url = "https://kr.api.riotgames.com/lol/match/v4/matches/" + match_gameId[0] + "?api_key=" + apikey;
244 - request(match1Url,function(error,response,body){
245 - var match1_json = JSON.parse(body);
246 - var match1_gameLength = match_json.gameDuration;
247 - var match1_teams = match1_json.teams;
248 - var match1_participants = match1_json.participants;
249 - var match1_participantIdentities = match1_json.participantIdentities;
250 -
251 - var match1_bannedChamp = new Array();
252 - var match1_selectedChamp = new Array();
253 - var match1_spellId = new Array();
254 - var match1_summonerName = new Array();
255 - var match1_kda = new Array();
256 -
257 - var match1_bannedChamp_image = new Array();
258 - var match1_selectedChamp_image = new Array();
259 - var match1_spell_image = new Array();
260 -
261 - for(var i=0; i<2; i++){
262 - var temp = match1_teams[i].bans;
263 - for(var j=0; j<5; j++){
264 - match1_bannedChamp.push(temp[j].championId);
265 - }
266 - }
267 -
268 - for(var i=0; i<10; i++){
269 - match1_selectedChamp.push(match1_participants[i].championId);
270 - match1_spellId.push(match1_participants[i].spell1Id);
271 - match1_spellId.push(match1_participants[i].spell2Id);
272 - match1_summonerName.push((match1_participantIdentities[i].player).summonerName);
273 - var obj = {
274 - 'k' : (match1_participants[i].stats).kills,
275 - 'd' : (match1_participants[i].stats).deaths,
276 - 'a' : (match1_participants[i].stats).assists
277 - };
278 - match1_kda.push(obj);
279 - }
280 -
281 - for(var i=0; i<10; i++) {
282 - for(key in champion) {
283 - if(champion.hasOwnProperty(key) && champion[key].key == match1_bannedChamp[i]) {
284 - match1_bannedChamp_image.push("http://ddragon.leagueoflegends.com/cdn/10.11.1/img/champion/"+champion[key].id+".png");
285 - }
286 - if(champion.hasOwnProperty(key) && champion[key].key == match1_selectedChamp[i]) {
287 - match1_selectedChamp_image.push("http://ddragon.leagueoflegends.com/cdn/10.11.1/img/champion/"+champion[key].id+".png");
288 - }
289 - }
290 - }
291 -
292 - for(var i=0; i<20; i++) {
293 - for(key in spell){
294 - if(spell.hasOwnProperty(key) && spell[key].key == match1_spellId[i]){
295 - match1_spell_image.push("http://ddragon.leagueoflegends.com/cdn/10.12.1/img/spell/"+spell[key].id+".png");
296 - }
297 - }
298 - }
299 -
300 - var match1 = {
301 - "summonerName" : match1_summonerName,
302 - "selectedChamp_image" : match1_selectedChamp_image,
303 - "bannedChamp_image" : match1_bannedChamp_image,
304 - "spell_image" : match1_spell_image,
305 - "kda" : match1_kda
306 - };
307 -
308 - var match2Url = "https://kr.api.riotgames.com/lol/match/v4/matches/" + match_gameId[1] + "?api_key=" + apikey;
309 - request(match2Url,function(error,response,body){
310 - var match2_json = JSON.parse(body);
311 - var match2_gameLength = match_json.gameDuration;
312 - var match2_teams = match2_json.teams;
313 - var match2_participants = match2_json.participants;
314 - var match2_participantIdentities = match2_json.participantIdentities;
315 -
316 - var match2_bannedChamp = new Array();
317 - var match2_selectedChamp = new Array();
318 - var match2_spellId = new Array();
319 - var match2_summonerName = new Array();
320 - var match2_kda = new Array();
321 -
322 - var match2_bannedChamp_image = new Array();
323 - var match2_selectedChamp_image = new Array();
324 - var match2_spell_image = new Array();
325 -
326 - for(var i=0; i<2; i++){
327 - var temp = match2_teams[i].bans;
328 - for(var j=0; j<5; j++){
329 - match2_bannedChamp.push(temp[j].championId);
330 - }
331 - }
332 -
333 - for(var i=0; i<10; i++){
334 - match2_selectedChamp.push(match2_participants[i].championId);
335 - match2_spellId.push(match2_participants[i].spell1Id);
336 - match2_spellId.push(match2_participants[i].spell2Id);
337 - match2_summonerName.push((match2_participantIdentities[i].player).summonerName);
338 - var obj = {
339 - 'k' : (match2_participants[i].stats).kills,
340 - 'd' : (match2_participants[i].stats).deaths,
341 - 'a' : (match2_participants[i].stats).assists
342 - };
343 - match2_kda.push(obj);
344 - }
345 -
346 - for(var i=0; i<10; i++) {
347 - for(key in champion) {
348 - if(champion.hasOwnProperty(key) && champion[key].key == match2_bannedChamp[i]) {
349 - match2_bannedChamp_image.push("http://ddragon.leagueoflegends.com/cdn/10.11.1/img/champion/"+champion[key].id+".png");
350 - }
351 - if(champion.hasOwnProperty(key) && champion[key].key == match2_selectedChamp[i]) {
352 - match2_selectedChamp_image.push("http://ddragon.leagueoflegends.com/cdn/10.11.1/img/champion/"+champion[key].id+".png");
353 - }
354 - }
355 - }
356 -
357 - for(var i=0; i<20; i++) {
358 - for(key in spell){
359 - if(spell.hasOwnProperty(key) && spell[key].key == match2_spellId[i]){
360 - match2_spell_image.push("http://ddragon.leagueoflegends.com/cdn/10.12.1/img/spell/"+spell[key].id+".png");
361 - }
362 - }
363 - }
364 -
365 - var match2 = {
366 - "summonerName" : match2_summonerName,
367 - "selectedChamp_image" : match2_selectedChamp_image,
368 - "bannedChamp_image" : match2_bannedChamp_image,
369 - "spell_image" : match2_spell_image,
370 - "kda" : match2_kda
371 - };
372 -
373 -
374 - var match3Url = "https://kr.api.riotgames.com/lol/match/v4/matches/" + match_gameId[2] + "?api_key=" + apikey;
375 - request(match3Url,function(error,response,body){
376 - var match3_json = JSON.parse(body);
377 - var match3_gameLength = match_json.gameDuration;
378 - var match3_teams = match3_json.teams;
379 - var match3_participants = match3_json.participants;
380 - var match3_participantIdentities = match3_json.participantIdentities;
381 -
382 - var match3_bannedChamp = new Array();
383 - var match3_selectedChamp = new Array();
384 - var match3_spellId = new Array();
385 - var match3_summonerName = new Array();
386 - var match3_kda = new Array();
387 -
388 - var match3_bannedChamp_image = new Array();
389 - var match3_selectedChamp_image = new Array();
390 - var match3_spell_image = new Array();
391 -
392 - for(var i=0; i<2; i++){
393 - var temp = match3_teams[i].bans;
394 - for(var j=0; j<5; j++){
395 - match3_bannedChamp.push(temp[j].championId);
396 - }
397 - }
398 -
399 - for(var i=0; i<10; i++){
400 - match3_selectedChamp.push(match3_participants[i].championId);
401 - match3_spellId.push(match3_participants[i].spell1Id);
402 - match3_spellId.push(match3_participants[i].spell2Id);
403 - match3_summonerName.push((match3_participantIdentities[i].player).summonerName);
404 - var obj = {
405 - 'k' : (match3_participants[i].stats).kills,
406 - 'd' : (match3_participants[i].stats).deaths,
407 - 'a' : (match3_participants[i].stats).assists
408 - };
409 - match3_kda.push(obj);
410 - }
411 -
412 - for(var i=0; i<10; i++) {
413 - for(key in champion) {
414 - if(champion.hasOwnProperty(key) && champion[key].key == match3_bannedChamp[i]) {
415 - match3_bannedChamp_image.push("http://ddragon.leagueoflegends.com/cdn/10.11.1/img/champion/"+champion[key].id+".png");
416 - }
417 - if(champion.hasOwnProperty(key) && champion[key].key == match3_selectedChamp[i]) {
418 - match3_selectedChamp_image.push("http://ddragon.leagueoflegends.com/cdn/10.11.1/img/champion/"+champion[key].id+".png");
419 - }
420 - }
421 - }
422 -
423 - for(var i=0; i<20; i++) {
424 - for(key in spell){
425 - if(spell.hasOwnProperty(key) && spell[key].key == match3_spellId[i]){
426 - match3_spell_image.push("http://ddragon.leagueoflegends.com/cdn/10.12.1/img/spell/"+spell[key].id+".png");
427 - }
428 - }
429 - }
430 -
431 - var match3 = {
432 - "summonerName" : match3_summonerName,
433 - "selectedChamp_image" : match3_selectedChamp_image,
434 - "bannedChamp_image" : match3_bannedChamp_image,
435 - "spell_image" : match3_spell_image,
436 - "kda" : match3_kda
437 - };
438 -
439 -
440 - var match4Url = "https://kr.api.riotgames.com/lol/match/v4/matches/" + match_gameId[3] + "?api_key=" + apikey;
441 - request(match4Url,function(error,response,body){
442 - var match4_json = JSON.parse(body);
443 - var match4_gameLength = match_json.gameDuration;
444 - var match4_teams = match4_json.teams;
445 - var match4_participants = match4_json.participants;
446 - var match4_participantIdentities = match4_json.participantIdentities;
447 -
448 - var match4_bannedChamp = new Array();
449 - var match4_selectedChamp = new Array();
450 - var match4_spellId = new Array();
451 - var match4_summonerName = new Array();
452 - var match4_kda = new Array();
453 -
454 - var match4_bannedChamp_image = new Array();
455 - var match4_selectedChamp_image = new Array();
456 - var match4_spell_image = new Array();
457 -
458 - for(var i=0; i<2; i++){
459 - var temp = match4_teams[i].bans;
460 - for(var j=0; j<5; j++){
461 - match4_bannedChamp.push(temp[j].championId);
462 - }
463 - }
464 -
465 - for(var i=0; i<10; i++){
466 - match4_selectedChamp.push(match4_participants[i].championId);
467 - match4_spellId.push(match4_participants[i].spell1Id);
468 - match4_spellId.push(match4_participants[i].spell2Id);
469 - match4_summonerName.push((match4_participantIdentities[i].player).summonerName);
470 - var obj = {
471 - 'k' : (match4_participants[i].stats).kills,
472 - 'd' : (match4_participants[i].stats).deaths,
473 - 'a' : (match4_participants[i].stats).assists
474 - };
475 - match4_kda.push(obj);
476 - }
477 -
478 - for(var i=0; i<10; i++) {
479 - for(key in champion) {
480 - if(champion.hasOwnProperty(key) && champion[key].key == match4_bannedChamp[i]) {
481 - match4_bannedChamp_image.push("http://ddragon.leagueoflegends.com/cdn/10.11.1/img/champion/"+champion[key].id+".png");
482 - }
483 - if(champion.hasOwnProperty(key) && champion[key].key == match4_selectedChamp[i]) {
484 - match4_selectedChamp_image.push("http://ddragon.leagueoflegends.com/cdn/10.11.1/img/champion/"+champion[key].id+".png");
485 - }
486 - }
487 - }
488 -
489 - for(var i=0; i<20; i++) {
490 - for(key in spell){
491 - if(spell.hasOwnProperty(key) && spell[key].key == match4_spellId[i]){
492 - match4_spell_image.push("http://ddragon.leagueoflegends.com/cdn/10.12.1/img/spell/"+spell[key].id+".png");
493 - }
494 - }
495 - }
496 -
497 - var match4 = {
498 - "summonerName" : match4_summonerName,
499 - "selectedChamp_image" : match4_selectedChamp_image,
500 - "bannedChamp_image" : match4_bannedChamp_image,
501 - "spell_image" : match4_spell_image,
502 - "kda" : match4_kda
503 - };
504 -
505 -
506 - var match5Url = "https://kr.api.riotgames.com/lol/match/v4/matches/" + match_gameId[4] + "?api_key=" + apikey;
507 - request(match5Url,function(error,response,body){
508 - var match5_json = JSON.parse(body);
509 - var match5_gameLength = match_json.gameDuration;
510 - var match5_teams = match5_json.teams;
511 - var match5_participants = match5_json.participants;
512 - var match5_participantIdentities = match5_json.participantIdentities;
513 -
514 - var match5_bannedChamp = new Array();
515 - var match5_selectedChamp = new Array();
516 - var match5_spellId = new Array();
517 - var match5_summonerName = new Array();
518 - var match5_kda = new Array();
519 -
520 - var match5_bannedChamp_image = new Array();
521 - var match5_selectedChamp_image = new Array();
522 - var match5_spell_image = new Array();
523 -
524 - for(var i=0; i<2; i++){
525 - var temp = match5_teams[i].bans;
526 - for(var j=0; j<5; j++){
527 - match5_bannedChamp.push(temp[j].championId);
528 - }
529 - }
530 -
531 - for(var i=0; i<10; i++){
532 - match5_selectedChamp.push(match5_participants[i].championId);
533 - match5_spellId.push(match5_participants[i].spell1Id);
534 - match5_spellId.push(match5_participants[i].spell2Id);
535 - match5_summonerName.push((match5_participantIdentities[i].player).summonerName);
536 - var obj = {
537 - 'k' : (match5_participants[i].stats).kills,
538 - 'd' : (match5_participants[i].stats).deaths,
539 - 'a' : (match5_participants[i].stats).assists
540 - };
541 - match5_kda.push(obj);
542 - }
543 -
544 - for(var i=0; i<10; i++) {
545 - for(key in champion) {
546 - if(champion.hasOwnProperty(key) && champion[key].key == match5_bannedChamp[i]) {
547 - match5_bannedChamp_image.push("http://ddragon.leagueoflegends.com/cdn/10.11.1/img/champion/"+champion[key].id+".png");
548 - }
549 - if(champion.hasOwnProperty(key) && champion[key].key == match5_selectedChamp[i]) {
550 - match5_selectedChamp_image.push("http://ddragon.leagueoflegends.com/cdn/10.11.1/img/champion/"+champion[key].id+".png");
551 - }
552 - }
553 - }
554 -
555 - for(var i=0; i<20; i++) {
556 - for(key in spell){
557 - if(spell.hasOwnProperty(key) && spell[key].key == match5_spellId[i]){
558 - match5_spell_image.push("http://ddragon.leagueoflegends.com/cdn/10.12.1/img/spell/"+spell[key].id+".png");
559 - }
560 - }
561 - }
562 -
563 - var match5 = {
564 - "summonerName" : match5_summonerName,
565 - "selectedChamp_image" : match5_selectedChamp_image,
566 - "bannedChamp_image" : match5_bannedChamp_image,
567 - "spell_image" : match5_spell_image,
568 - "kda" : match5_kda
569 - };
570 -
571 - var summoner_info = {
572 - "summoner_Name" : summoner,
573 - "summoner_tierimage" : img_tier,
574 - "summoner_tier" : tier,
575 - "summoner_rank" : rank,
576 - "summoner_leaguepoint" : leaguePoints,
577 - "summoner_wins" : wins,
578 - "summoner_losses" : losses,
579 - "summoner_winrate" : ((wins/(wins+losses))*100).toFixed(2),
580 - "summoner_carry" : (wins/losses*2).toFixed(2)
581 - };
582 -
583 - var rotation_info = {
584 - "rotation_image" : rotation_pic,
585 - "rotation_image_newbie" : rotation_pic_newbie
586 - };
587 -
588 - var total_info = {
589 - "Summoner_info" : summoner_info,
590 - "Rotation_info" : rotation_info,
591 - "Spectator_flag" : flag,
592 - "Spectator" : spectator,
593 - "Match1" : match1,
594 - "Match2" : match2,
595 - "Match3" : match3,
596 - "Match4" : match4,
597 - "Match5" : match5
598 - };
599 -
600 - console.log(total_info);
601 -
602 -
603 - res.render('index', { title: req.params.username ,
604 - c_id: champ_id,
605 - c_name: champ_name,
606 - c_point: champ_point,
607 - c_pic: champ_pic,
608 - c_rotation : rotation_pic,
609 - c_rotation_newbie : rotation_pic_newbie,
610 - c_summoner: summoner,
611 - c_wins: wins,
612 - c_losses: losses,
613 - c_tier: tier,
614 - c_imgtier: img_tier,
615 - c_rank: rank,
616 - c_leaguePoint: leaguePoints
617 - });
618 -
619 - });
620 - });
621 - });
622 - });
623 - });
624 - });
625 - });
626 - });
627 - });
628 - });
629 - });
630 - });
631 }); 313 });
314 + }
315 + console.log(match);
316 + res.render('match', {
317 + match: match
632 }); 318 });
633 - };
634 -
...\ No newline at end of file ...\ No newline at end of file
319 + });
320 + });
321 +}
...\ No newline at end of file ...\ No newline at end of file
......