-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpopulate-sets.ts
More file actions
28 lines (25 loc) · 796 Bytes
/
populate-sets.ts
File metadata and controls
28 lines (25 loc) · 796 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
const fs = require('fs');
const path = require('path');
async function downloadSetIcons() {
const res = await fetch('https://api.scryfall.com/sets');
const { data } = await res.json();
const iconsDir = path.join(process.cwd(), 'public', 'set_icons');
if (!fs.existsSync(iconsDir)) {
fs.mkdirSync(iconsDir, { recursive: true });
}
for (const set of data) {
const iconUrl = set.icon_svg_uri;
const setCode = set.code;
if (iconUrl) {
try {
const iconRes = await fetch(iconUrl);
const svg = await iconRes.text();
fs.writeFileSync(path.join(iconsDir, `${setCode}.svg`), svg);
console.log(`Saved ${setCode}.svg`);
} catch (err) {
console.error(`Failed to save ${setCode}:`, err);
}
}
}
}
downloadSetIcons();