-
Notifications
You must be signed in to change notification settings - Fork 0
/
Image_Extraction.js
75 lines (53 loc) · 1.76 KB
/
Image_Extraction.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
A Node.js script to extract images from the system
To use:
1) Install Node (https://nodejs.org/en/download/)
2) Install Axios (https://github.com/axios/axios)
3) Install Image-Downloader (https://www.npmjs.com/package/image-downloader)
4) Specify accountID variable
5) Specify fileLocation variable
Register and authenticate your client to get your access token:
https://developers.lightspeedhq.com/retail/authentication/authentication-overview/
*/
const axios = require('axios');
const download = require('image-downloader');
const accountID = insertNumber; // Insert your accountID here
const folderLocation = 'Specify File Directory'; // e.g. /Users/Name/Documents/RetailImages
const instance = axios.create({
baseURL: 'https://api.lightspeedapp.com/API/Account/{{accountID}}/',
timeout: 30000,
headers: {
Authorization: 'Bearer {{access_token}}',
Accept: 'application/json'
}
});
(async () => {
try {
let offset = 0;
let results = [];
let next = true;
while (next) {
let request = await instance.get(`Image.json?&offset=${offset}`)
let response = request.data;
if (response.hasOwnProperty('Image')) {
results.push(...response.Image);
offset += 100;
} else {
next = false;
}
}
for (let picture of results) {
let imageURL = picture.baseImageURL + picture.publicID;
const options = {
url: `${imageURL}.png`,
dest: folderLocation
}
const {
filename,
image
} = await download.image(options);
}
} catch (err) {
console.log(err);
}
})();