-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLocalRankings.js
More file actions
31 lines (26 loc) · 983 Bytes
/
LocalRankings.js
File metadata and controls
31 lines (26 loc) · 983 Bytes
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
import fetch from 'node-fetch';
import fs from 'fs';
async function pathoflegend_getData(api_key,local) {
const url = `https://api.clashroyale.com/v1/locations/${local}/pathoflegend/players`;
const headers = {
"Content-Type": "application/json",
"Authorization": "Bearer " + api_key
};
try {
const response = await fetch(url, { headers });
if (!response.ok) {
throw new Error(`Response status: ${response.status} ${response.statusText} Please check if your API key is correct, replace # with %23 in PlayerTag`);
}
const json = await response.json();
fs.writeFile(`json/${local}RankingsList.json`, JSON.stringify(json), (err) => {
if (err) {
console.error(err);
} else {
}
});
console.log("RankingsList.json created");
} catch (error) {
console.error(error.message);
}
}
export { pathoflegend_getData };