-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
36 lines (31 loc) · 1.27 KB
/
index.js
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
// v2: have the script create a story about a champion based on their lore
let Airtable = require('airtable');
const airtableApiKey = require('./passkeys').airtableApiKey;
const airtableBaseId = require('./passkeys').airtableBaseId;
var base = new Airtable({ apiKey: airtableApiKey }).base(airtableBaseId);
async function getChampInfo(champName) {
try {
if (champName === "" || champName === undefined) {
// if no champName is provided, let's pick a random champ!
const response = await fetch(`http://ddragon.leagueoflegends.com/cdn/12.8.1/data/en_US/champion.json`);
const data = await response.json();
return new Promise((resolve, reject) => {
const champ = data.data;
resolve(champ);
});
} else {
const response = await fetch(`http://ddragon.leagueoflegends.com/cdn/12.8.1/data/en_US/champion/${champName}.json`);
const data = await response.json();
return new Promise((resolve, reject) => {
const champ = data.data;
resolve(champ);
});
}
} catch (error) {
console.log(error);
}
};
let champion = getChampInfo("Shaco").then(champ => {
console.log(champ);
return champ;
});