-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
43 lines (40 loc) · 1.22 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
const { exec } = require("child_process");
const fs = require("fs");
const readline = require("readline");
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.question("Do you want to rhyme somehting?\n\n", value => {
const re = new RegExp(/y|ok|sure|fine/gi);
if (re.test(value)) {
rl.question(
"\n\x1b[34mGreat! What word would you like to rhyme?\x1b[0m \n \n",
value => {
exec(
`curl https://api.datamuse.com/words\?rel_rhy\=${value}`,
(error, stdout, stderr) => {
if (error) throw error;
const date = new Date();
const bestof = JSON.parse(stdout);
fs.writeFile(
`./results/${value}-rhyme-from-${date}.json`,
stdout,
err => err ? (() => {throw new err})() : []
);
console.log(
`\x1b[36m \nYour rhymes are saved and rated in file:\x1b[0m ${value}-rhyme-from-${date}.json!`
);
console.log(
`\nThe best result was\x1b[35m ${bestof[0].word}. \x1b[0m`
);
rl.close();
}
);
}
);
} else {
console.log("Too bad...");
rl.close();
}
});