works for poco phone m4

This commit is contained in:
2023-10-25 16:22:05 +02:00
parent a36a9cf7cb
commit 6772283ede
4 changed files with 78 additions and 73 deletions
+21 -34
View File
@@ -4,6 +4,7 @@ const OCRResult = require("../models/OCRResult");
const Jimp = require('jimp');
const fs = require("fs");
const {exec} = require("child_process");
const findText = require("../utiles/CmdUtils");
function delay(delayInMs) {
return new Promise(resolve => {
@@ -70,19 +71,6 @@ const BRAVE_SKIP_DEFAULT_PAGE_2 = "définissant Brave"
const BRAVE_SKIP_PRIVACY_PAGE = "Partagez des informations"
const BRAVE_SKIP_PRIVACY_PAGE_2 = "Partagez des renseignements"
async function convertImageToWhiteBlack(image_path, device) {
console.log("convertImageToWhiteBlack for " + device.serial())
try {
const image = await Jimp.read(image_path);
image.grayscale().write(image_path + ".wb");
return image_path + ".wb";
} catch (e) {
console.log(e)
return image_path
}
}
class OCRChecker {
constructor(device, contact) {
@@ -98,49 +86,52 @@ class OCRChecker {
async get_result() {
let fileName = await this.take_screen_shot()
let screenShot = await convertImageToWhiteBlack(fileName, this.device);
// let screenShot = await convertImageToWhiteBlack(fileName, this.device);
await delay(1000)
try {
let result = await tesseract
.recognize(screenShot, config)
let result = await findText(fileName)
console.log(result)
if (result.includes(MESSAGE_URL_VALIDATION_EN) || result.includes(MESSAGE_URL_VALIDATION_FR) || result.includes(MESSAGE_URL_VALIDATION_FR_2)) {
await this.deleteFile(fileName)
await this.deleteFile(screenShot)
// await this.deleteFile(screenShot)
return OCRResult.SUCCESS
} else if (result.includes(MESSAGE_FILL_FIELD_FR) || result.includes(MESSAGE_FILL_FIELD_FR_2) || result.includes(MESSAGE_FILL_FIELD_FR_3) || result.includes(MESSAGE_FILL_FIELD_FR_4) || result.includes(MESSAGE_FILL_FIELD_FR_5)) {
await this.deleteFile(fileName)
await this.deleteFile(screenShot)
// await this.deleteFile(screenShot)
return OCRResult.FILL_FIELD
} else if (result.includes(CAPTCHA_ERROR_MESSAGE) || result.includes(CAPTCHA_ERROR_MESSAGE_FR)) {
return OCRResult.RECAPTCHA_ERROR
} else if (result.includes(BLOCKED_MSG_EN) || result.includes(BLOCKED_MSG_FR) || result.includes(BLOCKED_MSG_FR_2)) {
await this.deleteFile(fileName)
await this.deleteFile(screenShot)
// await this.deleteFile(screenShot)
return OCRResult.BLOCKED
} else if (result.includes(ERR_CACHE_MISS) || result.includes(ERR_CACHE_MISS_2) || result.includes(ERR_CACHE_MISS_3) || result.includes(ERR_CACHE_MISS_4)) {
return OCRResult.TO_REFRESH
} else if (result.includes(CHECKING_MSG_FR) || result.includes(CHECKING_MSG_FR_2)) {
await this.deleteFile(fileName)
await this.deleteFile(screenShot)
// await this.deleteFile(screenShot)
return OCRResult.RECHECK
} else if (result.includes(BRAVE_NOTIFICATION)) {
await this.deleteFile(fileName)
// await this.deleteFile(screenShot)
return OCRResult.BRAVE_NOTIFICATION
} else if (result.includes(SLIDING_CAPTCHA_FR) || result.includes(SLIDING_CAPTCHA_FR_2) || result.includes(SLIDING_CAPTCHA_FR_3) || result.includes(SLIDING_CAPTCHA_FR_4)) {
await this.deleteFile(fileName)
await this.deleteFile(screenShot)
// await this.deleteFile(screenShot)
// if (result.includes("rac"))
// return OCRResult.SLIDING_CAPTCHA_REFRESH
return OCRResult.SLIDING_CAPTCHA
} else if (result.includes(WELCOME_MESSAGE_FR)) {
await this.deleteFile(fileName)
await this.deleteFile(screenShot)
// await this.deleteFile(screenShot)
return OCRResult.NEED_TO_CLICK_LATE_BTN
} else if (result.includes(GOOGLE_DISCONNECT_FR) || result.includes(GOOGLE_DISCONNECT_FR_1)) {
await this.deleteFile(fileName)
await this.deleteFile(screenShot)
// await this.deleteFile(screenShot)
return OCRResult.GOOGLE_DISCONNECT
} else if (result.toLowerCase().includes(ONLINE_APPOINTMENT.toLowerCase())) {
await this.deleteFile(fileName)
await this.deleteFile(screenShot)
// await this.deleteFile(screenShot)
return OCRResult.ONLINE_APPOINTMENT
} else if (result.includes(PAGE_OPTIMIZATION_CHROME_FR) || result.includes(PAGE_OPTIMIZATION_CHROME_FR_2) || result.includes(PAGE_OPTIMIZATION_CHROME_FR_3)
|| result.includes(PAGE_OPTIMIZATION_CHROME_FR_4) || result.includes(PAGE_OPTIMIZATION_CHROME_FR_5)
@@ -149,11 +140,11 @@ class OCRChecker {
|| result.includes(PAGE_OPTIMIZATION_CHROME_FR_7)
) {
await this.deleteFile(fileName)
await this.deleteFile(screenShot)
// await this.deleteFile(screenShot)
return OCRResult.PAGE_OPTIMIZATION
} else if (result.includes(CONFIRM_RESEND_FORM_FR)) {
await this.deleteFile(fileName)
await this.deleteFile(screenShot)
// await this.deleteFile(screenShot)
return OCRResult.CONFIRM_RESEND_FORM
} else if (result.includes(CLOSED_MESSAGE_FR)) {
return OCRResult.CLOSED
@@ -161,7 +152,7 @@ class OCRChecker {
return OCRResult.TERMINAED
} else if (result.includes(DIALOG_TO_SKIP)) {
await this.deleteFile(fileName)
await this.deleteFile(screenShot)
// await this.deleteFile(screenShot)
return OCRResult.TO_SKIP
} else if (result.includes(RECAPTCHA_FAILED_FR)) {
return OCRResult.TERMINAED
@@ -169,19 +160,15 @@ class OCRChecker {
return OCRResult.NO_INTERNET
} else if (result.includes(BRAVE_SKIP_DEFAULT_PAGE) || result.includes(BRAVE_SKIP_DEFAULT_PAGE_2)) {
await this.deleteFile(fileName)
await this.deleteFile(screenShot)
// await this.deleteFile(screenShot)
return OCRResult.BRAVE_SKIP
} else if (result.includes(BRAVE_SKIP_PRIVACY_PAGE) || result.includes(BRAVE_SKIP_PRIVACY_PAGE_2)) {
await this.deleteFile(fileName)
await this.deleteFile(screenShot)
// await this.deleteFile(screenShot)
return OCRResult.BRAVE_PRIVACY
} else if (result.includes(BRAVE_NOTIFICATION)) {
await this.deleteFile(fileName)
await this.deleteFile(screenShot)
return OCRResult.BRAVE_NOTIFICATION
} else if (result.includes(BRAVE_SKIP_PUB) || result.includes(BRAVE_SKIP_PUB_2) || result.includes(BRAVE_SKIP_PUB_3) || result.includes(BRAVE_SKIP_PUB_4) || result.includes(BRAVE_SKIP_PUB_5)) {
await this.deleteFile(fileName)
await this.deleteFile(screenShot)
// await this.deleteFile(screenShot)
return OCRResult.BRAVE_PRIVACY_PUB
} else {
return OCRResult.TERMINAED