-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patht.js
More file actions
64 lines (60 loc) · 1.98 KB
/
t.js
File metadata and controls
64 lines (60 loc) · 1.98 KB
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
63
64
import { args } from './util/common.js';
import { splinterApi, createPage } from './splinterApi.js';
import { createWriteStream } from 'node:fs';
const filePath = 'data/network.jsonl';
const JsonLStreamer = (filePath) => {
const stream = createWriteStream(filePath, 'utf-8');
return {
write: async (record) => {
const line = JSON.stringify(record) + '\n';
// Respect backpressure
if (!stream.write(line)) {
await new Promise((resolve) => stream.once('drain', resolve));
}
},
end: () => stream.end(),
on: stream.on,
};
};
const stream = JsonLStreamer(filePath);
const page = await createPage(args);
page.on('requestfinished', async (request) => {
const url = request.url();
if (url.match(/googletagmanager|cloudfront.net|splinterlands.zendesk.com/))
return;
if (url.match(/g.doubleclick|google.co|appleid.cdn|zdassets.com/)) return;
if (url.match(/config.js|settings$|bootstrap|cdn.jsdelivr|\/auctions\//))
return;
const respHeaders = request.response().headers();
if (
respHeaders['content-type'] &&
respHeaders['content-type'].includes`/json;`
) {
try {
const response = await request.response().json();
stream.write({ response, url });
} catch (e) {
console.log(respHeaders);
console.log(e);
}
}
});
const nSM = await splinterApi(
page,
{ account: args.ACCOUNT[2], password: args.PASSWORD[2] },
args,
);
await nSM.login();
for (let i = 0; i < 222; i++) {
console.log({ i });
nSM.clickButtonWith('MODERN');
for (const urlRegex of [/battle-history/, /find-match/])
!(await page
.waitForFunction(() => document.URL.match(urlRegex), {
timeout: 1e5,
polling: 1e3,
})
.catch(console.log));
const details = await parseBattleDetails().catch(console.log);
console.log(details);
}