-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerateTelemetry.js
62 lines (48 loc) · 1.59 KB
/
generateTelemetry.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
60
61
62
const puppeteer = require("puppeteer");
const { promisify } = require("util");
const path = require("path");
const fs = require("fs");
const RESULT_DIR = path.join(__dirname, "result");
const writeFileSync = promisify(fs.writeFileSync);
if (!fs.existsSync(RESULT_DIR)) fs.mkdirSync(RESULT_DIR);
(async () => {
const browser = await puppeteer.launch({ headless: false });
const page = await browser.newPage();
console.log("> GO TO RSIM");
await page.goto("https://www.rocket-simulator.com/csimulator.php", {
timeout: 0,
});
console.log("> FORM SUBMIT");
await page.$eval('input[name="t1"]', (el) => (el.value = "101"));
await page.$eval('form[name="form1"]', (form) => form.submit());
await page.waitForNavigation({ waitUntil: "networkidle0", timeout: 0 });
console.log("> IDLE");
page.on("error", () => {
console.log("Reload");
page.reload();
});
const telemetries = await page.evaluate(() => {
const rows = document.querySelectorAll("#AutoNumber1 tr");
const arr = Array.from(rows, (row) => {
const columns = row.querySelectorAll("td");
return Array.from(columns, (column) => column.innerText);
});
arr.shift();
return arr;
});
console.log("> EVALUATE");
await browser.close();
console.log("> CLOSED");
const indexs = telemetries.shift();
const mainData = telemetries.map((telemetry) => {
const output = {};
indexs.forEach((key, idx) => {
output[key] = telemetry[idx];
});
return output;
});
await writeFileSync(
path.join(RESULT_DIR, "telemetry.json"),
JSON.stringify(mainData, null, 2)
);
})();