From cc868e011092d426c3a917454ab2facecc43d1b5 Mon Sep 17 00:00:00 2001 From: Lei PAN Date: Tue, 24 Oct 2023 08:16:19 +0200 Subject: [PATCH 1/3] change brave notification order --- src/workers/OCRChecker.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/workers/OCRChecker.js b/src/workers/OCRChecker.js index 3f15761..96fe260 100644 --- a/src/workers/OCRChecker.js +++ b/src/workers/OCRChecker.js @@ -108,6 +108,10 @@ class OCRChecker { await this.deleteFile(fileName) await this.deleteFile(screenShot) return OCRResult.SUCCESS + } else if (result.includes(BRAVE_NOTIFICATION)) { + await this.deleteFile(fileName) + await this.deleteFile(screenShot) + return OCRResult.BRAVE_NOTIFICATION } 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) @@ -175,10 +179,6 @@ class OCRChecker { await this.deleteFile(fileName) 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) From 00d70cd00f6bcb2b1d32a86a6bd2f66481d26076 Mon Sep 17 00:00:00 2001 From: Lei PAN Date: Wed, 25 Oct 2023 08:59:46 +0200 Subject: [PATCH 2/3] use adb to start browser --- package.json | 2 +- src/appointment.js | 37 ++++++++++++++++++------------------ src/workers/CommandorPage.js | 32 ++++++++++++++++++------------- 3 files changed, 39 insertions(+), 32 deletions(-) diff --git a/package.json b/package.json index 5815948..dfdd90a 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ "node-tesseract-ocr": "^2.2.1", "node-wget": "^0.4.3", "node-xlsx": "^0.21.0", - "playwright": "^1.32.1", + "playwright": "^1.39.0", "puppeteer": "^15.5.0", "read-ini-file": "^3.0.1", "uuid": "^9.0.0", diff --git a/src/appointment.js b/src/appointment.js index b8a0db2..f511c43 100644 --- a/src/appointment.js +++ b/src/appointment.js @@ -16,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"] +let six_to_excludes = ["4e8ca027", "hi7ljr5xduyt9pfi", "e30eb015", "EPHUT20825001518", "bec11752", "fy65eqs4wkvcpf9h", "07fbd156"] 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 = [] @@ -80,12 +80,12 @@ async function filterBlacklistedContacts(contactList) { return contactsToBook; } -async function needToBook(contact, mongoManager) { +async function needToBook(contact, mongoManager, alreadyBooked) { console.log("check contact with email " + contact.mail) - let alreadyBooked = await mongoManager.getAllSuccessfulItemsForDay(collectionName); + // let alreadyBooked = await mongoManager.getAllSuccessfulItemsForDay(collectionName); // let blackListItems = await mongoManager.getAllBlackedListItems(); let blackListItems = []; - let alreadyAcceptedItems = await mongoManager.getAllAcceptedAppointments(); + // let alreadyAcceptedItems = await mongoManager.getAllAcceptedAppointments(); let needToBook = true; await alreadyBooked.forEach((bookedItem) => { if (bookedItem.email === contact.mail) { @@ -106,26 +106,27 @@ async function needToBook(contact, mongoManager) { } }) } - if (needToBook) { - await alreadyAcceptedItems.forEach((acceptedItem) => { - if (acceptedItem.email === contact.mail) { - console.log("=====handle already accepted item===="); - console.log("accepted_at is " + acceptedItem.accepted_at); - console.log("accepted email is " + acceptedItem.email); - needToBook = acceptedItem.accepted_at + NINETY_DAYS_IN_S <= (new Date()) / 1000; - if (!needToBook) { - console.log("already accepted appointment --> skip"); - } - } - }) - } + // if (needToBook) { + // await alreadyAcceptedItems.forEach((acceptedItem) => { + // if (acceptedItem.email === contact.mail) { + // console.log("=====handle already accepted item===="); + // console.log("accepted_at is " + acceptedItem.accepted_at); + // console.log("accepted email is " + acceptedItem.email); + // needToBook = acceptedItem.accepted_at + NINETY_DAYS_IN_S <= (new Date()) / 1000; + // if (!needToBook) { + // console.log("already accepted appointment --> skip"); + // } + // } + // }) + // } return needToBook } async function startBook(contactPojo, device, selectedStore, audioAnalyse, alertBeep, port) { console.log(`model: ${device.model()}`); console.log(`serial: ${device.serial()}`); - if (await needToBook(contactPojo, mongoManager)) { + let alreadyBooked = await mongoManager.getAllSuccessfulItemsForDay(collectionName); + if (await needToBook(contactPojo, mongoManager, alreadyBooked)) { let commandor = new CommandorPage(contactPojo, device, mongoManager, selectedStore, audioAnalyse, alertBeep, port); //read contacts form excel return await commandor.loadPage(); diff --git a/src/workers/CommandorPage.js b/src/workers/CommandorPage.js index c018b82..0fafa91 100644 --- a/src/workers/CommandorPage.js +++ b/src/workers/CommandorPage.js @@ -146,7 +146,7 @@ class CommandorPage { async loadPage() { logWithDevice(this.device.serial() + ":loadPage() called, with port:" + this.port, this.device); try { - await this.device.shell("am start -n " + this.browserPackageName + "/com.google.android.apps.chrome.Main") + await this.startPage(this.device, this.browserPackageName + "/com.google.android.apps.chrome.Main") await delay(5 * 1000); } catch (e) { console.log(e) @@ -201,9 +201,6 @@ class CommandorPage { await this.enableDisableAirPlanMode(); await delay(10 * 1000); await this.clickOnlineAppointment(); - // await delay(2000); - // if (!this.isTerminated) - // await this.clickOnlineAppointment(); } else { this.isTerminated = true; } @@ -1002,9 +999,9 @@ class CommandorPage { await this.checkResultWithOcr(); break; case OCRResult.BRAVE_PRIVACY_PUB: - if (this.device.model() === "MI 5s") - await this.device.shell("input tap " + 60 + " " + 1400) - else + if (this.device.model() === "MI 5s") { + await this.tapForDevice(this.device, 60, 1400) + } else await this.tapForDevice(this.device, 455, 1920) await delay(2000); await this.checkResultWithOcr(); @@ -1016,7 +1013,8 @@ class CommandorPage { else if (this.device.model() === "22041219PG") await this.device.shell("input tap " + 530 + " " + 1600) else - await this.device.shell("input tap " + 500 + " " + 1680) + await this.tapForDevice(this.device, 500, 1680) + // await this.device.shell("input tap " + 500 + " " + 1680) await delay(2000); await this.checkResultWithOcr(); break; @@ -1230,9 +1228,9 @@ class CommandorPage { async tapGoogleDisconnectBtn() { if (this.device.model() === "MI 5s") { - if (this.browserPackageName.includes("brave")) - await this.device.shell("input tap " + 535 + " " + 1629) - else + if (this.browserPackageName.includes("brave")) { + await this.tapForDevice(this.device, 535, 1629) + } else await this.device.shell("input tap " + 550 + " " + 1740) } else { if (this.browserPackageName.includes("brave") && this.device.model() === "CPH2219") { @@ -1243,11 +1241,19 @@ class CommandorPage { await this.device.shell("input tap " + 411 + " " + 1970) } else if (this.browserPackageName.includes("brave") && this.device.model() === "22041219PG") { await this.device.shell("input tap " + 411 + " " + 2020) - } else - await this.device.shell("input tap " + 411 + " " + 2100) + } else { + await this.tapForDevice(this.device, 411, 2100) + } + // await this.device.shell("input tap " + 411 + " " + 2100) } await delay(2000); } + + async startPage(device, activity) { + let cmd = `adb -s ${device.serial()} shell am start -n ${activity}` + logWithDevice("cmd is " + cmd, this.device) + await exec(cmd); + } } module From fbdc5ad73c834d9ec8d5be72b2d6d2efa2b81684 Mon Sep 17 00:00:00 2001 From: Lei PAN Date: Wed, 25 Oct 2023 16:03:23 +0200 Subject: [PATCH 3/3] use adb to start browser --- src/workers/CommandorPage.js | 49 ++++++++++++++++++++--------- src/workers/SlidingCaptchaSolver.js | 5 --- 2 files changed, 35 insertions(+), 19 deletions(-) diff --git a/src/workers/CommandorPage.js b/src/workers/CommandorPage.js index 0fafa91..b8ab9d5 100644 --- a/src/workers/CommandorPage.js +++ b/src/workers/CommandorPage.js @@ -55,6 +55,18 @@ function log(message) { appointmentLogger.log({level: "info", message: message}) } +async function clearApp(device, packageName) { + let cmd = `adb -s ${device.serial()} shell pm clear ${packageName}` + logWithDevice("cmd is " + cmd, device) + await exec(cmd); +} + +async function exceutShellCmd(device, cmdToExecut) { + let cmd = `adb -s ${device.serial()} shell ${cmdToExecut}` + logWithDevice("cmd is " + cmd, device) + await exec(cmd); +} + function logWithDevice(message, device) { appointmentLogger.log({level: "info", message: device.model() + ":" + device.serial() + ":" + message}) } @@ -146,8 +158,11 @@ class CommandorPage { async loadPage() { logWithDevice(this.device.serial() + ":loadPage() called, with port:" + this.port, this.device); try { + // let cmd = 'adb -s ' + device.serial() + " forward tcp:" + attributedPort + " localabstract:chrome_devtools_remote"; + await exceutShellCmd(this.device, " forward tcp:" + this.port + " localabstract:chrome_devtools_remote") + await delay(1 * 1000); await this.startPage(this.device, this.browserPackageName + "/com.google.android.apps.chrome.Main") - await delay(5 * 1000); + await delay(4 * 1000); } catch (e) { console.log(e) this.isTerminated = true; @@ -810,7 +825,8 @@ class CommandorPage { this.isPhoneInput = false; this.isPasspordInput = false; // this.disconnectBrowser(); - await this.device.shell("pm clear " + this.browserPackageName) + await clearApp(this.device, this.browserPackageName) + // await this.device.shell("pm clear " + this.browserPackageName) await delay(1000) this.isTerminated = true; // await this.checkResultWithOcr(); @@ -986,9 +1002,10 @@ class CommandorPage { // await this.device.shell("input tap " + 530 + " " + 970) } else if (this.device.model() === "ONEPLUS A6000") await this.device.shell("input tap " + 530 + " " + 1064) - else if (this.device.model() === "KB2003") + else if (this.device.model() === "KB2003" || this.device.model() === "DE2117") { await this.tapForDevice(this.device, 500, 1200) - else + await this.tapForDevice(this.device, 500, 1120) + } else try { await this.tapForDevice(this.device, 500, 1120) // await this.device.shell("input tap " + 500 + " " + 1120) @@ -1008,11 +1025,11 @@ class CommandorPage { break; case OCRResult.BRAVE_NOTIFICATION: logWithDevice("BRAVE_NOTIFICATION", this.device) - if (this.device.model() === "21091116C") - await this.device.shell("input tap " + 540 + " " + 1611) - else if (this.device.model() === "22041219PG") - await this.device.shell("input tap " + 530 + " " + 1600) - else + if (this.device.model() === "21091116C") { + await this.tapForDevice(this.device, 540, 1611) + } else if (this.device.model() === "22041219PG") { + await this.tapForDevice(this.device, 530, 1600) + } else await this.tapForDevice(this.device, 500, 1680) // await this.device.shell("input tap " + 500 + " " + 1680) await delay(2000); @@ -1210,11 +1227,11 @@ class CommandorPage { async enableDisableAirPlanMode() { logWithDevice("will enable/disable airplane mode", this.device) try { - await this.device.shell("cmd connectivity airplane-mode enable") - // await this.device.shell("adb shell settings put global airplane_mode_on 1") + // await this.device.shell("cmd connectivity airplane-mode enable") + await exceutShellCmd(this.device, "cmd connectivity airplane-mode enable") await delay(1000) - // await this.device.shell("adb shell settings put global airplane_mode_on 0") - await this.device.shell("cmd connectivity airplane-mode disable") + await exceutShellCmd(this.device, "cmd connectivity airplane-mode disable") + // await this.device.shell("cmd connectivity airplane-mode disable") await delay(2000) } catch (e) { try { @@ -1239,8 +1256,12 @@ class CommandorPage { await this.device.shell("input tap " + 411 + " " + 1977) } else if (this.browserPackageName.includes("brave") && this.device.model() === "ONEPLUS A6000") { await this.device.shell("input tap " + 411 + " " + 1970) + } else if (this.browserPackageName.includes("brave") && this.device.model() === "ASUS_X00QD") { + await this.device.shell("input tap " + 411 + " " + 1970) } else if (this.browserPackageName.includes("brave") && this.device.model() === "22041219PG") { - await this.device.shell("input tap " + 411 + " " + 2020) + await this.tapForDevice(this.device, 411, 2020) + } else if (this.browserPackageName.includes("brave") && this.device.model() === "21091116C") { + await this.tapForDevice(this.device, 411, 2020) } else { await this.tapForDevice(this.device, 411, 2100) } diff --git a/src/workers/SlidingCaptchaSolver.js b/src/workers/SlidingCaptchaSolver.js index 31b402f..1988579 100644 --- a/src/workers/SlidingCaptchaSolver.js +++ b/src/workers/SlidingCaptchaSolver.js @@ -102,11 +102,6 @@ class SlidingCaptchaSolver { let result = response.data; console.log(result); await callback(result); - // console.log("will delete png file: " + fileName); - // await fs.unlink(fileName, (err) => { - // if (err) throw err; - // console.log(fileName + ' was deleted'); - // }) } else { console.log("error"); await callback([]);