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