works with disconnect
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
const OCRResult = {
|
||||
SUCCESS: Symbol("SUCCESS"),
|
||||
TO_REFRESH: Symbol("TO_REFRESH"),
|
||||
BLOCKED: Symbol("BLOCKED"),
|
||||
SLIDING_CAPTCHA: Symbol("SLIDING_CAPTCHA"),
|
||||
RECHECK: Symbol("RECHECK"),
|
||||
RECAPTCHA_ERROR: Symbol("RECAPTCHA_ERROR"),
|
||||
}
|
||||
module.exports = OCRResult
|
||||
@@ -2,6 +2,7 @@ const {SolveCaptcha, TWO_CAPTCHA_CONNECTION_FAILED} = require("./SolveCaptcha");
|
||||
const ReserveResultPojo = require("../models/ReserveResultPojo");
|
||||
const BlackListContactPojo = require("../models/BlackListContactPojo");
|
||||
const appointmentLogger = require("../utiles/LoggerUtils")
|
||||
const OCRResult = require("../models/OCRResult");
|
||||
const PublishType = require("../models/PublishType");
|
||||
const puppeteer = require('puppeteer');
|
||||
|
||||
@@ -88,15 +89,29 @@ class CommandorPage {
|
||||
}
|
||||
|
||||
|
||||
async connect_to_browser(){
|
||||
async connect_to_browser(ocrResult) {
|
||||
this.browser = await puppeteer.connect({
|
||||
browserWSEndpoint: "ws://127.0.0.1:" + this.port + "/devtools/browser",
|
||||
headless: false, defaultViewport: null
|
||||
})
|
||||
let pages = await this.browser.pages();
|
||||
this.page = pages[pages.length - 1]
|
||||
let content = await this.page.content()
|
||||
console.log(content)
|
||||
switch (ocrResult) {
|
||||
case OCRResult.SUCCESS:
|
||||
// get url and push to server
|
||||
logWithDevice("will save success appointment", this.device)
|
||||
await this.push_message_to_queue(PublishType.SUCCESS);
|
||||
break;
|
||||
case OCRResult.TO_REFRESH:
|
||||
logWithDevice("will reload page", this.device)
|
||||
await this.page.reload();
|
||||
logWithDevice("will disconnect browser", this.device)
|
||||
await this.browser.disconnect()
|
||||
break;
|
||||
|
||||
}
|
||||
let content = await this.page.content();
|
||||
console.log(content);
|
||||
}
|
||||
|
||||
async loadPage() {
|
||||
@@ -348,18 +363,27 @@ class CommandorPage {
|
||||
try {
|
||||
// remove debug flag
|
||||
// const validElement = await page.$('.btn');
|
||||
console.log("will click on valid button")
|
||||
console.log("will click on valid button")
|
||||
console.log("will click on valid button")
|
||||
this.page.evaluate(() => {
|
||||
console.log("will click on valid button");
|
||||
console.log("will click on valid button");
|
||||
console.log("will click on valid button");
|
||||
await this.page.evaluate(() => {
|
||||
document.getElementsByClassName("btn")[0].click();
|
||||
})
|
||||
// this.browser.disconnect();
|
||||
await delay(2000);
|
||||
let ocrChecker = new OCRChecker(this.device, this.contact)
|
||||
await ocrChecker.get_result()
|
||||
// await delay(2000);
|
||||
// let ocrChecker = new OCRChecker(this.device, this.contact);
|
||||
// let checkResult = await ocrChecker.get_result();
|
||||
// switch (checkResult) {
|
||||
// case OCRResult.SUCCESS:
|
||||
// // reconnect to page and get url
|
||||
// await this.connect_to_browser(OCRResult.SUCCESS);
|
||||
// break;
|
||||
// case OCRResult.BLOCKED:
|
||||
// await this.resetBrowser();
|
||||
// break;
|
||||
// }
|
||||
} catch (e) {
|
||||
log(e)
|
||||
log(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -656,8 +680,6 @@ class CommandorPage {
|
||||
console.log("will reset browser")
|
||||
await this.device.shell("pm clear com.android.chrome")
|
||||
await delay(1000)
|
||||
await this.device.shell("am set-debug-app --persistent com.android.chrome")
|
||||
await delay(1000)
|
||||
await this.device.shell("pm am start -n com.android.chrome/com.google.android.apps.chrome.Main")
|
||||
await delay(1000)
|
||||
this.isTerminated = true
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
const {v4: uuidv4} = require("uuid");
|
||||
const tesseract = require("node-tesseract-ocr");
|
||||
const OCRResult = require("../models/OCRResult");
|
||||
|
||||
function delay(delayInMs) {
|
||||
return new Promise(resolve => {
|
||||
@@ -15,6 +16,13 @@ const config = {
|
||||
psm: 3,
|
||||
}
|
||||
|
||||
const MESSAGE_URL_VALIDATION_FR = "Nous avons envoyé un lien par e-mail."
|
||||
const MESSAGE_URL_VALIDATION_EN = "Please click on the link we sent by email"
|
||||
const CAPTCHA_ERROR_MESSAGE = "Error verifying captcha, please try again"
|
||||
const CAPTCHA_ERROR_MESSAGE_FR = "La vérification du captcha a échoué"
|
||||
const BLOCKED_MSG_EN = "have been blocked"
|
||||
const BLOCKED_MSG_FR = "avez été bloqué"
|
||||
const CHECKING_MSG_FR = "Verifying"
|
||||
|
||||
class OCRChecker {
|
||||
|
||||
@@ -33,6 +41,13 @@ class OCRChecker {
|
||||
let result = await tesseract
|
||||
.recognize(fileName, config)
|
||||
console.log(result)
|
||||
if (result.includes(MESSAGE_URL_VALIDATION_EN) || result.includes(MESSAGE_URL_VALIDATION_FR)) {
|
||||
return OCRResult.SUCCESS
|
||||
} 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)) {
|
||||
return OCRResult.BLOCKED
|
||||
}
|
||||
}
|
||||
|
||||
async take_screen_shot() {
|
||||
@@ -43,4 +58,5 @@ class OCRChecker {
|
||||
// console.log(`stdout: ${stdout1}`);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = OCRChecker
|
||||
|
||||
Reference in New Issue
Block a user