-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget-reviews.js
52 lines (40 loc) · 1.21 KB
/
get-reviews.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
52
const fetch = require("node-fetch");
const fs = require("fs");
const reviewsDir = "../jobguy/reviews/";
if (!fs.existsSync(reviewsDir)) {
fs.mkdirSync(reviewsDir);
}
fs.readdir("../jobguy/companies/", async (err, companies) => {
var errors = [];
var rawData, data, reviewJson;
for (const companyName of companies) {
path = `../jobguy/companies/${companyName}/`;
console.log(`Company: ${companyName}`);
rawData = fs.readFileSync(`${path}review.json`);
data = JSON.parse(rawData);
if (data.data.length) {
for (const review of data.data) {
try {
var response = await fetch(
"https://api.jobguy.ir/public/company_review/" + review.id
);
if (!response.ok) {
throw response.status;
}
console.info(`${review.id}: ✅`);
reviewJson = await response.json();
fs.writeFileSync(
`${reviewsDir}${review.id}.json`,
JSON.stringify(reviewJson)
);
} catch (error) {
errors.push(review.id);
console.error(`${review.id}: ❌`);
}
}
}
}
if (errors) {
fs.writeFileSync(`reviews-errors.json`, JSON.stringify(errors));
}
});