-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetCardCollection.js
More file actions
33 lines (27 loc) · 876 Bytes
/
getCardCollection.js
File metadata and controls
33 lines (27 loc) · 876 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 axios from "axios";
import { promises as fs } from "fs";
import { dirname } from 'path';
// Function to ensure the directory exists
async function ensureDirectoryExistence(filePath) {
const dir = dirname(filePath);
try {
await fs.access(dir);
} catch {
await fs.mkdir(dir, { recursive: true });
}
}
async function fetchCardCollection(outputPath) {
try {
await ensureDirectoryExistence(outputPath);
const response = await axios.get(
"https://api.hearthstonejson.com/v1/latest/enUS/cards.collectible.json"
);
const data = response.data;
const jsonString = JSON.stringify(data, null, 2);
await fs.writeFile(outputPath, jsonString);
console.log("Card collection loaded");
} catch (error) {
console.error("Error on getting the cards", error);
}
}
fetchCardCollection("src/resources/cards.collectible.json");