From 56347a83f11a25e32221c037e40f5978aaaf4865 Mon Sep 17 00:00:00 2001 From: PAN Lei Date: Sun, 15 Dec 2024 11:31:07 +0100 Subject: [PATCH] add bindSerial param --- src/appointment.js | 24 +++++++++++++----------- src/workers/CommandorPage.js | 2 +- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/appointment.js b/src/appointment.js index b220e21..7308d7c 100644 --- a/src/appointment.js +++ b/src/appointment.js @@ -63,7 +63,7 @@ async function needToBook(contact, mongoManager, alreadyBooked) { return needToBook } -async function startBook(contactPojo, device, sender, selectedStore, audioAnalyse, alertBeep, port) { +async function startBook(contactPojo, device, sender, selectedStore, alertBeep, port) { console.log(`model: ${device.model}`); console.log(`serial: ${device.serial}`); let alreadyBooked = await mongoManager.getAllSuccessfulItemsForDay(collectionName); @@ -74,7 +74,7 @@ async function startBook(contactPojo, device, sender, selectedStore, audioAnalys return } if (await needToBook(contactPojo, mongoManager, alreadyBooked)) { - let commandor = new CommandorPage(contactPojo, device, sender, mongoManager, selectedStore, audioAnalyse, alertBeep, port); + let commandor = new CommandorPage(contactPojo, device, sender, mongoManager, selectedStore, alertBeep, port); //read contacts form excel return await commandor.loadPage(); } else { @@ -82,14 +82,14 @@ async function startBook(contactPojo, device, sender, selectedStore, audioAnalys } } -async function startWithList(contacts, device, sender, selectedStore, audioAnalyse, alertBeep, port) { +async function startWithList(contacts, device, sender, selectedStore, 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, sender, selectedStore, audioAnalyse, alertBeep, port); + const contents = await startBook(contactPojo, device, sender, selectedStore, alertBeep, port); console.log(contents); }, Promise.resolve()); } @@ -128,7 +128,7 @@ function getContactListForDevice(device, allContactList) { return contactList; } -async function startBookWithNumbers(startNumber, endNumber, selectedStore, pathToExcelFile = '/Users/lpan/Desktop/contact_all.xlsx', audioAnalyse = true, alertBeep = false) { +async function startBookWithNumbers(startNumber, endNumber, selectedStore, pathToExcelFile = '/Users/lpan/Desktop/contact_all.xlsx', bindSerial = true, alertBeep = false) { let allContactList = excelUtil.readContacts(pathToExcelFile); let contactList; if (endNumber <= allContactList.length) { @@ -159,8 +159,6 @@ async function startBookWithNumbers(startNumber, endNumber, selectedStore, pathT const output = execSync(cmd, {encoding: 'utf-8'}); // the default is 'buffer' console.log('Output was:\n', output); } - // start chrome - // device.shell("am start -n com.brave.browser/com.google.android.apps.chrome.Main") return attributedPort } @@ -190,7 +188,7 @@ async function startBookWithNumbers(startNumber, endNumber, selectedStore, pathT } else if (includeMode === DeviceExcludeMode.APPOINTMENT) { device_to_excludes = appointment_to_include } else if (includeMode === DeviceExcludeMode.ZERO) { - device_to_excludes = [] + device_to_excludes = ["127.0.0.1:6555"] } let filteredDeviceList; if (includeMode === DeviceExcludeMode.ZERO) { @@ -205,10 +203,14 @@ async function startBookWithNumbers(startNumber, endNumber, selectedStore, pathT for (let i = 0; i < filteredDeviceList.length; i++) { let device = filteredDeviceList[i]; let port = startForwordingForDevice(device) - let _contactList = listWithoutBlackContact.slice(i * segmentNumber, segmentNumber * (i + 1)) - // let _contactList = getContactListForDevice(device, listWithoutBlackContact) + let _contactList = [] + if (bindSerial) { + _contactList = getContactListForDevice(device, listWithoutBlackContact) + } else { + _contactList = listWithoutBlackContact.slice(i * segmentNumber, segmentNumber * (i + 1)) + } console.log("contactList: for device:" + device.serial + " has " + _contactList.length) - startWithList(_contactList, device, sender, selectedStore, audioAnalyse, alertBeep, port); + startWithList(_contactList, device, sender, selectedStore, alertBeep, port); } }) diff --git a/src/workers/CommandorPage.js b/src/workers/CommandorPage.js index 5f218dd..6d7f1a9 100644 --- a/src/workers/CommandorPage.js +++ b/src/workers/CommandorPage.js @@ -84,7 +84,7 @@ function logWithDevice(message, device) { 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'] class CommandorPage { - constructor(contact, device, sender, mongoManager, selectedStore = DEFAULT_STORE, audioAnalyse = false, alertBeep = false, port = 9000, shareCookiesWithRequests = true) { + constructor(contact, device, sender, mongoManager, selectedStore = DEFAULT_STORE, alertBeep = false, port = 9000, shareCookiesWithRequests = true) { this.contact = contact; // to remove this line if we want to use store in contacts // this.contact.store = DEFAULT_STORE