-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
44 lines (34 loc) · 908 Bytes
/
index.js
File metadata and controls
44 lines (34 loc) · 908 Bytes
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
// index.js
const Mustache = require('mustache');
const request = require('request');
const fs = require('fs');
const MUSTACHE_MAIN_DIR = './main.mustache';
var options = {
url: 'https://quotes.rest/qod?language=en',
json: true,
headers: {
'Authorization': 'Bearer ' + process.env.apiKey
}
};
request(options, function(error, response, body){
if (error) {
generateReadMe("Err", "or");
} else {
console.log(body);
quote = body["contents"]["quotes"][0]["quote"];
author = body["contents"]["quotes"][0]["author"];
generateReadMe(quote, author)
}
});
function generateReadMe(quote, author) {
let DATA = {
quote: quote,
quoteauthor: author
};
fs.readFile(MUSTACHE_MAIN_DIR, (err, data) => {
if (err) throw err;
const output = Mustache.render(data.toString(), DATA);
fs.writeFileSync('README.md', output);
});
}
generateReadMe();