-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgifd.js
84 lines (70 loc) · 2.04 KB
/
gifd.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
74
75
76
77
78
79
80
81
82
83
84
// Generated by CoffeeScript 1.7.1
(function() {
var args, asciimo, colors, copypaste, feeling, fetchGif, http, key, next, readline, url;
readline = require('readline');
http = require('http');
asciimo = require('./node_modules/asciimo/lib/asciimo').Figlet;
colors = require('./node_modules/asciimo/lib/colors');
copypaste = require('copy-paste');
key = "VAa2AVeWXThiu2qD";
url = "http://api.gifme.io/v1/gifs/random?key=" + key;
args = process.argv;
next = false;
feeling = "";
args.forEach(function(val) {
if (next === false) {
if (val.indexOf("gifd") >= 0) {
return next = true;
}
} else {
return feeling = val;
}
});
fetchGif = function(callback) {
return http.get(url, function(res) {
var str;
res.setEncoding('utf8');
str = "";
res.on('data', function(chunk) {
return str += chunk;
});
return res.on('end', function() {
var img, json;
json = JSON.parse(str);
img = json.gif.gif;
return copy(img, function() {
return asciimo.write("Copied!", "banner3", function(art) {
console.log("\n" + art.green);
if (callback) {
return callback();
}
});
});
});
});
};
asciimo.write("gifD", "isometric2", function(art) {
var feelings, rl;
console.log(art.green);
if (feeling === "") {
rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
feelings = ["happy", "sad", "excited", "angry", "lazy", "confused", "bored", "interested"];
feeling = feelings[Math.floor(Math.random() * feelings.length)];
return rl.question("What are you feeling? eg. " + feeling + " ", function(a) {
if (!a) {
a = feeling;
}
url = "" + url + "&term=" + a;
return fetchGif(function() {
return rl.close();
});
});
} else {
url = "" + url + "&term=" + feeling;
return fetchGif();
}
});
}).call(this);