Advertisement
Garey

test

May 10th, 2017
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var express = require('express');
  2. var app = express();
  3. var async = require('async');
  4. var request = require('request');
  5. var exphbs = require('express-handlebars')
  6. app.engine('handlebars', exphbs({defaultLayout: 'main'}));
  7.  
  8. app.set('view engine', 'handlebars');
  9.  
  10. app.get('/', function(req, res) {
  11.   var data = {};
  12.   var name = 'Row';
  13.   var api_key = 'RGAPI-5aeee0fb-2c02-4576-87db-b786d6ad42e3';
  14.   var summoner = 'https://eun1.api.riotgames.com/lol/summoner/v3/summoners/by-name/'+ name +'?api_key=' + api_key;
  15.   var ranked = 'https://eune.api.riotgames.com/api/lol/EUNE/v1.3/stats/by-summoner/23507564/summary?season=SEASON2017&api_key=' + api_key;
  16.  
  17.   async.waterfall([
  18.     function(callback){
  19.       request(summoner, function(err, response, body){
  20.         if(!err && response.statusCode == 200)
  21.         {
  22.           var json = JSON.parse(body);
  23.           data.id = json.id;
  24.           data.name = json.name;
  25.           data.summonerLevel = json.summonerLevel;
  26.           data.profileIcon = json.profileIconId;
  27.           ranked = 'htt'
  28.           callback(null, data);
  29.         }else {
  30.           console.log(err);
  31.         }
  32.       });
  33.  
  34.       request(ranked, function(err, response, body) {
  35.         if(!err && response.statusCode == 200){
  36.           var json = JSON.parse(body);
  37.           if(json['playerStatSummaries'][6].playerStatSummaryType == 'RankedSolo5x5'){
  38.             data.queueType = 'Ranked Solo';
  39.             data.rankedWins = json['playerStatSummaries'][6].wins;
  40.             data.rankedLosses = json['playerStatSummaries'][6].losses;
  41.             var wins = json['playerStatSummaries'][6].wins
  42.             var losses = json['playerStatSummaries'][6].losses;
  43.             var games = Number(json['playerStatSummaries'][6].wins) + Number(json['playerStatSummaries'][6].losses);
  44.             var winRatio = (Number(wins) / Number(games));
  45.             data.winPercent = Math.round(winRatio * 100) + '%';
  46.             var lossRatio = (Number(losses) / Number(games));
  47.             data.lossPercent = Math.round(lossRatio * 100) + '%';
  48.           }
  49.         }else {
  50.           console.log(err);
  51.         }
  52.       });
  53.     }
  54.   ],
  55.   function(err, data) {
  56.     if(err) {
  57.       console.log(err);
  58.       return;
  59.     }
  60.  
  61.     res.render('index', {
  62.       info: data
  63.     });
  64.   });
  65. });
  66. var port = Number(process.env.PORT || 3000);
  67. app.listen(port);
  68. ----
  69.  
  70. <img src="http://opgg-static.akamaized.net/images/profile_icons/profileIcon{{{info.profileIcon}}}.jpg" alt="">
  71. <br>
  72. Summoner Name: {{{info.name}}} <br>
  73. Summoner Level: {{{info.summonerLevel}}} <br>
  74. Summoner ID: {{{info.id}}}<br>
  75. Wins: {{{info.rankedWins}}} <br>
  76. Losses: {{{info.rankedLosses}}} <br>
  77. Win Percent: {{{info.winPercent}}} <br>
  78. Loss: Percent: {{{info.lossPercent}}} <br>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement