-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
51 lines (45 loc) · 1.29 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
47
48
49
50
51
require("dotenv").config();
const readline = require("readline-sync");
const cron = require("node-cron");
const fetch = require("node-fetch");
const fs = require("fs");
require("colors");
const attendees = new Set();
const minutes = 3;
const date = new Date();
const dateString = `${date.getDate()}-${
date.getMonth() + 1
}-${date.getFullYear()}`;
const fetchAttendance = async () => {
const URL = `${process.env.API_KEY}&id=${meetID}`;
try {
const res = await fetch(URL);
const attendance = (await res.json()).attendance;
if (attendance) {
attendance.forEach((e) => attendees.add(e));
fs.writeFileSync(
`./attendances/${meetID} ${dateString}.csv`,
`Name\n${[...attendees].join("\n")}`,
{ flag: "w" }
);
console.log(
`${new Date().toLocaleTimeString()}`,
`: Fetched Attendance Now`.blue.bold
);
}
} catch (e) {
console.error("Some error occured".red);
}
};
const meetID = readline
.question("Enter the meet ID: ".yellow.red)
.replace("https://meet.google.com/", "");
if (meetID === "") {
console.error("Enter ID Properly".red.bold);
return;
}
console.log(`Fetching attendance every ${minutes} minutes`.green.bold);
fetchAttendance();
cron.schedule(`*/${minutes} * * * *`, () => {
fetchAttendance();
});