-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
33 lines (26 loc) · 873 Bytes
/
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
const fs = require("fs");
const http = require("https");
const init = async () => {
let readData = fs.readFileSync("README.md", "utf8");
readData = readData.toString();
http.request("https://api.adviceslip.com/advice", function (res) {
res.setEncoding("utf8");
res.on("data", function (chunk) {
let data = JSON.parse(chunk);
console.log(data);
let adviceTxt = `<!-- ADVICE:START -->\n<p align="center"><br><i>${data.slip.advice}</i><br></p>\n<!-- ADVICE:END -->`;
readData = readData.replace(
/(?:<!-- ADVICE:START -->)([\s\S]*)(?:<!-- ADVICE:END -->)/g,
adviceTxt
);
console.log(adviceTxt);
fs.writeFile("README.md", readData, function (err) {
if (err) {
return console.log(err);
}
console.log("The file was saved!");
});
});
}).end();
};
init();