Ejemplo n.º 1
0
var interval = setInterval(function() { // setup a function which will be called at a set interval
    var dq = requestQueue.dequeue(); // will be undefined if queue is empty
    if (typeof dq !== 'undefined') {// if not undefined, this is a legit request
        if (typeof dq[1] === 'function') // api call
            request(dq[0], dq[1]); 
        else {// img call
            console.log('Downloading image ' + dq[1]);
            var file = fs.createWriteStream(rootPath + '/' + dq[2] + '/' + dq[1]);
            var req = http.get(dq[0].uri, function(res) {
                res.pipe(file);
                console.log('Downloaded image ' + dq[1]);
            });
            //request(dq[0]).pipe(fs.createWriteStream(rootPath + '/' + dq[2] + '/' + dq[1]));
        }
    }
    else {  
        if (argv.recover) {
            if (!blah)
                recoverImages();
            blah = true;
            if (deletedPosts.length == 0) {
                clearInterval(interval);
                fs.writeFileSync(rootPath + '/deleted.json', JSON.stringify(deletedData), 'utf8');
            }
        } else {
            clearInterval(interval);
        }
    }
}, 1000/requestsPerSecond); 
Ejemplo n.º 2
0
 var interval = setInterval(function() { // direct copypasta from the bottom of the script, this is really hacky
     var dq = requestQueue.dequeue(); 
     if (typeof dq !== 'undefined') {
         console.log('Downloading image ' + dq[1]);
         var file = fs.createWriteStream(rootPath + '/' + dq[2] + '/' + dq[1]);
         var req = http.get(dq[0].uri, function(res) {
             res.pipe(file);
             console.log('Downloaded image ' + dq[1]);
         });
         //request(dq[0]).pipe(fs.createWriteStream(rootPath + '/' + dq[2] + '/' + dq[1]));
     }
     else {  
         clearInterval(interval);
     }
 }, 1000/requestsPerSecond); 
Ejemplo n.º 3
0
var Queue = require('qv2');
var testQueue = new Queue();

console.log(testQueue.empty); // prints: true

// .enqueue moves the argument to the back of the queue
testQueue.enqueue(1);
testQueue.enqueue(2);
testQueue.enqueue(3);

// queue.length returns the length
console.log(testQueue.length); // prints: 3

// .dequeue dequeues the frontmost element
console.log(testQueue.dequeue()); // prints: 1

// .peek returns the frontmost element without dequeuing it
console.log(testQueue.peek()); // prints: 2

console.log(testQueue.dequeue()); // prints: 2
console.log(testQueue.dequeue()); // prints: 3
console.log(testQueue.length); // prints: 0

// .dequeue returns undefined when the queue is empty
console.log(testQueue.dequeue() == undefined); // prints: true