-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathocr.js
128 lines (115 loc) · 3.64 KB
/
ocr.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import fetch from "node-fetch";
import boidInfo from "./data/data.js";
import colors from "colors";
import promptSync from "prompt-sync";
import { createSpinner } from "nanospinner";
import { createWorker, OEM } from "tesseract.js";
const prompt = promptSync();
const url = "https://iporesult.cdsc.com.np/";
const sleep = (ms = 2000) => new Promise((r) => setTimeout(r, ms));
const getData = () => {
return fetch(url + "result/companyShares/fileUploaded")
.then((res) => res.json())
.catch((err) => {
console.error("Error:", err);
process.exit(1);
});
};
const postData = async (userID, v, userCaptcha, captchaIdentifier) => {
try {
const res = await fetch(url + "result/result/check", {
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
companyShareId: userID,
boid: v,
userCaptcha: userCaptcha,
captchaIdentifier: captchaIdentifier,
}),
method: "POST",
});
return await res.json();
} catch (error) {
console.log("Something went wrong!".red.bold.underline);
}
};
const workers = [];
boidInfo.map((user) => {
if (user.boid)
workers.push(
createWorker({
cachePath: ".",
cacheMethod: "refresh",
})
);
});
getData()
.then((data) => {
if (data.error) throw "Data Not Found!";
const details = [];
data.body.companyShareList.map((company) => {
details.push({ id: company.id, name: company.name });
});
details.map((a) => console.log(a.id, "=>", a.name));
console.log("");
const userID = prompt("Choose: ");
const checking = details.filter((a) => a.id == userID)[0];
console.log("Checking Result of", `${checking.name}`.cyan.underline, "\n");
const result = async (worker, v, captchaSpinner) => {
let userCaptcha,
captcha,
captchaIdentifier = null;
await worker.load();
await worker.loadLanguage("eng");
await worker.initialize("eng");
await worker.setParameters({
init_oem: OEM.TESSERACT_LSTM_COMBINED,
tessedit_char_whitelist: "0123456789",
});
while (true) {
let data = await getData();
({ captcha, captchaIdentifier } = data.body.captchaData);
let captchaImg = Buffer.from(captcha, "base64");
let {
data: { text },
} = await worker.recognize(captchaImg);
userCaptcha = text.replace(/[^0-9]/g, "");
let results = await postData(userID, v, userCaptcha, captchaIdentifier);
if (
results.message &&
results.message !== "Invalid Captcha Provided. Please try again "
) {
await worker.terminate();
captchaSpinner.success({ text: "Completed!" });
return results;
}
}
};
let workerIndex = 0;
boidInfo.map(async (user) => {
if (user.boid) {
const captchaSpinner = createSpinner("Solving CAPTCHA...").start();
await sleep();
result(workers[workerIndex++], user.boid, captchaSpinner).then((r) =>
typeof r === "undefined"
? console.log(
`${user.name} => Possible Error: Incorrect BOID`.yellow + "\n"
)
: r.success === true
? console.log(
`Congratulations! ${
user.name
}. IPO Alloted. Alloted quantity: ${r.message.split(" ")[6]} `
.bgGreen.black + "\n"
)
: r.success === false &&
console.log(`${user.name} => Sorry not Alloted`.yellow + "\n")
);
}
});
})
.catch((err) => {
console.error("Error:", err);
process.exit(1);
});