-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
59 lines (41 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
52
53
54
55
56
57
58
59
const axios = require("axios").default;
const fs = require("fs");
const SteamAppId = process.argv[2];
if (isNaN(parseInt(SteamAppId, 10))) {
throw new Error("Enter a valid Steam App ID: yarn start YourSteamAppId");
}
const AppReviewsUrl = `https://store.steampowered.com/appreviews/${SteamAppId}?json=1`;
const params = {
filter: "recent",
language: "all",
day_range: 365, // 365 is max
review_type: "all",
purchase_type: "all",
num_per_page: 100,
};
let NextCursor = "*";
// array of arrays of reviews
let reviews = [];
const PreviousCursors = [];
(async () => {
while (NextCursor) {
params.cursor = encodeURIComponent(NextCursor);
const paramsEncoded = Object.keys(params).map(key => {
return `&${key}=${params[key]}`;
});
const CompleteUrl = AppReviewsUrl + paramsEncoded.join("");
console.log(CompleteUrl);
const content = await axios.get(CompleteUrl);
if (content.status !== 200) {
throw new Error(content.statusText);
}
reviews.push(content.data.reviews);
if (PreviousCursors.includes(content.data.cursor)) {
break;
}
NextCursor = content.data.cursor;
PreviousCursors.push(NextCursor);
}
const joinedReviews = reviews.flat();
fs.writeFileSync("reviews.json", JSON.stringify(joinedReviews, null, 2));
})();