-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
56 lines (48 loc) · 1.25 KB
/
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
45
46
47
48
49
50
51
52
53
54
55
56
const querystring = require("querystring");
const H = require("highland");
const axios = require("axios");
const axiosSaveFile = require("axios-savefile");
const BASE_URL = "https://api.scryfall.com";
const IMAGE_DIR = "images";
// TODO: Modify list of cards here
const cards = [
"City of Brass",
"Mirror Universe",
"Underground Sea",
"Tropical Island"
];
const saveImage = info => {
const url = info.image;
const savePath = `${__dirname}/${IMAGE_DIR}/${info.card}.png`;
return H(axiosSaveFile(url, savePath));
};
const search = name => {
const options = {
format: "json",
include_extras: false,
include_multilingual: false,
order: "cmc",
page: 1,
unique: "cards",
q: `name:${name}`
};
const qs = querystring.stringify(options);
return `${BASE_URL}/cards/search?${qs}`;
};
const getCardInfo = name => {
const url = search(name);
return H(axios(url)).map(response => response.data);
};
const getImage = size => response => {
return {
card: response.data[0].name,
image: response.data[0].image_uris[size]
};
};
H(cards)
.ratelimit(1, 100)
.flatMap(getCardInfo)
.map(getImage("normal")) // [small,normal,large,png,art_crop,border_crop]
.flatMap(saveImage)
.errors(console.log)
.done(() => {});