fetching games?
This commit is contained in:
parent
484e1ba409
commit
45a8083857
2 changed files with 63 additions and 6 deletions
|
@ -1,3 +1,7 @@
|
||||||
|
volumes:
|
||||||
|
lol-fetcher-data:
|
||||||
|
external: true
|
||||||
|
|
||||||
services:
|
services:
|
||||||
stat-fetcher:
|
stat-fetcher:
|
||||||
image: node:current-alpine
|
image: node:current-alpine
|
||||||
|
@ -13,3 +17,5 @@ services:
|
||||||
|
|
||||||
redis:
|
redis:
|
||||||
image: redis
|
image: redis
|
||||||
|
volumes:
|
||||||
|
- lol-fetcher-data:/data
|
||||||
|
|
59
index.mjs
59
index.mjs
|
@ -1,6 +1,8 @@
|
||||||
// @ts-check
|
// @ts-check
|
||||||
import { RiotAPI, RiotAPITypes, PlatformId } from "@fightmegg/riot-api";
|
import { RiotAPI, RiotAPITypes, PlatformId } from "@fightmegg/riot-api";
|
||||||
|
|
||||||
|
const METHOD_KEY = RiotAPITypes.METHOD_KEY;
|
||||||
|
|
||||||
/** @type {RiotAPITypes.Config} */
|
/** @type {RiotAPITypes.Config} */
|
||||||
const config = {
|
const config = {
|
||||||
cache: {
|
cache: {
|
||||||
|
@ -8,7 +10,9 @@ const config = {
|
||||||
client: "redis://redis:6379", // leave null if client is local
|
client: "redis://redis:6379", // leave null if client is local
|
||||||
ttls: {
|
ttls: {
|
||||||
byMethod: {
|
byMethod: {
|
||||||
[RiotAPITypes.METHOD_KEY.SUMMONER.GET_BY_SUMMONER_NAME]: 30 * 60 * 100, // ms
|
[METHOD_KEY.SUMMONER.GET_BY_SUMMONER_NAME]: 24 * 60 * 60 * 100, // ms
|
||||||
|
[METHOD_KEY.MATCH_V5.GET_IDS_BY_PUUID]: 24 * 60 * 60 * 100, // ms
|
||||||
|
[METHOD_KEY.MATCH.GET_MATCHLIST_BY_ACCOUNT]: 24 * 60 * 60 * 100, // ms
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -16,9 +20,56 @@ const config = {
|
||||||
|
|
||||||
const rAPI = new RiotAPI("RGAPI-8f41294d-7bb1-4fd5-83d4-773a8a7b25f5", config);
|
const rAPI = new RiotAPI("RGAPI-8f41294d-7bb1-4fd5-83d4-773a8a7b25f5", config);
|
||||||
|
|
||||||
const summoner = await rAPI.summoner.getBySummonerName({
|
let val = await rAPI.summoner
|
||||||
|
.getBySummonerName({
|
||||||
region: PlatformId.NA1,
|
region: PlatformId.NA1,
|
||||||
summonerName: "RavenShade",
|
summonerName: "RavenShade",
|
||||||
});
|
})
|
||||||
|
.then(({ name, puuid }) => ({ name, puuid }));
|
||||||
|
|
||||||
console.log(`${JSON.stringify(summoner, null, " ")}`);
|
const ice = await rAPI.summoner
|
||||||
|
.getBySummonerName({
|
||||||
|
region: PlatformId.NA1,
|
||||||
|
summonerName: "IcePhoenix05",
|
||||||
|
})
|
||||||
|
.then(({ name, puuid }) => ({ name, puuid }));
|
||||||
|
|
||||||
|
console.log(`${JSON.stringify(val, null, " ")}`);
|
||||||
|
console.log(`${JSON.stringify(ice, null, " ")}`);
|
||||||
|
|
||||||
|
const valGames = await get_games_by_puuid(val.puuid);
|
||||||
|
const iceGames = await get_games_by_puuid(ice.puuid);
|
||||||
|
|
||||||
|
const commonGames = valGames.filter(Set.prototype.has, new Set(iceGames));
|
||||||
|
|
||||||
|
console.log(`${JSON.stringify(commonGames, null, " ")}`);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} puuid
|
||||||
|
* @returns {Promise<string[]>}
|
||||||
|
*/
|
||||||
|
async function get_games_by_puuid(puuid) {
|
||||||
|
let games = [];
|
||||||
|
|
||||||
|
let start = 0;
|
||||||
|
while (start >= 0) {
|
||||||
|
console.log(`getting entries ${start}-${start + 19}`);
|
||||||
|
let newGames = await rAPI.matchV5.getIdsByPuuid({
|
||||||
|
cluster: PlatformId.AMERICAS,
|
||||||
|
puuid: val.puuid,
|
||||||
|
params: {
|
||||||
|
start,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (newGames.length < 20) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
games.push.apply(games, newGames);
|
||||||
|
|
||||||
|
start += 20;
|
||||||
|
}
|
||||||
|
|
||||||
|
return games;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue