-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget-interviews-comments.js
48 lines (38 loc) · 1.23 KB
/
get-interviews-comments.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
const fetch = require("node-fetch");
const fs = require("fs");
const interviewsDir = "../jobguy/interviews/";
const interviewsCommentsDir = "../jobguy/interviews-comments/";
if (!fs.existsSync(interviewsCommentsDir)) {
fs.mkdirSync(interviewsCommentsDir);
}
fs.readdir(interviewsDir, async (err, interviews) => {
var errors = [];
var interviewId, interviewComments;
for (const interviewFileName of interviews) {
interviewId = interviewFileName.replace(".json", "");
interviewId = parseInt(interviewId);
try {
var response = await fetch(
`https://api.jobguy.ir/public/interview/${interviewId}/comment_list/?size=1000`
);
if (!response.ok) {
throw response.status;
}
console.info(`${interviewId}: ✅`);
interviewComments = await response.json();
if (interviewComments.data.length) {
fs.writeFileSync(
interviewsCommentsDir + interviewId + ".json",
JSON.stringify(interviewComments)
);
}
} catch (error) {
console.error(error);
errors.push(interviewId);
console.error(`${interviewId}: ❌`);
}
}
if (errors) {
fs.writeFileSync(`interviews-comments-errors.json`, JSON.stringify(errors));
}
});