-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
68 lines (65 loc) · 3.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
var prompt = require('prompt');
var request = require('request');
var cheerio = require('cheerio');
var colors = require('colors');
function run(){
prompt.start();
prompt.get(['How much ?', 'What do you want to convert from?', 'What do you want to convert to?'], function (err, result) {
// var much = result[Object.keys(result)[0]];
var one = result[Object.keys(result)[1]].toUpperCase(); // || are for tests
var two = result[Object.keys(result)[2]].toUpperCase();
if (!isNaN(parseFloat(result[Object.keys(result)[0]]))) {
console.log('Thank you for using this , Plase wait a moment...');
request({
method: 'GET',
url: 'http://www.xe.com/currencyconverter/convert/?Amount=' + result[Object.keys(result)[0]] + '&From=' + one + '&To=' + two,
}, function (err, response, body) {
var test_if_title = false;
if (err) return console.error(err);
// Tell Cherrio to load the HTML
$ = cheerio.load(body);
var title = $('.wrapper .bodyContent .quickFixesTopModule .uccResultContainer #ucc-container .uccResultAmount').eq(0).text();
if (title == 0.00) {
console.log(colors.red('⊙﹏⊙ Something went wrong, maybe you put wrong data ⊙﹏⊙'));
return null;
} else {
console.log("\n$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n•_•) ( ゚o゚) (•_• \n$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ \n \n" + colors.yellow(result[Object.keys(result)[0]]) + ' ' + one.bgMagenta + ' is equal to '.white + '('.green + title.green + ') '.green + two.bgMagenta + "\n \n$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ \n•_•) ( ゚o゚) (•_•\n$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ \n");
return title;
}
});
} else {
console.log(colors.red('⊙﹏⊙ Type error , one the arguments was wrong , try again'));
return null;
}
});
}
function toTest(){
var much = result[Object.keys(result)[0]] || 100;
var one = result[Object.keys(result)[1]].toUpperCase() || "USD"; // || are for tests
var two = result[Object.keys(result)[2]].toUpperCase() || "BAM";
if (!isNaN(parseFloat(result[Object.keys(result)[0]]))) {
console.log('Thank you for using this , Plase wait a moment...');
request({
method: 'GET',
url: 'http://www.xe.com/currencyconverter/convert/?Amount=' + much + '&From=' + one + '&To=' + two,
}, function (err, response, body) {
var test_if_title = false;
if (err) return console.error(err);
// Tell Cherrio to load the HTML
$ = cheerio.load(body);
var title = $('.wrapper .bodyContent .quickFixesTopModule .uccResultContainer #ucc-container .uccResultAmount').eq(0).text();
if (title == 0.00) {
console.log(colors.red('⊙﹏⊙ Something went wrong, maybe you put wrong data ⊙﹏⊙'));
return null;
} else {
console.log("\n$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n•_•) ( ゚o゚) (•_• \n$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ \n \n" + colors.yellow(result[Object.keys(result)[0]]) + ' ' + one.bgMagenta + ' is equal to '.white + '('.green + title.green + ') '.green + two.bgMagenta + "\n \n$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ \n•_•) ( ゚o゚) (•_•\n$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ \n");
return title;
}
});
} else {
console.log(colors.red('⊙﹏⊙ Type error , one the arguments was wrong , try again'));
return null;
}
}
module.exports = toTest;
run();