-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·73 lines (62 loc) · 1.49 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
69
70
71
72
73
#! /usr/bin/env node
'use strict';
const request = require('request');
const debug = false
if(debug){
var url_to_use = 'http://localhost:5000/api/v1'
} else {
var url_to_use = 'https://a3odwonexi.execute-api.us-east-2.amazonaws.com/default/Bars_API'
}
var all_args = process.argv
if(all_args.length>2){
var val_args = all_args.slice(2)
var my_json_body = {
method: 'getRandomQuote',
category: val_args
}
var options = {
url: url_to_use,
method: 'POST',
json: true,
body: my_json_body
};
} else {
var options = {
url: url_to_use,
method: 'GET'
};
}
var r = request(options, function(error, response, body) {
if (error) {
console.error(error);
}
if (response.statusCode === 200) {
// bc sometimes it gets returned in strange format? idk what im doing
if(body.toString() === "[object Object]"){
var new_body = body
} else {
var new_body=JSON.parse(body)
}
if(new_body.meta.code > 399){
console.log(new_body.error.message)
} else {
var lyric = new_body.data.lyric
var song = new_body.data.song
var author = new_body.data.author
if(song.length>0){
console.log(lyric, '--',author, 'in' ,song)
} else {
console.log(lyric, '--', author);
}
}
} else {
console.log(JSON.stringify(body))
console.error('Error:', response.statusCode, ':', response.statusMessage);
}
});
//r.end();
function endIt(){
r.end()
process.exit(1)
}
setTimeout(endIt,1500)