forked from eth-collision/eth-collision-random
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfileCount.js
More file actions
48 lines (44 loc) · 1.15 KB
/
fileCount.js
File metadata and controls
48 lines (44 loc) · 1.15 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
const { ethers } = require("ethers");
const axios = require("axios");
const fs = require("fs");
const { apiKey, tgKey, tgChatId } = require("./config.js");
function sendTgMsg(message) {
const { tgKey, tgChatId } = require("./config.js");
const url = `https://api.telegram.org/bot${tgKey}/sendMessage`;
axios.post(url, {
chat_id: tgChatId,
text: message,
});
}
function getFileCount(file) {
return new Promise((resolve, reject) => {
var i;
var count = 0;
fs.createReadStream(file)
.on("data", function (chunk) {
for (i = 0; i < chunk.length; ++i) if (chunk[i] == 10) count++;
})
.on("end", function () {
resolve(count);
})
.on("error", function (err) {
resolve(0);
});
});
}
function countFile() {
let msg = "";
Promise.all([
getFileCount("no-random.txt").then((res) => (msg += `No: ${res}\n`)),
getFileCount("yes-random.txt").then(
(res) => (msg += `Yes: ${res}\n`)
),
getFileCount("err-random.txt").then(
(res) => (msg += `Err: ${res}\n`)
),
]).then(() => {
sendTgMsg(msg);
});
}
countFile();
setInterval(countFile, 60 * 60 * 1000);