-
Notifications
You must be signed in to change notification settings - Fork 34
/
index.js
40 lines (31 loc) · 901 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
34
35
36
37
38
39
40
const axios = require("axios");
const fs = require("fs");
const getQuote = async () => {
try {
const { data } = await axios.get("https://api.goprogram.ai/inspiration");
const quote = data.quote;
const author = data.author;
console.log("new quote", `"${quote}"`);
return {
quote,
author,
};
} catch (err) {
console.error(err.message);
return {};
}
};
const generate = async () => {
const { quote, author } = await getQuote();
if (!quote) return;
const content = fs.readFileSync("README.md", "utf8");
const lastIndex = content.indexOf("⚡");
if (lastIndex !== -1) {
let subContent = content.substring(0, lastIndex);
subContent += `⚡ Quote: \n**${quote}**\n\n${author}`
fs.writeFileSync("README.md", subContent);
return;
}
fs.appendFileSync("README.md", `⚡ Quote: \n**${quote}**\n\n${author}`);
};
generate();