2022-01-06 13:04:03 +01:00
|
|
|
/* eslint-disable @typescript-eslint/no-var-requires */
|
2022-04-07 01:30:08 +02:00
|
|
|
const https = require("https");
|
|
|
|
const fs = require("fs").promises;
|
|
|
|
const path = require("path");
|
2022-01-06 13:04:03 +01:00
|
|
|
|
2022-04-07 01:30:08 +02:00
|
|
|
const key = process.argv[2];
|
2022-01-06 13:04:03 +01:00
|
|
|
|
|
|
|
function getRawJSON() {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
const options = {
|
2022-04-07 01:30:08 +02:00
|
|
|
hostname: "api.steampowered.com",
|
2022-01-06 13:04:03 +01:00
|
|
|
port: 443,
|
|
|
|
path: `/ISteamUserStats/GetSchemaForGame/v0002/?appid=1812820&key=${key}`,
|
2022-04-07 01:30:08 +02:00
|
|
|
method: "GET",
|
2022-01-06 13:04:03 +01:00
|
|
|
headers: {
|
|
|
|
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:95.0) Gecko/20100101 Firefox/95.0",
|
2022-04-07 01:30:08 +02:00
|
|
|
Accept: "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8",
|
|
|
|
},
|
|
|
|
};
|
2022-01-06 13:04:03 +01:00
|
|
|
|
|
|
|
let data = [];
|
2022-04-07 01:30:08 +02:00
|
|
|
const req = https.request(options, (res) => {
|
|
|
|
console.log(`statusCode: ${res.statusCode}`);
|
2022-01-06 13:04:03 +01:00
|
|
|
|
2022-04-07 01:30:08 +02:00
|
|
|
res.on("data", (chunk) => {
|
|
|
|
data.push(chunk);
|
|
|
|
});
|
2022-01-06 13:04:03 +01:00
|
|
|
|
2022-04-07 01:30:08 +02:00
|
|
|
res.on("end", () => {
|
|
|
|
console.log("Response ended: ");
|
2022-01-06 13:04:03 +01:00
|
|
|
resolve(Buffer.concat(data).toString());
|
|
|
|
});
|
2022-04-07 01:30:08 +02:00
|
|
|
});
|
2022-01-06 13:04:03 +01:00
|
|
|
|
2022-04-07 01:30:08 +02:00
|
|
|
req.on("error", (error) => {
|
|
|
|
console.error(error);
|
2022-01-06 13:04:03 +01:00
|
|
|
req.end();
|
|
|
|
reject(error);
|
|
|
|
});
|
|
|
|
|
|
|
|
req.end();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async function fetchAchievementsData() {
|
|
|
|
const raw = await getRawJSON();
|
|
|
|
const o = JSON.parse(raw);
|
|
|
|
const achievements = {};
|
|
|
|
o.game.availableGameStats.achievements.forEach((a) => {
|
|
|
|
achievements[a.name] = {
|
|
|
|
ID: a.name,
|
|
|
|
Name: a.displayName,
|
|
|
|
Description: a.description,
|
|
|
|
};
|
2022-04-07 01:30:08 +02:00
|
|
|
});
|
2022-01-06 13:04:03 +01:00
|
|
|
|
|
|
|
const data = {
|
2022-04-07 01:30:08 +02:00
|
|
|
note: "***** Generated from a script, overwritten by steam achievements data *****",
|
2022-01-06 13:04:03 +01:00
|
|
|
fetchedOn: new Date().getTime(),
|
|
|
|
achievements,
|
2022-04-07 01:30:08 +02:00
|
|
|
};
|
2022-01-06 13:04:03 +01:00
|
|
|
|
2022-04-07 01:30:08 +02:00
|
|
|
const jsonPath = path.resolve(__dirname, "../src/Achievements/AchievementData.json");
|
2022-01-06 13:04:03 +01:00
|
|
|
await fs.writeFile(jsonPath, JSON.stringify(data, null, 2));
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2022-04-07 01:30:08 +02:00
|
|
|
fetchAchievementsData().then((json) => console.log(JSON.stringify(json, null, 2)));
|