View difference between Paste ID: 8p24nRB8 and JU6bpjDb
SHOW: | | - or go back to the newest paste.
1
const Promise = require('bluebird');
2
const request = require('request');
3
const arequest = Promise.PromisifyAll(request);
4
5
const getAndStoreBoobies = Promise.coroutine(function* (id, threshold){
6
	var resp, json;
7
	resp = (yield arequest.getAsync('http://www.myboobies.com/' + id)).body;
8
	json = JSON.parse(resp);
9
	if (json.bra_size <= threshold){
10
		return;
11
	}
12
	const options = {
13
		url: 'http://www.mybobbiesstorage.com/api/dump',
14
		form: {
15
			thumb: json.thumbnail,
16
			bra_size: json.bra_size,
17
			name: json.name
18
		}
19
	};
20
	resp = (yield arequest.postAsync(options)).body;
21
	json = JSON.parse(resp);	
22
	if (json.error){
23
		console.log("boobies not saved: ", json.error);
24
		return;
25
	} else {
26
		console.log("All good!");
27
	}
28
	return true;
29
});
30
31
getAndStoreBoobies('EdithPiaf', 3);