-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFindClan.js
More file actions
33 lines (27 loc) · 898 Bytes
/
FindClan.js
File metadata and controls
33 lines (27 loc) · 898 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
32
33
import fetch from 'node-fetch';
import fs from 'fs';
async function Clan_getData(api_key,clans) {
encodeURI(clans);
const url = `https://api.clashroyale.com/v1/clans?name=${clans}`;
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}`);
}
const json = await response.json();
fs.writeFile(`json/${decodeURIComponent(clans)}.json`, JSON.stringify(json), (err) => {
if (err) {
console.error(err);
} else {
}
});
console.log("clans.json created");
} catch (error) {
console.error(error.message);
}
}
export { Clan_getData };