-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
44 lines (35 loc) · 1006 Bytes
/
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
34
35
36
37
38
39
40
41
42
43
44
import fs from "fs-extra";
import axios from "axios";
import { getImageSize } from "./getImageSize";
import { log, time } from "./log";
const INITIAL_ID_XKCD_COMIC = 2580;
const MAX_ID_XKCD_COMIC = 2588;
let options = {
proxy: {
host: "192.168.0.1",
port: 8080,
},
};
const endTime = time();
const { writeJSON } = fs;
for (let id = INITIAL_ID_XKCD_COMIC; id < MAX_ID_XKCD_COMIC; id++) {
const url = `https://xkcd.com/${id}/info.0.json`;
log(`Fetching ${url}...`);
// const data = getData(url);
const { data } = await axios.get(url);
const { num, news, transcript, ...restOfComic } = data;
log(`Fetched #${num}. Getting image dimensions...`);
const { height, width } = await getImageSize({ url: img });
log(`Got image dimensions: ${width}x${height}`);
const comicToStore = {
id,
img,
height,
width,
...restOfComic,
};
const jsonFile = `./comics/${id}`;
await writeJSON(jsonFile, comicToStore);
log(`Wrote ${jsonFile}! ✅\n`);
}
endTime();