Skip to content

Instantly share code, notes, and snippets.

@mcpie87
Created April 7, 2021 22:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mcpie87/b20e8e4ad83ec0b666ebc53ecb3980be to your computer and use it in GitHub Desktop.
Save mcpie87/b20e8e4ad83ec0b666ebc53ecb3980be to your computer and use it in GitHub Desktop.
GI - extract wish history (node 14)
const https = require('https')
const fs = require('fs');
const FEEDBACK_URL = "PLACE YOUR FEEDBACK URL HERE"
const PAGE_SIZE = 20;
const DELAY = 1000;
const GACHA_MAP = {
"STANDARD": 200,
"NOVICE": 100,
"WEAPON": 302,
"CHARACTER": 301
}
const GACHA_TYPE_NAME = process.argv[2];
const GACHA_TYPE = GACHA_MAP[process.argv[2]];
if (!GACHA_TYPE) {
console.log("Invalid gacha type. Available types are:\n" + Object.keys(GACHA_MAP).map(e => "\t- " + e).join("\n"))
process.exit(0);
}
const feedbackParams = new URLSearchParams(FEEDBACK_URL)
const queryParams = new URLSearchParams({
"authkey_ver": "1",
"sign_type": "2",
"auth_appid": "webview_gacha",
"init_type": "301",
"gacha_id": "b8fd0d8a6c940c7a16a486367de5f6d2232f53",
"lang": "en",
"device_type": "pc",
"game_version": feedbackParams.get("game_version"),
"region": "os_euro",
"authkey": feedbackParams.get("authkey"),
"game_biz": "hk4e_global",
"gacha_type": GACHA_TYPE,
"page": 1,
"size": PAGE_SIZE,
"end_id": 0
});
const pages = {};
let page = 1;
let lastId = 0;
function getGachaLog() {
const options = {
hostname: 'hk4e-api-os.mihoyo.com',
port: 443,
path: `/event/gacha_info/api/getGachaLog?${queryParams.toString()}`,
method: 'GET',
}
const req = https.request(options, res => {
console.log(`statusCode: ${res.statusCode}`)
let data = [];
res.on('data', (chunk) => {
data.push(chunk);
})
res.on('end', () => {
const tmp = JSON.parse(Buffer.concat(data).toString());
if (tmp.retcode !== 0 || tmp.message !== "OK" || typeof tmp.data !== "object") {
throw ('you broke it');
}
pages[tmp.data.page] = tmp.data.list;
page += 1;
const n = tmp.data.list.length;
lastId = n > 0 && n <= PAGE_SIZE ? tmp.data.list[n - 1].id : 0;
queryParams.set('page', page);
queryParams.set('end_id', lastId);
if (page > 1 && lastId === 0) {
console.log("Finished, saving to " + GACHA_TYPE_NAME + ".json");
const combined = []
for (p in pages) { Array.prototype.push.apply(combined, pages[p]); }
fs.writeFile(`${GACHA_TYPE_NAME}.json`, JSON.stringify(combined, null, 2), (err) => {
console.log(err);
});
}
else {
console.log(`Receiving page ${page}... lastId ${lastId}`);
setTimeout(getGachaLog, DELAY);
}
})
})
req.on('error', error => {
console.error(error)
})
req.end();
}
getGachaLog();
@mcpie87
Copy link
Author

mcpie87 commented Apr 7, 2021

Usage:

node extract-wishes.js [STANDARD/NOVICE/WEAPON/CHARACTER]

will create a json file for selected category

First you need to prepare feedback url from Paimon Menu -> Feedback -> copy url in opened browser and replace PLACE YOUR FEEDBACK URL HERE with your url

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment