-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.gs
More file actions
56 lines (43 loc) · 2.07 KB
/
code.gs
File metadata and controls
56 lines (43 loc) · 2.07 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
const key = <RIOT API KEY GOES HERE. GET ONE AT https://developer.riotgames.com/>;
function GETPLAYERDATA(user, champion) {
//GET SUMMONER ACCOUNT ID
var data = {};
var response = UrlFetchApp.fetch("https://na1.api.riotgames.com/lol/summoner/v4/summoners/by-name/" + user + "?api_key=" + key, {muteHttpExceptions: true, validateHttpsCertificates: true})
data = JSON.parse(response.getContentText());
var accountId = data["accountId"];
//USE SUMMONER ACCOUNT ID TO GET MATCH LIST. FILTER USING CRITERIA
var criteria = [["queue", 420], ["queue", 440], ["queue", 700], ["api_key", key], ["endIndex", 20]];
if(champion){
criteria.push(["champion", champion]);
}
var matchesUrl = "https://na1.api.riotgames.com/lol/match/v4/matchlists/by-account/" + accountId + "?";
for(let i = 0; i < criteria.length; i++) {
matchesUrl += criteria[i][0] + "=" + criteria[i][1];
if(i + 1 < criteria.length) {
matchesUrl += "&";
}
}
response = UrlFetchApp.fetch(matchesUrl, {muteHttpExceptions: true, validateHttpsCertificates: true})
data = JSON.parse(response.getContentText());
var matches = data["matches"];
//ITERATE OVER MATCHES AND AGGRIGATE DATA
var wins = 0;
var total = 0;
for(let i = 0; i < matches.length; i++) {
var matchUrl = "https://na1.api.riotgames.com/lol/match/v4/matches/" + matches[i]["gameId"] + "?api_key=" + key;
response = UrlFetchApp.fetch(matchUrl, {muteHttpExceptions: true, validateHttpsCertificates: true})
data = JSON.parse(response.getContentText());
var teams = data["teams"];
var winningTeam = teams[0]["win"] == "Win" ? teams[0]["teamId"] : teams[1]["teamId"];
var participants = data["participants"];
for(let p = 0; p < participants.length; p++){
if(participants[p]["championId"] == matches[i]["champion"]){
if(participants[p]["teamId"] == winningTeam){
wins++;
}
}
}
total++;
}
return total == 0 ? "NONE/ERROR" : wins/total;
}