-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
46 lines (37 loc) · 1.75 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
44
45
46
import { promises as fs } from "fs";
import axios from "axios";
import dotenv from "dotenv";
dotenv.config();
const LATEST_IMAGES_YOUTUBE1 = "%{{latest_images_youtube1}}%";
const LATEST_IMAGES_YOUTUBE2 = "%{{latest_images_youtube2}}%";
const LATEST_IMAGES_YOUTUBE3 = "%{{latest_images_youtube3}}%";
async function handler() {
try {
const markdownTemplate = await fs.readFile("./README.md.tpl", {
encoding: "utf-8",
});
const responseYoutube = await axios.get(
`https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=${process.env.CHANNELID}&maxResults=10&order=date&type=video&key=${process.env.API_KEY}`
);
const youtubeItems = responseYoutube.data.items;
// YOUTUBE
const youtubePost1 = `<a href="https://www.youtube.com/watch?v=${youtubeItems[0].id.videoId}" target='_blank'>
<img width='30%' src="${youtubeItems[0].snippet.thumbnails.high.url}" alt="${youtubeItems[0].snippet.title}" />
</a>`;
const youtubePost2 = `<a href="https://www.youtube.com/watch?v=${youtubeItems[1].id.videoId}" target='_blank'>
<img width='30%' src="${youtubeItems[1].snippet.thumbnails.high.url}" alt="${youtubeItems[1].snippet.title}" />
</a>`;
const youtubePost3 = `<a href="https://www.youtube.com/watch?v=${youtubeItems[2].id.videoId}" target='_blank'>
<img width='30%' src="${youtubeItems[2].snippet.thumbnails.high.url}" alt="${youtubeItems[2].snippet.title}" />
</a>`;
const newMarkdown = markdownTemplate
// YOUTUBE
.replace(LATEST_IMAGES_YOUTUBE1, youtubePost1)
.replace(LATEST_IMAGES_YOUTUBE2, youtubePost2)
.replace(LATEST_IMAGES_YOUTUBE3, youtubePost3);
await fs.writeFile("./profile/README.md", newMarkdown);
} catch (error) {
console.log("Ocurrió un error " + error);
}
}
handler();