-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchainpromises.js
35 lines (22 loc) · 999 Bytes
/
chainpromises.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
const fs = require('fs');
var rp = require('request-promise');
const user = 'BoxerMc';
var pages = 0;
var promise1 = rp('http://ws.audioscrobbler.com/2.0/?method=user.getRecentTracks&api_key=60e256b3eda3fe54934d79339614411f&user=' + user + '&format=json');
var promise2 = rp('http://ws.audioscrobbler.com/2.0/?method=user.getRecentTracks&api_key=60e256b3eda3fe54934d79339614411f&user=' + user + '&page=5&format=json');
promise1.then(function(data) {
str = JSON.parse(data);
pages = str.recenttracks["@attr"].totalPages;
var arr = [];
for (let i = 0; i < pages; i++) {
arr.push(rp('http://ws.audioscrobbler.com/2.0/?method=user.getRecentTracks&api_key=60e256b3eda3fe54934d79339614411f&user=' + user + '&page=' + (i + 1) + '&format=json'))
}
var ok = [];
Promise.all(arr).then(function(data) {
var ok = [];
for (let i = 0; i < data.length; i++) {
ok.push(JSON.parse(data[i]));
}
console.log(ok);
});
});