-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathss-example.js
93 lines (75 loc) · 1.91 KB
/
ss-example.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
SS Example — do pongs on different accounts and write account and response duration
*/
require("isomorphic-fetch");
const dotenv = require("dotenv");
const Sendsay = require("sendsay-api");
const fs = require("fs");
const { Parser } = require("json2csv");
const cliProgress = require("cli-progress");
const INPUT_FILE = "logins.txt";
const OUTPUT_FILE = "pongs.csv";
const bar = new cliProgress.SingleBar(
{
format: "Making queries: {value}/{total} [ {bar} — {percentage}% ]",
},
cliProgress.Presets.shades_classic
);
const sendsay = new Sendsay();
const json2csvParser = new Parser();
const loginToAccount = (login) =>
sendsay
.login({
login: login.trim(),
password: process.env.MAGIC_PASS,
})
.then(() => true)
.catch((err) => {
console.log(`error with: ${login} — ${err}`);
return false;
});
const doQuery = async (login) => {
/*
Do the query for each account
*/
const query = {
action: "pong",
};
return sendsay
.request(query)
.then((res) => {
/*
Here you can get some data from response.
Use API console to explore shapes of server response.
*/
return {
login: res.account,
duration: res.duration,
};
})
.catch((err) => {
console.log(`error with: ${login} — ${err}`);
return {
login: res.account,
duration: res.duration,
};
});
};
const processLineByLine = async () => {
const data = fs.readFileSync(INPUT_FILE, "UTF-8");
const logins = data.split(/\r?\n/).filter((s) => !!s);
const result = [];
bar.start(logins.length, 0);
for (const login of logins) {
if (await loginToAccount(login)) {
result.push(await doQuery(login));
bar.increment();
}
}
return result;
};
dotenv.config();
processLineByLine().then((res) => {
bar.stop();
fs.writeFileSync(OUTPUT_FILE, json2csvParser.parse(res));
});