LIANG XIAOTONG

api1,2 completed, index.ejs modified

1 var express = require('express'); 1 var express = require('express');
2 var app = express(); 2 var app = express();
3 -var router = require('./router/Test')(app); 3 +var router = require('./router/main')(app);
4 var bodyParser = require('body-parser'); 4 var bodyParser = require('body-parser');
5 5
6 app.set('views', __dirname + '/views'); 6 app.set('views', __dirname + '/views');
......
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-df870784-f399-4104-bfbb-1b209aeb597f"//api 5 + var apikey = "RGAPI-899abd44-2f7c-4e2d-981e-7cad9e50d1cb"//api
6 6
7 -var profileIconId; //아이콘 번호 7 + app.get('/', function (req, res) {
8 -var revisionDate; //수정날짜 8 + res.render('main', { title: 'R U TROLL?' });
9 -var id; //소환사ID
10 -var accountId; //계정Id
11 -var name; //소환사 이름
12 -var summonerLevel; //소환사 레벨
13 -
14 -var startIndex;
15 -var endIndex;
16 -var totalGames;
17 -var matches; //경기정보
18 -
19 - app.get('/', function(req, res) {
20 - res.render('main', { title: 'R U TROLL?' });
21 }); 9 });
22 10
23 - app.get('/search/:username/', function(req, res){ 11 + app.get('/search/:username/', function (req, res) {
24 //롤 api url 12 //롤 api url
25 - name = req.params.username; 13 + const summonerName = req.params.username;
26 - var nameUrl = "https://kr.api.riotgames.com/lol/summoner/v3/summoners/by-name/" + urlenconde(name)+"?api_key="+ apikey; 14 + var nameUrl = `https://kr.api.riotgames.com/tft/summoner/v1/summoners/by-name/${summonerName}?api_key=${apikey}`
27 - request(nameUrl,function(error,response,body){ 15 + request(nameUrl, function (error, response, body) {
28 - var info_summoner_json = JSON.parse(body);
29 -
30 - accountId = info_summoner_json["accountId"];
31 - id = info_summoner_json["id"];
32 - summoner = info_summoner_json["name"];
33 - profileIconId = info_summoner_json["profileIconId"];
34 - summonerLevel = info_summoner_json["summonerLevel"];
35 - revisionDate = info_summoner_json["revisionDate"];
36 -
37 - var rankedUrl = "https://kr.api.pvp.net/api/lol/kr/v2.5/league/by-summoner/"+ urlenconde(id)+ "?api_key=" + apikey;
38 - var champUrl = "https://kr.api.pvp.net/api/lol/kr/v1.3/stats/by-summoner/" + urlenconde(id) + "/ranked?api_key=" + apikey;
39 - request(champUrl,function(error,response,body){
40 - var info_champ_json = JSON.parse(body);
41 - var champions = info_champ_json["champions"];
42 - var champ_point = new Array();
43 - var champ_id = new Array();
44 - var champ_name = new Array();
45 - var champ_pic = new Array();
46 - var champions_length = Object.keys(champions).length;
47 16
48 - for(var i=0; i < champions_length; i++){ 17 + var info_summoner_json = JSON.parse(body);
49 - champ_point[i] = (champions[i]["stats"]["totalSessionsWon"]/champions[i]["stats"]["totalSessionsPlayed"]*200) 18 + console.log('summoner', body);
50 - + ((champions[i]["stats"]["totalAssists"]+champions[i]["stats"]["totalChampionKills"])/champions[i]["stats"]["totalDeathsPerSession"]*100) 19 + if (info_summoner_json.status?.status_code) {
51 - + (champions[i]["stats"]["totalSessionsPlayed"]*3); 20 + return res.render('index', {
52 - champ_id[i] = champions[i]["id"]; 21 + title: req.params.username,
53 - } 22 + error_message: info_summoner_json.status?.message
54 - 23 + });
55 - var staticUrl = "https://global.api.pvp.net/api/lol/static-data/kr/v1.2/champion/?api_key=" + apikey; 24 + }
56 - request(staticUrl,function(error,response,body){ 25 + const summonerId = info_summoner_json["id"];
57 - var info_static_champ_json = JSON.parse(body); 26 + const summoner = info_summoner_json["name"];
58 - var champion = info_static_champ_json["data"]; 27 + const leagueUrl = `https://kr.api.riotgames.com/tft/league/v1/entries/by-summoner/${summonerId}?api_key=${apikey}`;
59 - for(var i=0; i < champ_id.length; i++){ 28 + request(leagueUrl, function (error, response, body) {
60 - for(js in champion){ 29 + const info_league_json = JSON.parse(body);
61 - for(j in champion[js]){ 30 + console.log('league', body);
62 - if(champion[js]["id"] == champ_id[i]){ 31 + res.render('index', {
63 - champ_name[i] = champion[js]["key"]; 32 + title: req.params.username,
64 - champ_pic[i] = "https://opgg-static.akamaized.net/images/lol/champion/"+champ_name[i]+".png?image=c_scale,w_46"; 33 + error_message: false,
65 - } 34 + c_summoner: summoner,
66 - } 35 + c_leagueList: info_league_json
67 - }
68 - }
69 - champ_name[champ_name.length] = "total";
70 - var temp_id;
71 - var temp_name;
72 - var temp_point;
73 - var temp_pic;
74 - for(var i=0; i < champ_id.length-1; i++){
75 - for(var j=i+1;j <champ_id.length-1; j++)
76 - if(champ_point[i] > champ_point[j]){
77 - temp_id = champ_id[i];
78 - temp_name = champ_name[i];
79 - temp_point = champ_point[i];
80 - temp_pic = champ_pic[i];
81 - champ_id[i] = champ_id[j]
82 - champ_name[i] = champ_name[j];
83 - champ_point[i] = champ_point[j];
84 - champ_pic[i] = champ_pic[j];
85 - champ_id[j] = temp_id
86 - champ_name[j] = temp_name;
87 - champ_point[j] = temp_point;
88 - champ_pic[j] = temp_pic;
89 - }
90 - }
91 -
92 - res.render('index', { title: req.params.username ,
93 - c_id: champ_id,
94 - c_name: champ_name,
95 - c_point: champ_point,
96 - c_pic: champ_pic,
97 - c_summoner: summoner
98 - });
99 }); 36 });
100 }); 37 });
101 }); 38 });
......
...@@ -35,77 +35,47 @@ ...@@ -35,77 +35,47 @@
35 </div> 35 </div>
36 </div> 36 </div>
37 37
38 -
39 -
40 -
41 <br></br> 38 <br></br>
42 - <font size=10em> 39 + <% if (error_message) { %>
43 - <strong> 40 + <h2><%= error_message %></h2>
44 - <%= c_summoner + "\n"%> 41 + <% } else { %>
45 - </strong> 42 + <font size=10em>
46 - </font> 43 + <strong>
47 - 44 + <%= c_summoner + "\n"%>
48 - <table class="basic"> 45 + </strong>
46 + </font>
47 + <table class="table">
48 + <thead>
49 + <tr>
50 + <th>Tier</th>
51 + <th>Win</th>
52 + <th>Lose</th>
53 + <th>승률</th>
54 + <th>캐리력</th>
55 + </tr>
56 + </thead>
57 + <% if (c_leagueList.length>0) { %>
58 + <tbody>
59 + <%
60 + c_leagueList.forEach(function(league){ %>
61 + <tr>
62 + <td><%= league.tier + " " + league.rank + " / " + league.leaguePoints + "점"%></td>
63 + <td><%= league.wins %></td>
64 + <td><%= league.losses %></td>
65 + <td><%= ((league.wins/(league.wins+league.losses))*100).toFixed(2) + "%" %></td>
66 + <td><%= (league.wins/league.losses*2).toFixed(2) %></td>
67 + </tr>
68 + <% }); %>
69 + </tbody>
70 + <% } else { %>
49 <tbody> 71 <tbody>
50 - <tr><td> <img src= <%=c_imgtier%> width=120, height=120></td></tr> 72 + <tr >
51 - <tr><td><%= "Tier : " + c_tier + " " + c_rank + " / " + c_leaguePoint + "점"%></td></tr> 73 + <td colspan="5" style="text-align: center;">no league</td>
52 - <tr><td><%= "Win : " + c_wins + " / Lose : " + c_losses%></td></tr> 74 + </tr>
53 - <tr><td><%= "승률 : " + ((c_wins/(c_wins+c_losses))*100).toFixed(2) + "%" %></td></tr>
54 - <tr><td><%= "캐리력 : " + (c_wins/c_losses*2).toFixed(2) %></td></tr>
55 </tbody> 75 </tbody>
56 - </table>
57 -
58 -
59 - <br></br>
60 -
61 - <div class="center">
62 - <strong>
63 - <%= "로테이션 챔피언: " %>
64 - </strong>
65 - <% for (var i=0; i<c_rotation.length-1; i++){ %>
66 - <img src= <%=c_rotation[i]%> width=50, height=50>
67 - <% } %>
68 - </div>
69 -
70 - <br></br>
71 -
72 - </div>
73 - <div class="center">
74 - <strong>
75 - <%= "추측 MMR:" %>
76 - <%if (c_tier=="SILVER") {%>
77 - <%="1200~1500"%>
78 - <%}%>
79 - <%if (c_tier=="GOLD") {%>
80 - <%="1500~1800"%>
81 - <%}%>
82 - <%if (c_tier=="PLATINUM") {%>
83 - <%="1800~2100"%>
84 - <%}%>
85 - <%if (c_tier=="DIAMOND") {%>
86 - <%="2100~2400"%>
87 - <%}%>
88 - <%if (c_tier=="MASTER") {%>
89 - <%="2400~2600"%>
90 - <%}%>
91 - <%if (c_tier=="GRANDMASTER") {%>
92 - <%="2600~2800"%>
93 - <%}%>
94 - <%if (c_tier=="CHALLENGER") {%>
95 - <%=">3000"%>
96 - <%}%>
97 - </strong>
98 - </div>
99 - <% for (var i=0; i<c_id.length-1; i++){ %>
100 - <div class="champImage">
101 - <div class="center">
102 - <img src= <%=c_pic[i]%> width=50, height=50>
103 - <%= c_name[i] %>
104 - <%= "point: " + (1000000/c_point[i]).toFixed(2) %>
105 <% } %> 76 <% } %>
106 - </div> 77 + </table>
107 - 78 + <% } %>
108 - 79 + </div>
109 -</div>
110 </body> 80 </body>
111 </html> 81 </html>
......