From 0751c8a79f253eae867cba7957cacd904ce07776 Mon Sep 17 00:00:00 2001 From: Lei PAN Date: Mon, 20 Nov 2023 22:27:55 +0100 Subject: [PATCH 01/17] remove unused codes --- src/workers/CommandorPage.js | 63 +++++++++--------------------------- 1 file changed, 16 insertions(+), 47 deletions(-) diff --git a/src/workers/CommandorPage.js b/src/workers/CommandorPage.js index e74e2ed..4068a93 100644 --- a/src/workers/CommandorPage.js +++ b/src/workers/CommandorPage.js @@ -33,8 +33,6 @@ const MESSAGE_URL_VALIDATION_EN = "Please click on the link we sent by email" const REGEX_RDV_URL = "https:\/\/rendezvousparis\.hermes\.com\/client\/register\/[A-Z0-9]+" const DEFAULT_STORE = 'faubourg'; -const searchTexts = ['hermes+rdv+online+paris', 'hermes+rdv+enligne+paris', 'hermes+rdv+en+ligne+paris', 'hermes+rendezvous+en+ligne+paris', 'hermes+appointment+online+paris', 'hermes+appointment+online+paris', 'appointment+hermes+paris+on+line', 'hermes+rendez+vous+online+paris', 'hermes+rendez+vous+paris+en+ligne', 'hermes+rendez+vous+paris+enligne', 'hermes+rendez+vous+paris+online', 'online+appointment+hermes+paris', 'hermes+online+appointment+paris', 'paris+hermes+online+appointment'] - function delay(delayInMs) { return new Promise(resolve => { setTimeout(() => { @@ -92,31 +90,6 @@ class CommandorPage { this.firstStart = true; } - async getActivePage(browser, timeout) { - const start = new Date().getTime(); - while (new Date().getTime() - start < timeout) { - logWithDevice("get pages", this.device) - let pages = await browser.pages(); - try { - pages.forEach((currentPage) => { - if (currentPage.url() === RDV_URL) { - return currentPage; - } else { - try { - currentPage.close() - } catch (e) { - console.log(e) - } - } - }) - } catch (e) { - this.isTerminated = true; - console.log(e) - } - } - throw "Unable to get active page"; - } - async connect_to_browser(ocrResult) { console.log("connect_to_browser() called"); if (this.browser === undefined) { @@ -193,7 +166,7 @@ class CommandorPage { await this.enableDisableAirPlanMode(); // await delay(10 * 1000); await openUrlWithAdb(RDV_URL, this.device) - await delay(5000) + await delay(10000) await this.checkResultWithOcr() // await this.clickOnlineAppointment(); // } else { @@ -748,10 +721,6 @@ class CommandorPage { this.isTerminated = true } - async deleteFromBlackList() { - await this.mongoManager.removeFromBlackList(this.contact) - } - async getErrors() { logWithDevice("getErrors", this.device); await this.checkResultWithOcr(); @@ -1193,21 +1162,21 @@ class CommandorPage { async enableDisableAirPlanMode() { logWithDevice("will enable/disable airplane mode", this.device) - try { - // await this.device.shell("cmd connectivity airplane-mode enable") - await exceutShellCmd(this.device, "cmd connectivity airplane-mode enable") - await delay(1000) - await exceutShellCmd(this.device, "cmd connectivity airplane-mode disable") - // await this.device.shell("cmd connectivity airplane-mode disable") - await delay(2000) - } catch (e) { - try { - await this.device.shell("cmd connectivity airplane-mode disable") - } catch (e) { - console.log(e) - } - console.log(e) - } + // try { + // // await this.device.shell("cmd connectivity airplane-mode enable") + // await exceutShellCmd(this.device, "cmd connectivity airplane-mode enable") + // await delay(1000) + // await exceutShellCmd(this.device, "cmd connectivity airplane-mode disable") + // // await this.device.shell("cmd connectivity airplane-mode disable") + // await delay(2000) + // } catch (e) { + // try { + // await this.device.shell("cmd connectivity airplane-mode disable") + // } catch (e) { + // console.log(e) + // } + // console.log(e) + // } } async tapGoogleDisconnectBtn() { From f3f82b2125683b823bb1acc57822e2d6a095b531 Mon Sep 17 00:00:00 2001 From: Lei PAN Date: Wed, 22 Nov 2023 12:28:22 +0100 Subject: [PATCH 02/17] support more devices for proxy --- src/workers/CommandorPage.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/workers/CommandorPage.js b/src/workers/CommandorPage.js index 4068a93..2452a04 100644 --- a/src/workers/CommandorPage.js +++ b/src/workers/CommandorPage.js @@ -671,10 +671,10 @@ class CommandorPage { async slidingCaptcha(onResult) { logWithDevice("slidingCaptcha", this.device); - if (this.device.model() === "MI 5s" || this.device.model() === "ASUS_X00QD") { + if (this.device.model() === "MI 5s" || this.device.model() === "ASUS_X00QD" || this.device.model() === "ASUS_Z012D") { let cmd = `adb -s ${this.device.serial()} shell input touchscreen swipe 900 495 900 195` await exec(cmd); - await delay(1000); + await delay(5000); } let slidingCaptchaSolver = new SlidingCaptchaSolver(this.device); await slidingCaptchaSolver.solve(this.page, async (isSuccessful) => { @@ -933,10 +933,10 @@ class CommandorPage { await this.checkResultWithOcr(); break; case OCRResult.BRAVE_PRIVACY: - if (this.device.model() === "MI 5s") { + if (this.device.model() === "MI 5s" || this.device.model() === "SM-G965U1" || this.device.model() === "ASUS_Z012D") { await this.tapForDevice(this.device, 530, 970) } else if (this.device.model() === "ONEPLUS A6000") { - await this.device.shell("input tap " + 530 + " " + 1064) + await this.tapForDevice(this.device, 530, 1064) } else if (this.device.model() === "moto g51 5G") { await this.tapForDevice(this.device, 500, 1080) } else if (this.device.model() === "M2006C3LG" || this.device.model() === "220233L2G") { @@ -955,7 +955,7 @@ class CommandorPage { await this.checkResultWithOcr(); break; case OCRResult.BRAVE_PRIVACY_PUB: - if (this.device.model() === "MI 5s") { + if (this.device.model() === "MI 5s" || this.device.model() === "ASUS_Z012D") { await this.tapForDevice(this.device, 60, 1400) } else await this.tapForDevice(this.device, 455, 1920) @@ -1070,12 +1070,14 @@ class CommandorPage { let model = this.device.model() if (model === "CPH2219") { await this.device.shell("input tap " + 558 + " " + 1160) - } else if (model === "MI 5s") { + } else if (model === "MI 5s" || model === "ASUS_Z012D") { + await this.tapForDevice(this.device, 530, 1000) + } else if (model === "SM-G965U1") { await this.tapForDevice(this.device, 530, 1000) } else if (model === "M2006C3LG" || model === "220233L2G") { await this.tapForDevice(this.device, 360, 777) } else if (model === "ONEPLUS A6000") { - await this.device.shell("input tap " + 530 + " " + 1106) + await this.tapForDevice(this.device, 530, 1045) } else { logWithDevice("handleBraveSkipBtn", this.device) await this.tapForDevice(this.device, 470, 1160) From 9be644aadf01c6a97d409e3cd471bb14185dd456 Mon Sep 17 00:00:00 2001 From: Lei PAN Date: Thu, 23 Nov 2023 17:47:01 +0100 Subject: [PATCH 03/17] support more devices --- src/workers/CommandorPage.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/workers/CommandorPage.js b/src/workers/CommandorPage.js index 2452a04..782b090 100644 --- a/src/workers/CommandorPage.js +++ b/src/workers/CommandorPage.js @@ -671,7 +671,7 @@ class CommandorPage { async slidingCaptcha(onResult) { logWithDevice("slidingCaptcha", this.device); - if (this.device.model() === "MI 5s" || this.device.model() === "ASUS_X00QD" || this.device.model() === "ASUS_Z012D") { + if (this.device.model() === "MI 5s" || this.device.model() === "ASUS_X00QD" || this.device.model() === "ASUS_Z012D" || this.device.model() === "HUAWEI NXT-TL00") { let cmd = `adb -s ${this.device.serial()} shell input touchscreen swipe 900 495 900 195` await exec(cmd); await delay(5000); @@ -933,8 +933,11 @@ class CommandorPage { await this.checkResultWithOcr(); break; case OCRResult.BRAVE_PRIVACY: - if (this.device.model() === "MI 5s" || this.device.model() === "SM-G965U1" || this.device.model() === "ASUS_Z012D") { + let model = this.device.model() + if (model === "MI 5s" || this.device.model() === "SM-G965U1" || this.device.model() === "ASUS_Z012D") { await this.tapForDevice(this.device, 530, 970) + } else if (model === "HUAWEI NXT-TL00") { + await this.tapForDevice(this.device, 530, 950) } else if (this.device.model() === "ONEPLUS A6000") { await this.tapForDevice(this.device, 530, 1064) } else if (this.device.model() === "moto g51 5G") { @@ -957,6 +960,8 @@ class CommandorPage { case OCRResult.BRAVE_PRIVACY_PUB: if (this.device.model() === "MI 5s" || this.device.model() === "ASUS_Z012D") { await this.tapForDevice(this.device, 60, 1400) + } else if (this.device.model() === "HUAWEI NXT-TL00") { + await this.tapForDevice(this.device, 530, 950) } else await this.tapForDevice(this.device, 455, 1920) await delay(2000); @@ -1074,6 +1079,8 @@ class CommandorPage { await this.tapForDevice(this.device, 530, 1000) } else if (model === "SM-G965U1") { await this.tapForDevice(this.device, 530, 1000) + } else if (model === "HUAWEI NXT-TL00") { + await this.tapForDevice(this.device, 530, 950) } else if (model === "M2006C3LG" || model === "220233L2G") { await this.tapForDevice(this.device, 360, 777) } else if (model === "ONEPLUS A6000") { From 939b98e3a3b3533d3141de7318584ca949c64ab8 Mon Sep 17 00:00:00 2001 From: Lei PAN Date: Wed, 29 Nov 2023 17:14:59 +0100 Subject: [PATCH 04/17] handle ssl error --- package.json | 2 +- src/models/OCRResult.js | 2 ++ src/workers/CommandorPage.js | 39 ++++++++++++++++++++++-------------- src/workers/OCRChecker.js | 14 +++++++++++-- 4 files changed, 39 insertions(+), 18 deletions(-) diff --git a/package.json b/package.json index dfdd90a..0efab76 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "node-wget": "^0.4.3", "node-xlsx": "^0.21.0", "playwright": "^1.39.0", - "puppeteer": "^15.5.0", + "puppeteer": "^15.2.0", "read-ini-file": "^3.0.1", "uuid": "^9.0.0", "winston": "^3.8.2", diff --git a/src/models/OCRResult.js b/src/models/OCRResult.js index b2180e2..6586681 100644 --- a/src/models/OCRResult.js +++ b/src/models/OCRResult.js @@ -3,6 +3,8 @@ const OCRResult = { TO_REFRESH: Symbol("TO_REFRESH"), BLOCKED: Symbol("BLOCKED"), SLIDING_CAPTCHA: Symbol("SLIDING_CAPTCHA"), + SSL_CERT_ERROR: Symbol("SSL_CERT_ERROR"), + SLIDING_CAPTCHA_LOADING: Symbol("SLIDING_CAPTCHA_LOADING"), SLIDING_CAPTCHA_REFRESH: Symbol("SLIDING_CAPTCHA_REFRESH"), FILL_FIELD: Symbol("FILL_FIELD"), NEED_TO_CLICK_LATE_BTN: Symbol("NEED_TO_CLICK_LATE_BTN"), diff --git a/src/workers/CommandorPage.js b/src/workers/CommandorPage.js index 782b090..3966fa6 100644 --- a/src/workers/CommandorPage.js +++ b/src/workers/CommandorPage.js @@ -178,7 +178,8 @@ class CommandorPage { if (this.isTerminated) { log(this.device.model() + ":request terminated, send cancel()"); try { - await this.page.close() + if (this.page !== undefined) + await this.page.close() } catch (e) { console.log(e) } @@ -726,16 +727,6 @@ class CommandorPage { await this.checkResultWithOcr(); if (this.page.url() === BLANK_URL) { this.isTerminated = true; - } else { - try { - // let errorItem = this.page.locator("div.alert"); - // if (errorItem) { - // let errorContent = await errorItem.innerHTML(); - // await this.handleError(errorContent); - // } - } catch (e) { - log(e); - } } } @@ -824,6 +815,12 @@ class CommandorPage { await delay(10 * 1000) } switch (checkResult) { + case OCRResult.SLIDING_CAPTCHA_LOADING: + this.isTerminated = true; + break; + case OCRResult.SSL_CERT_ERROR: + await this.resetBrowser() + break; case OCRResult.TERMINAED: this.isTerminated = true; break; @@ -842,17 +839,29 @@ class CommandorPage { logWithDevice("get pages", this.device) let pages = await this.browser.pages(); try { - pages.forEach((currentPage) => { + for (const currentPage of pages) { if (currentPage.url() === RDV_URL) { - this.page = currentPage; + logWithDevice("get content", this.device) + let pageContent = await currentPage.content() + logWithDevice("content:" + pageContent, this.device) + if (!pageContent.includes("geo.captcha-delivery.com")) { + this.page = currentPage; + break + } else { + try { + await currentPage.close() + } catch (e) { + console.log(e) + } + } } else { try { - currentPage.close() + await currentPage.close() } catch (e) { console.log(e) } } - }) + } } catch (e) { this.isTerminated = true; console.log(e) diff --git a/src/workers/OCRChecker.js b/src/workers/OCRChecker.js index aaa9374..12019e0 100644 --- a/src/workers/OCRChecker.js +++ b/src/workers/OCRChecker.js @@ -17,6 +17,7 @@ const NO_INTERNET_FR_2 = "Aucun accès à Internet" const BRAVE_VPN_SKIP = "Pare-feu + VPN Brave" const MESSAGE_URL_VALIDATION_FR = "envoyé un lien par e-mail." const MESSAGE_URL_VALIDATION_FR_2 = "un lien par e-mail" +const SSL_CERT_ERROR = " Votre connexion n'est pas privée" const MESSAGE_URL_VALIDATION_EN = "Please click on the link we sent by email" const CHOOSE_POSITION_GOOGLE_FR = " Choisir la position pour les résultats de recherche" const CAPTCHA_ERROR_MESSAGE = "Error verifying captcha, please try again" @@ -31,11 +32,14 @@ const ERR_CACHE_MISS = "ERR_CACHE_MISS" const ERR_CACHE_MISS_2 = "ERR_CACHE-MISS" const ERR_CACHE_MISS_3 = "appuyer sur le bouton d'actualisation" const ERR_CACHE_MISS_4 = "renvoyer les données" +const ERR_EMPTY_RESPONSE = "ERR_EMPTY_RESPONSE" const SLIDING_CAPTCHA_FR = "Pourquoi cette vérification" +const SLIDING_CAPTCHA_LOADING_FR = "Chargement." const SLIDING_CAPTCHA_FR_2 = "Glissez vers la droite pour" const SLIDING_CAPTCHA_FR_3 = "la droite pour completer le puzzle" const SLIDING_CAPTCHA_FR_4 = " s'assure qu'on s'adresse bien" const SLIDING_CAPTCHA_FR_5 = "On s'assure que c'est" +const SLIDING_CAPTCHA_FR_6 = "s'assure que cest bien vous" const MESSAGE_FILL_FIELD_FR = "Demande de rendez-vous pour" const MESSAGE_FILL_FIELD_FR_2 = "des champs de données doivent étre complétés" const MESSAGE_FILL_FIELD_FR_3 = "Sans préféré" @@ -100,6 +104,9 @@ class OCRChecker { } else if (result.includes(BRAVE_VPN_SKIP)) { await this.deleteFile(fileName) return OCRResult.BRAVE_VPN_SKIP + } else if (result.includes(SSL_CERT_ERROR)) { + await this.deleteFile(fileName) + return OCRResult.SSL_CERT_ERROR } 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) return OCRResult.FILL_FIELD @@ -108,7 +115,7 @@ class OCRChecker { } else if (result.includes(BLOCKED_MSG_EN) || result.includes(BLOCKED_MSG_FR) || result.includes(BLOCKED_MSG_FR_2) || result.includes(BLOCKED_MSG_FR_3)) { await this.deleteFile(fileName) 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)) { + } 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) || result.includes("ERR_EMPTY_RESPONSE")) { return OCRResult.TO_REFRESH } else if (result.includes(CHECKING_MSG_FR) || result.includes(CHECKING_MSG_FR_2)) { await this.deleteFile(fileName) @@ -119,8 +126,11 @@ class OCRChecker { } 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) return OCRResult.BRAVE_PRIVACY_PUB - } 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) || result.includes(SLIDING_CAPTCHA_FR_5)) { + } 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) || result.includes(SLIDING_CAPTCHA_FR_5) || result.includes(SLIDING_CAPTCHA_FR_6)) { await this.deleteFile(fileName) + if (result.includes(SLIDING_CAPTCHA_LOADING_FR)) { + return OCRResult.SLIDING_CAPTCHA_LOADING + } // await this.deleteFile(screenShot) // if (result.includes("rac")) // return OCRResult.SLIDING_CAPTCHA_REFRESH From 8ec0443a01214fa616bf755206f0c189fc533f15 Mon Sep 17 00:00:00 2001 From: Lei PAN Date: Thu, 30 Nov 2023 16:19:48 +0100 Subject: [PATCH 05/17] add timeout for pages() --- src/workers/CommandorPage.js | 100 +++++++++++++++------------- src/workers/OCRChecker.js | 1 + src/workers/SlidingCaptchaSolver.js | 7 +- 3 files changed, 58 insertions(+), 50 deletions(-) diff --git a/src/workers/CommandorPage.js b/src/workers/CommandorPage.js index 3966fa6..aca8cf1 100644 --- a/src/workers/CommandorPage.js +++ b/src/workers/CommandorPage.js @@ -32,6 +32,8 @@ 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 REGEX_RDV_URL = "https:\/\/rendezvousparis\.hermes\.com\/client\/register\/[A-Z0-9]+" const DEFAULT_STORE = 'faubourg'; +const timeout = (prom, time) => + Promise.race([prom, new Promise((_r, rej) => setTimeout(rej, time))]); function delay(delayInMs) { return new Promise(resolve => { @@ -178,8 +180,9 @@ class CommandorPage { if (this.isTerminated) { log(this.device.model() + ":request terminated, send cancel()"); try { - if (this.page !== undefined) + if (this.page !== undefined) { await this.page.close() + } } catch (e) { console.log(e) } @@ -786,7 +789,6 @@ class CommandorPage { } } - async checkResultWithOcr() { logWithDevice("checkResultWithOcr() called.", this.device) if (this.device.model() === "M2006C3LG") @@ -806,7 +808,9 @@ class CommandorPage { await this.slidingCaptcha(async (isSuccessful) => { logWithDevice("SLIDING_CAPTCHA result is " + isSuccessful, this.device) if (isSuccessful) { + await delay(5 * 1000) checkResult = await this.ocrChecker.get_result(); + console.log(checkResult); } else { checkResult = OCRResult.TERMINAED this.isTerminated = true @@ -836,41 +840,61 @@ class CommandorPage { browserWSEndpoint: "ws://127.0.0.1:" + this.port + "/devtools/browser", headless: false, defaultViewport: null }) - logWithDevice("get pages", this.device) - let pages = await this.browser.pages(); + try { - for (const currentPage of pages) { + logWithDevice("get pages", this.device) + // let pages = await this.browser.pages(); + let pages = await timeout(this.browser.pages(), 5 * 1000); + pages.forEach((currentPage) => { if (currentPage.url() === RDV_URL) { - logWithDevice("get content", this.device) - let pageContent = await currentPage.content() - logWithDevice("content:" + pageContent, this.device) - if (!pageContent.includes("geo.captcha-delivery.com")) { - this.page = currentPage; - break - } else { - try { - await currentPage.close() - } catch (e) { - console.log(e) - } - } + this.page = currentPage; } else { try { - await currentPage.close() + currentPage.close() } catch (e) { console.log(e) } } - } - } catch (e) { - this.isTerminated = true; - console.log(e) - } - logWithDevice("this.page.bringToFront();", this.device) + }) + logWithDevice("this.page.bringToFront();", this.device) + + await this.page.bringToFront(); + await this.fillFields(this.page) + await delay(2 * 1000); + } catch (e) { + console.log(e) + await this.resetBrowser() + // this.isTerminated = true; + } + // try { + // for (const currentPage of pages) { + // if (currentPage.url() === RDV_URL) { + // logWithDevice("get content", this.device) + // let pageContent = await currentPage.content() + // logWithDevice("content:" + pageContent, this.device) + // if (!pageContent.includes("geo.captcha-delivery.com")) { + // this.page = currentPage; + // break + // } else { + // try { + // await currentPage.close() + // } catch (e) { + // console.log(e) + // } + // } + // } else { + // try { + // await currentPage.close() + // } catch (e) { + // console.log(e) + // } + // } + // } + // } catch (e) { + // this.isTerminated = true; + // console.log(e) + // } - await this.page.bringToFront(); - await this.fillFields(this.page) - await delay(2 * 1000); } catch (e) { console.log(e) this.isTerminated = true @@ -879,27 +903,7 @@ class CommandorPage { logWithDevice("this.browser.isConnected() is " + this.browser.isConnected(), this.device) try { if (this.browser.isConnected()) { - // logWithDevice("get pages", this.device) - // let pages = await this.browser.pages(); logWithDevice("will use old page", this.device) - // try { - // pages.forEach((currentPage) => { - // if (currentPage.url() === RDV_URL) { - // this.page = currentPage; - // } else { - // // try { - // // if (!currentPage.isClosed()) { - // // currentPage.close() - // // } - // // } catch (e) { - // // console.log(e) - // // } - // } - // }) - // } catch (e) { - // this.isTerminated = true - // console.log(e) - // } logWithDevice("this.page.bringToFront();", this.device) await this.page.bringToFront(); // this.page = pages; diff --git a/src/workers/OCRChecker.js b/src/workers/OCRChecker.js index 12019e0..df5b847 100644 --- a/src/workers/OCRChecker.js +++ b/src/workers/OCRChecker.js @@ -194,6 +194,7 @@ class OCRChecker { async take_screen_shot() { let name = this.get_file_name() console.log("will take screenshot for " + this.device.model() + ":" + this.device.serial()) + console.log("name is " + name) let stdout1 = await exec("adb -s " + this.device.serial() + " exec-out screencap -p > " + name) await delay(5000); console.log(`stdout: ${stdout1}`); diff --git a/src/workers/SlidingCaptchaSolver.js b/src/workers/SlidingCaptchaSolver.js index c5798d4..66dc51f 100644 --- a/src/workers/SlidingCaptchaSolver.js +++ b/src/workers/SlidingCaptchaSolver.js @@ -34,17 +34,18 @@ class SlidingCaptchaSolver { let stdout1 = await exec("adb -s " + device.serial() + " exec-out screencap -p > " + name) // await delay(5000); console.log(`stdout: ${stdout1}`); - await delay(1000); + await delay(5000); } async sliding_captcha(device, onResult) { // take screenshot - console.log("take screenshot") + console.log("sliding_captcha.take screenshot") let blockedFileName = uuidv4(); let blockedImageFileName = "blocked_" + blockedFileName + ".png" await this.take_screen_shot(blockedImageFileName, device) //get resolution of screen + console.log("sliding_captcha.sendRequest:" + blockedImageFileName) await this.sendRequest(blockedImageFileName, async (detectedPositionList) => { console.log("detectedPosition: " + device.model() + ":" + detectedPositionList); if (detectedPositionList.length >= 2) { @@ -81,6 +82,7 @@ class SlidingCaptchaSolver { }) } + async deleteFile(filename) { try { fs.unlinkSync(filename) @@ -89,6 +91,7 @@ class SlidingCaptchaSolver { return OCRResult.TERMINAED } } + async sendRequest(fileName, callback) { const fileStream = fs.createReadStream(fileName); let response = await axios.post(DEEPLEARNING_CAPTCHA_HOST, fileStream, { From a52a65fd7280b1a1dbf0b73f6925bc7cb8b552a9 Mon Sep 17 00:00:00 2001 From: Lei PAN Date: Fri, 1 Dec 2023 10:06:29 +0100 Subject: [PATCH 06/17] support moto g51 --- src/workers/CommandorPage.js | 2 ++ src/workers/OCRChecker.js | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/workers/CommandorPage.js b/src/workers/CommandorPage.js index aca8cf1..6b7473f 100644 --- a/src/workers/CommandorPage.js +++ b/src/workers/CommandorPage.js @@ -1120,6 +1120,8 @@ class CommandorPage { this.device.shell("input tap " + 925 + " " + 1325) } else if (this.device.model() === "22041219PG") { this.device.shell("input tap " + 925 + " " + 1430) + } else if (this.device.model() === "moto g51 5G") { + await this.tapForDevice(this.device, 950, 1434) } else this.device.shell("input tap " + 933 + " " + 1538) await delay(2000); diff --git a/src/workers/OCRChecker.js b/src/workers/OCRChecker.js index df5b847..d9d6da6 100644 --- a/src/workers/OCRChecker.js +++ b/src/workers/OCRChecker.js @@ -33,6 +33,7 @@ const ERR_CACHE_MISS_2 = "ERR_CACHE-MISS" const ERR_CACHE_MISS_3 = "appuyer sur le bouton d'actualisation" const ERR_CACHE_MISS_4 = "renvoyer les données" const ERR_EMPTY_RESPONSE = "ERR_EMPTY_RESPONSE" +const ERR_SSL_PROTOCOL = "SSL_PROTOCOL_ERROR" const SLIDING_CAPTCHA_FR = "Pourquoi cette vérification" const SLIDING_CAPTCHA_LOADING_FR = "Chargement." const SLIDING_CAPTCHA_FR_2 = "Glissez vers la droite pour" @@ -115,7 +116,9 @@ class OCRChecker { } else if (result.includes(BLOCKED_MSG_EN) || result.includes(BLOCKED_MSG_FR) || result.includes(BLOCKED_MSG_FR_2) || result.includes(BLOCKED_MSG_FR_3)) { await this.deleteFile(fileName) 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) || result.includes("ERR_EMPTY_RESPONSE")) { + } 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) || result.includes(ERR_EMPTY_RESPONSE) || result.includes(ERR_SSL_PROTOCOL)) { + await this.deleteFile(fileName) return OCRResult.TO_REFRESH } else if (result.includes(CHECKING_MSG_FR) || result.includes(CHECKING_MSG_FR_2)) { await this.deleteFile(fileName) From e7a02a5c254bb85bcd627eace32ac1844df01284 Mon Sep 17 00:00:00 2001 From: Lei PAN Date: Tue, 5 Dec 2023 14:08:02 +0100 Subject: [PATCH 07/17] support moto g51 --- src/workers/CommandorPage.js | 2 +- src/workers/OCRChecker.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/workers/CommandorPage.js b/src/workers/CommandorPage.js index 6b7473f..94171f7 100644 --- a/src/workers/CommandorPage.js +++ b/src/workers/CommandorPage.js @@ -168,7 +168,7 @@ class CommandorPage { await this.enableDisableAirPlanMode(); // await delay(10 * 1000); await openUrlWithAdb(RDV_URL, this.device) - await delay(10000) + await delay(15000) await this.checkResultWithOcr() // await this.clickOnlineAppointment(); // } else { diff --git a/src/workers/OCRChecker.js b/src/workers/OCRChecker.js index d9d6da6..67f2c79 100644 --- a/src/workers/OCRChecker.js +++ b/src/workers/OCRChecker.js @@ -117,7 +117,7 @@ class OCRChecker { await this.deleteFile(fileName) 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) || result.includes(ERR_EMPTY_RESPONSE) || result.includes(ERR_SSL_PROTOCOL)) { + || result.includes(ERR_CACHE_MISS_4) || result.includes(ERR_EMPTY_RESPONSE) ) { //|| result.includes(ERR_SSL_PROTOCOL) await this.deleteFile(fileName) return OCRResult.TO_REFRESH } else if (result.includes(CHECKING_MSG_FR) || result.includes(CHECKING_MSG_FR_2)) { From 0c18ae491cfe45d3c3ddf6f4e449e974c631e0cf Mon Sep 17 00:00:00 2001 From: Lei PAN Date: Wed, 6 Dec 2023 09:33:57 +0100 Subject: [PATCH 08/17] add timeout for pages() --- src/workers/CommandorPage.js | 20 +++++++++----------- src/workers/OCRChecker.js | 3 ++- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/workers/CommandorPage.js b/src/workers/CommandorPage.js index 94171f7..4f23b43 100644 --- a/src/workers/CommandorPage.js +++ b/src/workers/CommandorPage.js @@ -721,7 +721,6 @@ class CommandorPage { await this.mongoManager.saveReserveToDb(reserve.to_mongo_dict()) await this.page.close(); // await this.deleteFromBlackList() - // await this.resetBrowser() this.isTerminated = true } @@ -751,7 +750,7 @@ class CommandorPage { logWithDevice("resetBrowser", this.device); this.isFillingFields = false; this.cguChecked = false; - this.isNameInput = false; + this.isNameInputing = false; this.isEmailFilled = false; this.isCountryChoosen = false; this.isPhoneInput = false; @@ -805,15 +804,19 @@ class CommandorPage { checkResult = await this.ocrChecker.get_result(); } while (checkResult === OCRResult.SLIDING_CAPTCHA) { + logWithDevice("will call this.slidingCaptcha()", this.device) await this.slidingCaptcha(async (isSuccessful) => { logWithDevice("SLIDING_CAPTCHA result is " + isSuccessful, this.device) + console.log(checkResult); if (isSuccessful) { await delay(5 * 1000) - checkResult = await this.ocrChecker.get_result(); - console.log(checkResult); + // checkResult = await this.ocrChecker.get_result(); + await this.checkResultWithOcr() } else { - checkResult = OCRResult.TERMINAED - this.isTerminated = true + if (checkResult === OCRResult.SLIDING_CAPTCHA) { + checkResult = OCRResult.TERMINAED + this.isTerminated = true + } } }) await delay(10 * 1000) @@ -933,12 +936,7 @@ class CommandorPage { break; case OCRResult.RECAPTCHA_ERROR: - // if (!this.isFillingFields) this.isTerminated = true; - // else { - // await this.checkResultWithOcr(); - // } - // await this.connect_to_browser(OCRResult.RECAPTCHA_ERROR) break; case OCRResult.BRAVE_SKIP: diff --git a/src/workers/OCRChecker.js b/src/workers/OCRChecker.js index 67f2c79..a699a5a 100644 --- a/src/workers/OCRChecker.js +++ b/src/workers/OCRChecker.js @@ -46,6 +46,7 @@ const MESSAGE_FILL_FIELD_FR_2 = "des champs de données doivent étre complété const MESSAGE_FILL_FIELD_FR_3 = "Sans préféré" const MESSAGE_FILL_FIELD_FR_4 = "Magasin préféré" const MESSAGE_FILL_FIELD_FR_5 = "email vous sera envoyé pour vous" +const MESSAGE_FILL_FIELD_FR_6 = "Prénom* Téléphone*" const WELCOME_MESSAGE_FR = "Bienvenue dans Chrome" const PAGE_OPTIMIZATION_CHROME_FR = "Vous pouvez changer d'avis a tout moment dans" const PAGE_OPTIMIZATION_CHROME_FR_6 = "Vous pouvez changer davis a tout moment" @@ -108,7 +109,7 @@ class OCRChecker { } else if (result.includes(SSL_CERT_ERROR)) { await this.deleteFile(fileName) return OCRResult.SSL_CERT_ERROR - } 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)) { + } 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)||result.includes(MESSAGE_FILL_FIELD_FR_6)) { await this.deleteFile(fileName) return OCRResult.FILL_FIELD } else if (result.includes(CAPTCHA_ERROR_MESSAGE) || result.includes(CAPTCHA_ERROR_MESSAGE_FR)) { From 95c62a614c78923de2cfd96830961d34fdf78c94 Mon Sep 17 00:00:00 2001 From: Lei PAN Date: Fri, 8 Dec 2023 11:38:19 +0100 Subject: [PATCH 09/17] support for oneplus N20 --- src/models/ReserveResultPojo.js | 6 ++++- src/workers/CommandorPage.js | 42 +++++++++++++++++---------------- 2 files changed, 27 insertions(+), 21 deletions(-) diff --git a/src/models/ReserveResultPojo.js b/src/models/ReserveResultPojo.js index 855a81b..b3a2f58 100644 --- a/src/models/ReserveResultPojo.js +++ b/src/models/ReserveResultPojo.js @@ -1,4 +1,6 @@ const PublishType = require("./PublishType"); +const {hostname} = require("os"); +const hostName = hostname(); class ReserveResultPojo { @@ -13,6 +15,7 @@ class ReserveResultPojo { this.email = mail; this.type = type; this.source_from = "" + this.hostName = hostName this.created_at = new Date().toLocaleString() } @@ -27,7 +30,8 @@ class ReserveResultPojo { url: this.url, store_type: this.storeType, source_from: this.source_from, - created_at: this.created_at + created_at: this.created_at, + hostName: this.hostName } } diff --git a/src/workers/CommandorPage.js b/src/workers/CommandorPage.js index 4f23b43..b8739f7 100644 --- a/src/workers/CommandorPage.js +++ b/src/workers/CommandorPage.js @@ -168,12 +168,8 @@ class CommandorPage { await this.enableDisableAirPlanMode(); // await delay(10 * 1000); await openUrlWithAdb(RDV_URL, this.device) - await delay(15000) + await delay(10 * 1000) await this.checkResultWithOcr() - // await this.clickOnlineAppointment(); - // } else { - // this.isTerminated = true; - // } let cancel const intervalTask = setInterval(async () => { @@ -953,6 +949,8 @@ class CommandorPage { await this.tapForDevice(this.device, 530, 1064) } else if (this.device.model() === "moto g51 5G") { await this.tapForDevice(this.device, 500, 1080) + } else if (this.device.model() === "CPH2469") { + await this.tapForDevice(this.device, 360, 820) } else if (this.device.model() === "M2006C3LG" || this.device.model() === "220233L2G") { await this.tapForDevice(this.device, 350, 777) } else if (this.device.model() === "KB2003" || this.device.model() === "DE2117") { @@ -984,6 +982,8 @@ class CommandorPage { await this.tapForDevice(this.device, 540, 1611) } else if (this.device.model() === "22041219PG") { await this.tapForDevice(this.device, 530, 1600) + } else if (this.device.model() === "CPH2469") { + await this.tapForDevice(this.device, 322, 1146) } else await this.tapForDevice(this.device, 500, 1680) // await this.device.shell("input tap " + 500 + " " + 1680) @@ -1096,6 +1096,8 @@ class CommandorPage { await this.tapForDevice(this.device, 360, 777) } else if (model === "ONEPLUS A6000") { await this.tapForDevice(this.device, 530, 1045) + } else if (model === "CPH2469") { + await this.tapForDevice(this.device, 360, 820) } else { logWithDevice("handleBraveSkipBtn", this.device) await this.tapForDevice(this.device, 470, 1160) @@ -1184,21 +1186,21 @@ class CommandorPage { async enableDisableAirPlanMode() { logWithDevice("will enable/disable airplane mode", this.device) - // try { - // // await this.device.shell("cmd connectivity airplane-mode enable") - // await exceutShellCmd(this.device, "cmd connectivity airplane-mode enable") - // await delay(1000) - // await exceutShellCmd(this.device, "cmd connectivity airplane-mode disable") - // // await this.device.shell("cmd connectivity airplane-mode disable") - // await delay(2000) - // } catch (e) { - // try { - // await this.device.shell("cmd connectivity airplane-mode disable") - // } catch (e) { - // console.log(e) - // } - // console.log(e) - // } + try { + // await this.device.shell("cmd connectivity airplane-mode enable") + await exceutShellCmd(this.device, "cmd connectivity airplane-mode enable") + await delay(1000) + await exceutShellCmd(this.device, "cmd connectivity airplane-mode disable") + // await this.device.shell("cmd connectivity airplane-mode disable") + await delay(2000) + } catch (e) { + try { + await this.device.shell("cmd connectivity airplane-mode disable") + } catch (e) { + console.log(e) + } + console.log(e) + } } async tapGoogleDisconnectBtn() { From b6dc3824cfff8441f1988b126f92981acd60c5a1 Mon Sep 17 00:00:00 2001 From: Lei PAN Date: Sat, 9 Dec 2023 09:44:46 +0100 Subject: [PATCH 10/17] stop after 19h --- src/appointment.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/appointment.js b/src/appointment.js index 7069ba6..be5f55f 100644 --- a/src/appointment.js +++ b/src/appointment.js @@ -15,7 +15,7 @@ let excludeMode = DeviceExcludeMode.SIX let three_to_excludes = ["bec11752", "4e8ca027", "hi7ljr5xduyt9pfi", "EPHUT20825001518"] let four_to_excludes = ["bec11752", "4e8ca027", "hi7ljr5xduyt9pfi", "e30eb015", "EPHUT20825001518"] let seven_to_excludes = ["4e8ca027", "hi7ljr5xduyt9pfi", "e30eb015", "EPHUT20825001518", "bec11752", "fy65eqs4wkvcpf9h", "fuljaueqguugf6pn", "EPHUT20825001518"] -let six_to_excludes = ["4e8ca027", "hi7ljr5xduyt9pfi", "e30eb015", "EPHUT20825001518", "bec11752", "fy65eqs4wkvcpf9h", "07fbd156", "NFD669QK8XNFSCNN", "6X494TTWQGFALB79","71a0371d"] +let six_to_excludes = ["4e8ca027", "hi7ljr5xduyt9pfi", "e30eb015", "EPHUT20825001518", "bec11752", "fy65eqs4wkvcpf9h", "07fbd156", "NFD669QK8XNFSCNN", "6X494TTWQGFALB79", "71a0371d", "YP6HVKLFE67T598L"] let nine_to_excludes = ["bec11752", "4e8ca027", "hi7ljr5xduyt9pfi", "e30eb015", "47e7e36b", "p7d6nbw8cu7duous", "njzxojhim7gedyvw", "fmiz5pa6rsx4u4ts", "fy65eqs4wkvcpf9h", "fuljaueqguugf6pn", "EPHUT20825001518", "W8GMFELRHIKZS84T"] let for_scrpay = ["07fbd156", "47e7e36b", "4f55c3d4", "5ac879a2", "69db59f0", "71a0371d", "774687ff", "7b71fb20", "8f76f9e7", "99cyfiaebqcy6poj", "EPHUT20825001518", "J4AXB761H2322WJ", "W8GMFELRHIKZS84T", "ai9xv8hy599hvkee", "b41c1b72", "bec11752", "becb6e99", "c3ba032e", "d54e946", "e30eb015", "fmiz5pa6rsx4u4ts", "fuljaueqguugf6pn", "fy65eqs4wkvcpf9h", "hi7ljr5xduyt9pfi", "njzxojhim7gedyvw", "p7d6nbw8cu7duous"] attributedPorts = [] @@ -125,6 +125,12 @@ async function startBook(contactPojo, device, selectedStore, audioAnalyse, alert console.log(`model: ${device.model()}`); console.log(`serial: ${device.serial()}`); let alreadyBooked = await mongoManager.getAllSuccessfulItemsForDay(collectionName); + const d = new Date(); + let hour = d.getHours(); + if (hour >= 19) { + console.log("do not continue after 19h") + return + } if (await needToBook(contactPojo, mongoManager, alreadyBooked)) { let commandor = new CommandorPage(contactPojo, device, mongoManager, selectedStore, audioAnalyse, alertBeep, port); //read contacts form excel From 549fc6e5eb6e38857738db1c0d752a185788c72d Mon Sep 17 00:00:00 2001 From: Lei PAN Date: Wed, 13 Dec 2023 10:19:41 +0100 Subject: [PATCH 11/17] try catch while closing page --- src/workers/CommandorPage.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/workers/CommandorPage.js b/src/workers/CommandorPage.js index b8739f7..46d4ce1 100644 --- a/src/workers/CommandorPage.js +++ b/src/workers/CommandorPage.js @@ -715,7 +715,11 @@ class CommandorPage { let reserve = ReserveResultPojo.create_from_contact(this.contact, id, url, this.choosedStore, publishType); reserve.source_from = this.device.model(); await this.mongoManager.saveReserveToDb(reserve.to_mongo_dict()) - await this.page.close(); + try { + await this.page.close(); + } catch (e) { + console.log(e) + } // await this.deleteFromBlackList() this.isTerminated = true } From 50785b58c74a929981ee9d68c3560c378c91a0a1 Mon Sep 17 00:00:00 2001 From: Lei PAN Date: Thu, 14 Dec 2023 23:20:24 +0100 Subject: [PATCH 12/17] new valid setences --- src/workers/CommandorPage.js | 8 +++++++- src/workers/OCRChecker.js | 8 ++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/workers/CommandorPage.js b/src/workers/CommandorPage.js index b8739f7..7117050 100644 --- a/src/workers/CommandorPage.js +++ b/src/workers/CommandorPage.js @@ -715,7 +715,13 @@ class CommandorPage { let reserve = ReserveResultPojo.create_from_contact(this.contact, id, url, this.choosedStore, publishType); reserve.source_from = this.device.model(); await this.mongoManager.saveReserveToDb(reserve.to_mongo_dict()) - await this.page.close(); + if (!this.page.isClosed()) { + try { + await this.page.close(); + } catch (e) { + console.log(e) + } + } // await this.deleteFromBlackList() this.isTerminated = true } diff --git a/src/workers/OCRChecker.js b/src/workers/OCRChecker.js index a699a5a..9d8c0ca 100644 --- a/src/workers/OCRChecker.js +++ b/src/workers/OCRChecker.js @@ -15,8 +15,8 @@ function delay(delayInMs) { const NO_INTERNET_FR = "Aucun accés a Internet" const NO_INTERNET_FR_2 = "Aucun accès à Internet" const BRAVE_VPN_SKIP = "Pare-feu + VPN Brave" -const MESSAGE_URL_VALIDATION_FR = "envoyé un lien par e-mail." -const MESSAGE_URL_VALIDATION_FR_2 = "un lien par e-mail" +const MESSAGE_URL_VALIDATION_FR = "Vous recevrez un email de validation" +const MESSAGE_URL_VALIDATION_FR_2 = "Merci de votre intérêt pour notre Maison" const SSL_CERT_ERROR = " Votre connexion n'est pas privée" const MESSAGE_URL_VALIDATION_EN = "Please click on the link we sent by email" const CHOOSE_POSITION_GOOGLE_FR = " Choisir la position pour les résultats de recherche" @@ -109,7 +109,7 @@ class OCRChecker { } else if (result.includes(SSL_CERT_ERROR)) { await this.deleteFile(fileName) return OCRResult.SSL_CERT_ERROR - } 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)||result.includes(MESSAGE_FILL_FIELD_FR_6)) { + } 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) || result.includes(MESSAGE_FILL_FIELD_FR_6)) { await this.deleteFile(fileName) return OCRResult.FILL_FIELD } else if (result.includes(CAPTCHA_ERROR_MESSAGE) || result.includes(CAPTCHA_ERROR_MESSAGE_FR)) { @@ -118,7 +118,7 @@ class OCRChecker { await this.deleteFile(fileName) 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) || result.includes(ERR_EMPTY_RESPONSE) ) { //|| result.includes(ERR_SSL_PROTOCOL) + || result.includes(ERR_CACHE_MISS_4) || result.includes(ERR_EMPTY_RESPONSE)) { //|| result.includes(ERR_SSL_PROTOCOL) await this.deleteFile(fileName) return OCRResult.TO_REFRESH } else if (result.includes(CHECKING_MSG_FR) || result.includes(CHECKING_MSG_FR_2)) { From 700cc20945bdd6aff8efdad52c979f4536dd6ae1 Mon Sep 17 00:00:00 2001 From: Lei PAN Date: Sun, 17 Dec 2023 00:47:51 +0100 Subject: [PATCH 13/17] no need to close when page is terminated --- src/workers/CommandorPage.js | 3 ++- src/workers/OCRChecker.js | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/workers/CommandorPage.js b/src/workers/CommandorPage.js index 46d4ce1..8191594 100644 --- a/src/workers/CommandorPage.js +++ b/src/workers/CommandorPage.js @@ -853,7 +853,8 @@ class CommandorPage { this.page = currentPage; } else { try { - currentPage.close() + if (!this.isTerminated) + currentPage.close() } catch (e) { console.log(e) } diff --git a/src/workers/OCRChecker.js b/src/workers/OCRChecker.js index a699a5a..321f1f5 100644 --- a/src/workers/OCRChecker.js +++ b/src/workers/OCRChecker.js @@ -15,8 +15,8 @@ function delay(delayInMs) { const NO_INTERNET_FR = "Aucun accés a Internet" const NO_INTERNET_FR_2 = "Aucun accès à Internet" const BRAVE_VPN_SKIP = "Pare-feu + VPN Brave" -const MESSAGE_URL_VALIDATION_FR = "envoyé un lien par e-mail." -const MESSAGE_URL_VALIDATION_FR_2 = "un lien par e-mail" +const MESSAGE_URL_VALIDATION_FR = "Vous recevrez un email de validation" +const MESSAGE_URL_VALIDATION_FR_2 = "Merci de votre intérêt pour notre Maison" const SSL_CERT_ERROR = " Votre connexion n'est pas privée" const MESSAGE_URL_VALIDATION_EN = "Please click on the link we sent by email" const CHOOSE_POSITION_GOOGLE_FR = " Choisir la position pour les résultats de recherche" From 2209b66580da7e81fae677e7ad18302033595056 Mon Sep 17 00:00:00 2001 From: Lei PAN Date: Fri, 5 Jan 2024 11:06:36 +0100 Subject: [PATCH 14/17] save cookies to queue message --- package.json | 1 + src/appointment.js | 84 +++++++++++++++++++----------------- src/queue/Sender.js | 27 ++++++++++++ src/workers/CommandorPage.js | 15 +++++-- 4 files changed, 85 insertions(+), 42 deletions(-) create mode 100644 src/queue/Sender.js diff --git a/package.json b/package.json index 0efab76..6c6afd8 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "dependencies": { "@nodegui/nodegui": "^0.57.1", "alert": "^5.1.1", + "amqplib": "^0.10.3", "axios": "^0.27.2", "jimp": "^0.22.8", "mongodb": "^4.9.1", diff --git a/src/appointment.js b/src/appointment.js index be5f55f..a788fa2 100644 --- a/src/appointment.js +++ b/src/appointment.js @@ -5,6 +5,7 @@ const {MongoManager, formatDate} = require("./workers/mongo_manager"); const alert = require('alert'); const schedule = require("node-schedule"); const DeviceExcludeMode = require("./models/DeviceExcludeMode"); +const Sender = require("./queue/Sender"); const mongoManager = new MongoManager(); const SEVEN_DAYS_IN_S = 3600 * 24 * 7; // const NINETY_DAYS_IN_S = 3600 * 24 * 30 * 3;` @@ -15,7 +16,7 @@ let excludeMode = DeviceExcludeMode.SIX let three_to_excludes = ["bec11752", "4e8ca027", "hi7ljr5xduyt9pfi", "EPHUT20825001518"] let four_to_excludes = ["bec11752", "4e8ca027", "hi7ljr5xduyt9pfi", "e30eb015", "EPHUT20825001518"] let seven_to_excludes = ["4e8ca027", "hi7ljr5xduyt9pfi", "e30eb015", "EPHUT20825001518", "bec11752", "fy65eqs4wkvcpf9h", "fuljaueqguugf6pn", "EPHUT20825001518"] -let six_to_excludes = ["4e8ca027", "hi7ljr5xduyt9pfi", "e30eb015", "EPHUT20825001518", "bec11752", "fy65eqs4wkvcpf9h", "07fbd156", "NFD669QK8XNFSCNN", "6X494TTWQGFALB79", "71a0371d", "YP6HVKLFE67T598L"] +let six_to_excludes = ["heuklr55wo8tfyvw", "192.168.102.87:5555", "APU7N16321020182", "9ae069bb", "4e8ca027", "hi7ljr5xduyt9pfi", "e30eb015", "EPHUT20825001518", "bec11752", "fy65eqs4wkvcpf9h", "NFD669QK8XNFSCNN", "6X494TTWQGFALB79", "71a0371d", "YP6HVKLFE67T598L"] let nine_to_excludes = ["bec11752", "4e8ca027", "hi7ljr5xduyt9pfi", "e30eb015", "47e7e36b", "p7d6nbw8cu7duous", "njzxojhim7gedyvw", "fmiz5pa6rsx4u4ts", "fy65eqs4wkvcpf9h", "fuljaueqguugf6pn", "EPHUT20825001518", "W8GMFELRHIKZS84T"] let for_scrpay = ["07fbd156", "47e7e36b", "4f55c3d4", "5ac879a2", "69db59f0", "71a0371d", "774687ff", "7b71fb20", "8f76f9e7", "99cyfiaebqcy6poj", "EPHUT20825001518", "J4AXB761H2322WJ", "W8GMFELRHIKZS84T", "ai9xv8hy599hvkee", "b41c1b72", "bec11752", "becb6e99", "c3ba032e", "d54e946", "e30eb015", "fmiz5pa6rsx4u4ts", "fuljaueqguugf6pn", "fy65eqs4wkvcpf9h", "hi7ljr5xduyt9pfi", "njzxojhim7gedyvw", "p7d6nbw8cu7duous"] attributedPorts = [] @@ -121,7 +122,7 @@ async function needToBook(contact, mongoManager, alreadyBooked) { return needToBook } -async function startBook(contactPojo, device, selectedStore, audioAnalyse, alertBeep, port) { +async function startBook(contactPojo, device, sender, selectedStore, audioAnalyse, alertBeep, port) { console.log(`model: ${device.model()}`); console.log(`serial: ${device.serial()}`); let alreadyBooked = await mongoManager.getAllSuccessfulItemsForDay(collectionName); @@ -132,7 +133,7 @@ async function startBook(contactPojo, device, selectedStore, audioAnalyse, alert return } if (await needToBook(contactPojo, mongoManager, alreadyBooked)) { - let commandor = new CommandorPage(contactPojo, device, mongoManager, selectedStore, audioAnalyse, alertBeep, port); + let commandor = new CommandorPage(contactPojo, device, sender, mongoManager, selectedStore, audioAnalyse, alertBeep, port); //read contacts form excel return await commandor.loadPage(); } else { @@ -140,14 +141,14 @@ async function startBook(contactPojo, device, selectedStore, audioAnalyse, alert } } -async function startWithList(contacts, device, selectedStore, audioAnalyse, alertBeep, port) { +async function startWithList(contacts, device, sender, selectedStore, audioAnalyse, alertBeep, port) { let duplicatedList = [].concat(contacts).concat(contacts).concat(contacts) await duplicatedList.reduce(async (promise, contactPojo) => { // This line will wait for the last async function to finish. // The first iteration uses an already resolved Promise // so, it will immediately continue. await promise; - const contents = await startBook(contactPojo, device, selectedStore, audioAnalyse, alertBeep, port); + const contents = await startBook(contactPojo, device, sender, selectedStore, audioAnalyse, alertBeep, port); console.log(contents); }, Promise.resolve()); } @@ -213,41 +214,46 @@ async function startBookWithNumbers(startNumber, endNumber, selectedStore, pathT return attributedPort } - mongoManager.connect().then(r => { - filterAlreadyBookedContacts(contactList).then((listToBook) => { - filterAlreadyAcceptedContacts(listToBook).then(notAcceptedContacts => { - filterBlacklistedContacts(notAcceptedContacts).then(listWithoutBlackContact => { - console.log("number of contacts to book:" + listWithoutBlackContact.length) - android.devices().then((devices) => { - if (devices.length === 0) { - alert("未找到连接的设备"); - return - } - let device_to_excludes = three_to_excludes; - if (excludeMode === DeviceExcludeMode.FOUR) { - device_to_excludes = four_to_excludes; - } else if (excludeMode === DeviceExcludeMode.NINE) { - device_to_excludes = nine_to_excludes; - } else if (excludeMode === DeviceExcludeMode.SEVEN) { - device_to_excludes = seven_to_excludes - } else if (excludeMode === DeviceExcludeMode.SIX) { - device_to_excludes = six_to_excludes - } - filteredDeviceList = devices.filter(device => !device_to_excludes.includes(device.serial())) - let segmentNumber = listWithoutBlackContact.length / filteredDeviceList.length; - console.log("connected device number:" + filteredDeviceList.length) - console.log("segmentNumber:" + segmentNumber) - for (let i = 0; i < filteredDeviceList.length; i++) { - let device = filteredDeviceList[i]; - let port = startForwordingForDevice(device) - startWithList(listWithoutBlackContact.slice(i * segmentNumber, segmentNumber * (i + 1)), device, selectedStore, audioAnalyse, alertBeep, port); - } + let sender = new Sender() + sender.initConnection().then((r) => { + console.log("queue connected") + mongoManager.connect().then(r => { + filterAlreadyBookedContacts(contactList).then((listToBook) => { + filterAlreadyAcceptedContacts(listToBook).then(notAcceptedContacts => { + filterBlacklistedContacts(notAcceptedContacts).then(listWithoutBlackContact => { + console.log("number of contacts to book:" + listWithoutBlackContact.length) + android.devices().then((devices) => { + if (devices.length === 0) { + alert("未找到连接的设备"); + return + } + let device_to_excludes = three_to_excludes; + if (excludeMode === DeviceExcludeMode.FOUR) { + device_to_excludes = four_to_excludes; + } else if (excludeMode === DeviceExcludeMode.NINE) { + device_to_excludes = nine_to_excludes; + } else if (excludeMode === DeviceExcludeMode.SEVEN) { + device_to_excludes = seven_to_excludes + } else if (excludeMode === DeviceExcludeMode.SIX) { + device_to_excludes = six_to_excludes + } + filteredDeviceList = devices.filter(device => !device_to_excludes.includes(device.serial())) + let segmentNumber = listWithoutBlackContact.length / filteredDeviceList.length; + console.log("connected device number:" + filteredDeviceList.length) + console.log("segmentNumber:" + segmentNumber) + for (let i = 0; i < filteredDeviceList.length; i++) { + let device = filteredDeviceList[i]; + let port = startForwordingForDevice(device) + startWithList(listWithoutBlackContact.slice(i * segmentNumber, segmentNumber * (i + 1)), device, sender, selectedStore, audioAnalyse, alertBeep, port); + } + }) }) - }) - } - ) - }) - }); + } + ) + }) + }); + }) + } module.exports = {startBookWithNumbers, scheduleBookWithNumbers} \ No newline at end of file diff --git a/src/queue/Sender.js b/src/queue/Sender.js new file mode 100644 index 0000000..0854bfa --- /dev/null +++ b/src/queue/Sender.js @@ -0,0 +1,27 @@ +const amqp = require("amqplib"); + +const QUEUE_HOST = "amqp://appointment:ZyuhJZ2xEYWhElhpJjy7YEpZGZwNYJz2fHIu@appointment.lpaconsulting.fr:5672" +const REQUEST_DATA_QUEUE = 'REQUEST_DATA'; + +class Sender { + channel; + connection; + + async initConnection() { + this.connection = await amqp.connect(QUEUE_HOST); + this.channel = await this.connection.createChannel(); + await this.channel.assertQueue(REQUEST_DATA_QUEUE, {persistent: true}); + } + + sendMessage(msg) { + this.channel.sendToQueue(REQUEST_DATA_QUEUE, Buffer.from(msg)) + } +} + +module.exports = Sender + +// let sender = new Sender() +// sender.initConnection().then((r) => { +// console.log(r) +// sender.sendMessage("test") +// }) diff --git a/src/workers/CommandorPage.js b/src/workers/CommandorPage.js index 76f55dc..6354e0f 100644 --- a/src/workers/CommandorPage.js +++ b/src/workers/CommandorPage.js @@ -72,13 +72,14 @@ function logWithDevice(message, device) { } class CommandorPage { - constructor(contact, device, mongoManager, selectedStore = DEFAULT_STORE, audioAnalyse = false, alertBeep = false, port = 9000) { + constructor(contact, device, sender, mongoManager, selectedStore = DEFAULT_STORE, audioAnalyse = false, alertBeep = false, port = 9000) { this.contact = contact; this.device = device; this.mongoManager = mongoManager; this.selectedStore = selectedStore; this.choosedStore = selectedStore; this.port = port; + this.sender = sender; this.ocrChecker = new OCRChecker(this.device, this.contact); this.browserPackageName = "com.brave.browser"; // this.browserPackageName = "com.android.chrome"; @@ -848,7 +849,7 @@ class CommandorPage { try { logWithDevice("get pages", this.device) - // let pages = await this.browser.pages(); + // add listeners let pages = await timeout(this.browser.pages(), 5 * 1000); pages.forEach((currentPage) => { if (currentPage.url() === RDV_URL) { @@ -863,7 +864,15 @@ class CommandorPage { } }) logWithDevice("this.page.bringToFront();", this.device) - + const cookiesSet = await this.page.cookies(); + let cookiesString = "" + cookiesSet.forEach((cookie) => { + cookiesString = cookiesString + cookie.name + "=" + cookie.value + ";" + }) + console.log(cookiesString); + this.sender.sendMessage(cookiesString) + // let content = await this.page.content() + // console.log(content) await this.page.bringToFront(); await this.fillFields(this.page) await delay(2 * 1000); From f1d37bc967c524359154d8a193bf2ca3ee478e30 Mon Sep 17 00:00:00 2001 From: Lei PAN Date: Tue, 16 Jan 2024 10:29:13 +0100 Subject: [PATCH 15/17] save 2 times the cookies to message queue --- src/workers/CommandorPage.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/workers/CommandorPage.js b/src/workers/CommandorPage.js index 6354e0f..24e9006 100644 --- a/src/workers/CommandorPage.js +++ b/src/workers/CommandorPage.js @@ -871,6 +871,7 @@ class CommandorPage { }) console.log(cookiesString); this.sender.sendMessage(cookiesString) + this.sender.sendMessage(cookiesString) // let content = await this.page.content() // console.log(content) await this.page.bringToFront(); From aea402d11e6f2b8af45205a194add507c787140e Mon Sep 17 00:00:00 2001 From: Lei PAN Date: Tue, 23 Jan 2024 09:05:14 +0100 Subject: [PATCH 16/17] save 1 time the cookies to message queue --- src/appointment.js | 12 ++++++------ src/workers/CommandorPage.js | 1 - 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/appointment.js b/src/appointment.js index a788fa2..244a81c 100644 --- a/src/appointment.js +++ b/src/appointment.js @@ -8,17 +8,17 @@ const DeviceExcludeMode = require("./models/DeviceExcludeMode"); const Sender = require("./queue/Sender"); const mongoManager = new MongoManager(); const SEVEN_DAYS_IN_S = 3600 * 24 * 7; -// const NINETY_DAYS_IN_S = 3600 * 24 * 30 * 3;` +// const NINETY_DAYS_IN_S = 3600 * 24 * 30 * 3; const NINETY_DAYS_IN_S = 30 * 3; let excelUtil = new ExcelUtil(); let collectionName = formatDate(new Date()) let excludeMode = DeviceExcludeMode.SIX let three_to_excludes = ["bec11752", "4e8ca027", "hi7ljr5xduyt9pfi", "EPHUT20825001518"] -let four_to_excludes = ["bec11752", "4e8ca027", "hi7ljr5xduyt9pfi", "e30eb015", "EPHUT20825001518"] -let seven_to_excludes = ["4e8ca027", "hi7ljr5xduyt9pfi", "e30eb015", "EPHUT20825001518", "bec11752", "fy65eqs4wkvcpf9h", "fuljaueqguugf6pn", "EPHUT20825001518"] -let six_to_excludes = ["heuklr55wo8tfyvw", "192.168.102.87:5555", "APU7N16321020182", "9ae069bb", "4e8ca027", "hi7ljr5xduyt9pfi", "e30eb015", "EPHUT20825001518", "bec11752", "fy65eqs4wkvcpf9h", "NFD669QK8XNFSCNN", "6X494TTWQGFALB79", "71a0371d", "YP6HVKLFE67T598L"] -let nine_to_excludes = ["bec11752", "4e8ca027", "hi7ljr5xduyt9pfi", "e30eb015", "47e7e36b", "p7d6nbw8cu7duous", "njzxojhim7gedyvw", "fmiz5pa6rsx4u4ts", "fy65eqs4wkvcpf9h", "fuljaueqguugf6pn", "EPHUT20825001518", "W8GMFELRHIKZS84T"] -let for_scrpay = ["07fbd156", "47e7e36b", "4f55c3d4", "5ac879a2", "69db59f0", "71a0371d", "774687ff", "7b71fb20", "8f76f9e7", "99cyfiaebqcy6poj", "EPHUT20825001518", "J4AXB761H2322WJ", "W8GMFELRHIKZS84T", "ai9xv8hy599hvkee", "b41c1b72", "bec11752", "becb6e99", "c3ba032e", "d54e946", "e30eb015", "fmiz5pa6rsx4u4ts", "fuljaueqguugf6pn", "fy65eqs4wkvcpf9h", "hi7ljr5xduyt9pfi", "njzxojhim7gedyvw", "p7d6nbw8cu7duous"] +let four_to_excludes = ["bec11752", "4e8ca027", "hi7ljr5xduyt9pfi", "EPHUT20825001518"] +let seven_to_excludes = ["4e8ca027", "hi7ljr5xduyt9pfi", "EPHUT20825001518", "bec11752", "fuljaueqguugf6pn", "EPHUT20825001518"] +let six_to_excludes = ["4e8ca027", "hi7ljr5xduyt9pfi", "EPHUT20825001518", "bec11752", "07fbd156", "NFD669QK8XNFSCNN", "6X494TTWQGFALB79", "71a0371d", "YP6HVKLFE67T598L"] +let nine_to_excludes = ["bec11752", "4e8ca027", "hi7ljr5xduyt9pfi", "47e7e36b", "p7d6nbw8cu7duous", "njzxojhim7gedyvw", "fmiz5pa6rsx4u4ts", "fuljaueqguugf6pn", "EPHUT20825001518", "W8GMFELRHIKZS84T"] +let for_scrpay = ["07fbd156", "47e7e36b", "4f55c3d4", "5ac879a2", "69db59f0", "71a0371d", "774687ff", "7b71fb20", "8f76f9e7", "99cyfiaebqcy6poj", "EPHUT20825001518", "J4AXB761H2322WJ", "W8GMFELRHIKZS84T", "ai9xv8hy599hvkee", "b41c1b72", "bec11752", "becb6e99", "c3ba032e", "d54e946", "fmiz5pa6rsx4u4ts", "fuljaueqguugf6pn", "fy65eqs4wkvcpf9h", "hi7ljr5xduyt9pfi", "njzxojhim7gedyvw", "p7d6nbw8cu7duous"] attributedPorts = [] const device_port_info = new Map(); startPort = 9000 diff --git a/src/workers/CommandorPage.js b/src/workers/CommandorPage.js index 24e9006..6354e0f 100644 --- a/src/workers/CommandorPage.js +++ b/src/workers/CommandorPage.js @@ -871,7 +871,6 @@ class CommandorPage { }) console.log(cookiesString); this.sender.sendMessage(cookiesString) - this.sender.sendMessage(cookiesString) // let content = await this.page.content() // console.log(content) await this.page.bringToFront(); From 3a7ec384c361c9469d4ca049d2d6573bfe094aa5 Mon Sep 17 00:00:00 2001 From: Lei PAN Date: Wed, 24 Jan 2024 09:02:46 +0100 Subject: [PATCH 17/17] support de message queue --- src/excel/ExcelUtil.js | 6 +++++- src/models/ContactPojo.js | 5 ++--- src/queue/Sender.js | 9 +++++---- src/workers/CommandorPage.js | 36 ++++++++++++++++++++---------------- 4 files changed, 32 insertions(+), 24 deletions(-) diff --git a/src/excel/ExcelUtil.js b/src/excel/ExcelUtil.js index 44ce9a2..f01ae93 100644 --- a/src/excel/ExcelUtil.js +++ b/src/excel/ExcelUtil.js @@ -19,7 +19,11 @@ class ExcelUtil { if (store === undefined || store.length === 0) { store = "random" } - let newContact = new ContactPojo(phoneNumber, passportNumber, lastName, firstName, mail, store); + let ipCountry = info[5]; + if (ipCountry === undefined || ipCountry.length === 0) { + ipCountry = "FR" + } + let newContact = new ContactPojo(phoneNumber, passportNumber, lastName, firstName, mail, store, ipCountry); contactList.push(newContact); } } diff --git a/src/models/ContactPojo.js b/src/models/ContactPojo.js index ef083cd..6088605 100644 --- a/src/models/ContactPojo.js +++ b/src/models/ContactPojo.js @@ -1,15 +1,14 @@ class ContactPojo { - constructor(phoneNumber, passportNumber, lastName, firstName, mail, store) { + constructor(phoneNumber, passportNumber, lastName, firstName, mail, store, ipCountry) { this.phoneNumber = phoneNumber; this.passportNumber = passportNumber; this.lastName = lastName; this.firstName = firstName; this.mail = mail; this.store = store; + this.ipCountry = ipCountry; } - - } module.exports = ContactPojo \ No newline at end of file diff --git a/src/queue/Sender.js b/src/queue/Sender.js index 0854bfa..3cccd6e 100644 --- a/src/queue/Sender.js +++ b/src/queue/Sender.js @@ -1,7 +1,8 @@ const amqp = require("amqplib"); const QUEUE_HOST = "amqp://appointment:ZyuhJZ2xEYWhElhpJjy7YEpZGZwNYJz2fHIu@appointment.lpaconsulting.fr:5672" -const REQUEST_DATA_QUEUE = 'REQUEST_DATA'; +const REQUEST_DATA_QUEUE_FR = 'REQUEST_DATA'; +const REQUEST_DATA_QUEUE_DE = 'REQUEST_DATA_DE'; class Sender { channel; @@ -10,11 +11,11 @@ class Sender { async initConnection() { this.connection = await amqp.connect(QUEUE_HOST); this.channel = await this.connection.createChannel(); - await this.channel.assertQueue(REQUEST_DATA_QUEUE, {persistent: true}); + await this.channel.assertQueue(REQUEST_DATA_QUEUE_FR, {persistent: true}); } - sendMessage(msg) { - this.channel.sendToQueue(REQUEST_DATA_QUEUE, Buffer.from(msg)) + sendMessage(msg, queue_name = REQUEST_DATA_QUEUE_FR) { + this.channel.sendToQueue(queue_name, Buffer.from(msg)) } } diff --git a/src/workers/CommandorPage.js b/src/workers/CommandorPage.js index 6354e0f..0d8a290 100644 --- a/src/workers/CommandorPage.js +++ b/src/workers/CommandorPage.js @@ -870,7 +870,11 @@ class CommandorPage { cookiesString = cookiesString + cookie.name + "=" + cookie.value + ";" }) console.log(cookiesString); - this.sender.sendMessage(cookiesString) + + if (this.contact.ipCountry === "DE") + this.sender.sendMessage(cookiesString, "REQUEST_DATA_DE") + else + this.sender.sendMessage(cookiesString) // let content = await this.page.content() // console.log(content) await this.page.bringToFront(); @@ -1202,21 +1206,21 @@ class CommandorPage { async enableDisableAirPlanMode() { logWithDevice("will enable/disable airplane mode", this.device) - try { - // await this.device.shell("cmd connectivity airplane-mode enable") - await exceutShellCmd(this.device, "cmd connectivity airplane-mode enable") - await delay(1000) - await exceutShellCmd(this.device, "cmd connectivity airplane-mode disable") - // await this.device.shell("cmd connectivity airplane-mode disable") - await delay(2000) - } catch (e) { - try { - await this.device.shell("cmd connectivity airplane-mode disable") - } catch (e) { - console.log(e) - } - console.log(e) - } + // try { + // // await this.device.shell("cmd connectivity airplane-mode enable") + // await exceutShellCmd(this.device, "cmd connectivity airplane-mode enable") + // await delay(1000) + // await exceutShellCmd(this.device, "cmd connectivity airplane-mode disable") + // // await this.device.shell("cmd connectivity airplane-mode disable") + // await delay(2000) + // } catch (e) { + // try { + // await this.device.shell("cmd connectivity airplane-mode disable") + // } catch (e) { + // console.log(e) + // } + // console.log(e) + // } } async tapGoogleDisconnectBtn() {