-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
44 lines (39 loc) · 1.48 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
import fetch from 'node-fetch';
import fs from 'fs';
import download from 'image-downloader';
if (!fs.existsSync('./funged')) fs.mkdirSync('./funged');
const Self_Args = process.argv.slice(2);
if (!Self_Args.length) {
console.log("node index.js <username>\nEX: node index.js turkeysmegaverse");
process.exit();
}
const path = `./funged/${Self_Args[0]}/`;
if (!fs.existsSync(path)) fs.mkdirSync(path);
const limit = Self_Args[1] || 50;
fetch(`https://api.opensea.io/api/v1/assets?collection=${Self_Args[0]}&format=json&limit=${limit}`, {
headers: {
'X-Forwarded': '127.0.0.1',
'User-Agent': 'Mozilla/5.0',
'content-type': 'application/json'
}
}).then(res => res.json()).then(json => {
console.log('Checking if user has assets I can download...');
if (json?.assets < 1) return console.error('The provided user has no assets in their collection to scrape.');
console.log('User has assets in collection. Scraping...\n')
json.assets.forEach(asset => {
//if (asset.image_url.length > 0) {
if (asset && asset.image_url && asset.image_url.length > 0) {
fungeTheToken({
url: asset.image_url,
dest: `../../${path}/`
});
}
});
});
const fungeTheToken = async (options) => {
download.image(options)
.then(({ filename }) => {
console.log('Saved to', filename) // saved to /path/to/dest/image.jpg
})
.catch((err) => console.error(err))
};