bitburner-src/tools/fetch-steam-achievements-data.js

69 lines
1.8 KiB
JavaScript
Raw Normal View History

/* 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-04-07 01:30:08 +02:00
const key = process.argv[2];
function getRawJSON() {
return new Promise((resolve, reject) => {
const options = {
2022-04-07 01:30:08 +02:00
hostname: "api.steampowered.com",
port: 443,
path: `/ISteamUserStats/GetSchemaForGame/v0002/?appid=1812820&key=${key}`,
2022-04-07 01:30:08 +02:00
method: "GET",
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",
},
};
let data = [];
2022-04-07 01:30:08 +02:00
const req = https.request(options, (res) => {
console.log(`statusCode: ${res.statusCode}`);
2022-04-07 01:30:08 +02:00
res.on("data", (chunk) => {
data.push(chunk);
});
2022-04-07 01:30:08 +02:00
res.on("end", () => {
console.log("Response ended: ");
resolve(Buffer.concat(data).toString());
});
2022-04-07 01:30:08 +02:00
});
2022-04-07 01:30:08 +02:00
req.on("error", (error) => {
console.error(error);
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
});
const data = {
2022-04-07 01:30:08 +02:00
note: "***** Generated from a script, overwritten by steam achievements data *****",
fetchedOn: new Date().getTime(),
achievements,
2022-04-07 01:30:08 +02:00
};
2022-04-07 01:30:08 +02:00
const jsonPath = path.resolve(__dirname, "../src/Achievements/AchievementData.json");
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)));