diff --git a/clear_all.js b/clear_all.js new file mode 100644 index 0000000..ca33a15 --- /dev/null +++ b/clear_all.js @@ -0,0 +1,28 @@ +const {exec} = require("child_process"); +const regexDevices = /[a-zA-Z0-9]/g +exec("adb devices ", (error, stdout, stderr) => { + if (error) { + console.log(`error: ${error.message}`); + return; + } + if (stderr) { + console.log(`stderr: ${stderr}`); + return; + } + console.log(`stdout: ${stdout}`); +// find the device id from output +// let matchedDeviceIds = regexDevices.exec(stdout) + regexDevices.global = true + let matchedDeviceIds = stdout.matchAll(regexDevices); + for (m in matchedDeviceIds) { + console.log(m); + } + console.log(matchedDeviceIds) + // var m; + // do { + // let m = regexDevices.exec(stdout); + // if (m) { + // console.log(m[1], m[2]); + // } + // } while (m); +}); \ No newline at end of file diff --git a/clear_all_devices.js b/clear_all_devices.js new file mode 100644 index 0000000..875198f --- /dev/null +++ b/clear_all_devices.js @@ -0,0 +1,50 @@ +const {_android: android} = require('playwright'); +const {exec} = require("child_process"); + +function delay(delayInMs) { + return new Promise(resolve => { + setTimeout(() => { + resolve(2); + }, delayInMs); + }); +} + +android.devices().then((devices) => { + devices.forEach((device) => { + console.log(device.serial() + ":will reset browser"); + exec("adb -s " + device.serial() + " shell pm clear com.android.chrome", (error, stdout, stderr) => { + if (error) { + console.log(`error: ${error.message}`); + return; + } + if (stderr) { + console.log(`stderr: ${stderr}`); + return; + } + console.log(`stdout: ${stdout}`); + }); + exec("adb -s " + device.serial() + " shell am set-debug-app --persistent com.android.chrome", (error, stdout, stderr) => { + if (error) { + console.log(`error: ${error.message}`); + return; + } + if (stderr) { + console.log(`stderr: ${stderr}`); + return; + } + console.log(`stdout: ${stdout}`); + }); + exec("adb -s " + device.serial() + " shell am start -n com.android.chrome/com.google.android.apps.chrome.Main", (error, stdout, stderr) => { + if (error) { + console.log(`error: ${error.message}`); + return; + } + if (stderr) { + console.log(`stderr: ${stderr}`); + return; + } + console.log(`stdout: ${stdout}`); + }); + }) + } +) diff --git a/clear_data.bat b/clear_data.bat index 602b399..08da9a6 100644 --- a/clear_data.bat +++ b/clear_data.bat @@ -247,7 +247,98 @@ adb -s APU7N16321020182 shell pm clear com.android.chrome adb -s APU7N16321020182 shell am set-debug-app --persistent com.android.chrome adb -s APU7N16321020182 shell am start -n com.android.chrome/com.google.android.apps.chrome.Main + #huawei mate 8 adb -s emulator-5554 shell pm clear com.android.chrome adb -s emulator-5554 shell am set-debug-app --persistent com.android.chrome -adb -s emulator-5554 shell am start -n com.android.chrome/com.google.android.apps.chrome.Main \ No newline at end of file +adb -s emulator-5554 shell am start -n com.android.chrome/com.google.android.apps.chrome.Main + +#1 +adb -s 2469c020930c7ece shell pm clear com.android.chrome +adb -s 2469c020930c7ece shell am set-debug-app --persistent com.android.chrome +adb -s 2469c020930c7ece shell am start -n com.android.chrome/com.google.android.apps.chrome.Main + +#2 +adb -s 2890e299833f7ece shell pm clear com.android.chrome +adb -s 2890e299833f7ece shell am set-debug-app --persistent com.android.chrome +adb -s 2890e299833f7ece shell am start -n com.android.chrome/com.google.android.apps.chrome.Main + +#3 +adb -s 2890e6d52b3f7ece shell pm clear com.android.chrome +adb -s 2890e6d52b3f7ece shell am set-debug-app --persistent com.android.chrome +adb -s 2890e6d52b3f7ece shell am start -n com.android.chrome/com.google.android.apps.chrome.Main + +#4 +adb -s 3058394b4a393498 shell pm clear com.android.chrome +adb -s 3058394b4a393498 shell am set-debug-app --persistent com.android.chrome +adb -s 3058394b4a393498 shell am start -n com.android.chrome/com.google.android.apps.chrome.Main + +#5 +adb -s 3131315531523098 shell pm clear com.android.chrome +adb -s 3131315531523098 shell am set-debug-app --persistent com.android.chrome +adb -s 3131315531523098 shell am start -n com.android.chrome/com.google.android.apps.chrome.Main + +#6 +adb -s 324d414b4a393498 shell pm clear com.android.chrome +adb -s 324d414b4a393498 shell am set-debug-app --persistent com.android.chrome +adb -s 324d414b4a393498 shell am start -n com.android.chrome/com.google.android.apps.chrome.Main + +#7 +adb -s 3452543639393498 shell pm clear com.android.chrome +adb -s 3452543639393498 shell am set-debug-app --persistent com.android.chrome +adb -s 3452543639393498 shell am start -n com.android.chrome/com.google.android.apps.chrome.Main + +#8 +adb -s 34e8475c2e0b7ece shell pm clear com.android.chrome +adb -s 34e8475c2e0b7ece shell am set-debug-app --persistent com.android.chrome +adb -s 34e8475c2e0b7ece shell am start -n com.android.chrome/com.google.android.apps.chrome.Main + +#9 +adb -s 364f55374c4c3098 shell pm clear com.android.chrome +adb -s 364f55374c4c3098 shell am set-debug-app --persistent com.android.chrome +adb -s 364f55374c4c3098 shell am start -n com.android.chrome/com.google.android.apps.chrome.Main + +#10 +adb -s 374a4a4b4a393498 shell pm clear com.android.chrome +adb -s 374a4a4b4a393498 shell am set-debug-app --persistent com.android.chrome +adb -s 374a4a4b4a393498 shell am start -n com.android.chrome/com.google.android.apps.chrome.Main + +#11 +adb -s 433954544a4a3098 shell pm clear com.android.chrome +adb -s 433954544a4a3098 shell am set-debug-app --persistent com.android.chrome +adb -s 433954544a4a3098 shell am start -n com.android.chrome/com.google.android.apps.chrome.Main + +#12 +adb -s 4347394655383098 shell pm clear com.android.chrome +adb -s 4347394655383098 shell am set-debug-app --persistent com.android.chrome +adb -s 4347394655383098 shell am start -n com.android.chrome/com.google.android.apps.chrome.Main + +#13 +adb -s 4448465253313498 shell pm clear com.android.chrome +adb -s 4448465253313498 shell am set-debug-app --persistent com.android.chrome +adb -s 4448465253313498 shell am start -n com.android.chrome/com.google.android.apps.chrome.Main + +#14 +adb -s 4653345154303098 shell pm clear com.android.chrome +adb -s 4653345154303098 shell am set-debug-app --persistent com.android.chrome +adb -s 4653345154303098 shell am start -n com.android.chrome/com.google.android.apps.chrome.Main + +#15 +adb -s 4b504b4b4a393498 shell pm clear com.android.chrome +adb -s 4b504b4b4a393498 shell am set-debug-app --persistent com.android.chrome +adb -s 4b504b4b4a393498 shell am start -n com.android.chrome/com.google.android.apps.chrome.Main + +#16 +adb -s 53534a4b4a393498 shell pm clear com.android.chrome +adb -s 53534a4b4a393498 shell am set-debug-app --persistent com.android.chrome +adb -s 53534a4b4a393498 shell am start -n com.android.chrome/com.google.android.apps.chrome.Main + +#17 +adb -s 5634563639393498 shell pm clear com.android.chrome +adb -s 5634563639393498 shell am set-debug-app --persistent com.android.chrome +adb -s 5634563639393498 shell am start -n com.android.chrome/com.google.android.apps.chrome.Main + +#18 +adb -s 344d395044413098 shell pm clear com.android.chrome +adb -s 344d395044413098 shell am set-debug-app --persistent com.android.chrome +adb -s 344d395044413098 shell am start -n com.android.chrome/com.google.android.apps.chrome.Main diff --git a/clear_data.sh b/clear_data.sh index 14dd25a..744840f 100644 --- a/clear_data.sh +++ b/clear_data.sh @@ -175,4 +175,123 @@ adb -s emulator-5556 shell am start -n com.android.chrome/com.google.android.app #huawei mate 8 adb -s APU7N16321020182 shell pm clear com.android.chrome adb -s APU7N16321020182 shell am set-debug-app --persistent com.android.chrome -adb -s APU7N16321020182 shell am start -n com.android.chrome/com.google.android.apps.chrome.Main \ No newline at end of file +adb -s APU7N16321020182 shell am start -n com.android.chrome/com.google.android.apps.chrome.Main +#1 +adb -s 2469c020930c7ece shell pm clear com.android.chrome +adb -s 2469c020930c7ece shell am set-debug-app --persistent com.android.chrome +adb -s 2469c020930c7ece shell am start -n com.android.chrome/com.google.android.apps.chrome.Main + +#2 +adb -s 2890e299833f7ece shell pm clear com.android.chrome +adb -s 2890e299833f7ece shell am set-debug-app --persistent com.android.chrome +adb -s 2890e299833f7ece shell am start -n com.android.chrome/com.google.android.apps.chrome.Main + +#3 +adb -s 2890e6d52b3f7ece shell pm clear com.android.chrome +adb -s 2890e6d52b3f7ece shell am set-debug-app --persistent com.android.chrome +adb -s 2890e6d52b3f7ece shell am start -n com.android.chrome/com.google.android.apps.chrome.Main + +#4 +adb -s 3058394b4a393498 shell pm clear com.android.chrome +adb -s 3058394b4a393498 shell am set-debug-app --persistent com.android.chrome +adb -s 3058394b4a393498 shell am start -n com.android.chrome/com.google.android.apps.chrome.Main + +#5 +adb -s 3131315531523098 shell pm clear com.android.chrome +adb -s 3131315531523098 shell am set-debug-app --persistent com.android.chrome +adb -s 3131315531523098 shell am start -n com.android.chrome/com.google.android.apps.chrome.Main + +#6 +adb -s 324d414b4a393498 shell pm clear com.android.chrome +adb -s 324d414b4a393498 shell am set-debug-app --persistent com.android.chrome +adb -s 324d414b4a393498 shell am start -n com.android.chrome/com.google.android.apps.chrome.Main + +#7 +adb -s 3452543639393498 shell pm clear com.android.chrome +adb -s 3452543639393498 shell am set-debug-app --persistent com.android.chrome +adb -s 3452543639393498 shell am start -n com.android.chrome/com.google.android.apps.chrome.Main + +#8 +adb -s 34e8475c2e0b7ece shell pm clear com.android.chrome +adb -s 34e8475c2e0b7ece shell am set-debug-app --persistent com.android.chrome +adb -s 34e8475c2e0b7ece shell am start -n com.android.chrome/com.google.android.apps.chrome.Main + +#9 +adb -s 364f55374c4c3098 shell pm clear com.android.chrome +adb -s 364f55374c4c3098 shell am set-debug-app --persistent com.android.chrome +adb -s 364f55374c4c3098 shell am start -n com.android.chrome/com.google.android.apps.chrome.Main + +#10 +adb -s 374a4a4b4a393498 shell pm clear com.android.chrome +adb -s 374a4a4b4a393498 shell am set-debug-app --persistent com.android.chrome +adb -s 374a4a4b4a393498 shell am start -n com.android.chrome/com.google.android.apps.chrome.Main + +#11 +adb -s 433954544a4a3098 shell pm clear com.android.chrome +adb -s 433954544a4a3098 shell am set-debug-app --persistent com.android.chrome +adb -s 433954544a4a3098 shell am start -n com.android.chrome/com.google.android.apps.chrome.Main + +#12 +adb -s 4347394655383098 shell pm clear com.android.chrome +adb -s 4347394655383098 shell am set-debug-app --persistent com.android.chrome +adb -s 4347394655383098 shell am start -n com.android.chrome/com.google.android.apps.chrome.Main + +#13 +adb -s 4448465253313498 shell pm clear com.android.chrome +adb -s 4448465253313498 shell am set-debug-app --persistent com.android.chrome +adb -s 4448465253313498 shell am start -n com.android.chrome/com.google.android.apps.chrome.Main + +#14 +adb -s 4653345154303098 shell pm clear com.android.chrome +adb -s 4653345154303098 shell am set-debug-app --persistent com.android.chrome +adb -s 4653345154303098 shell am start -n com.android.chrome/com.google.android.apps.chrome.Main + +#15 +adb -s 4b504b4b4a393498 shell pm clear com.android.chrome +adb -s 4b504b4b4a393498 shell am set-debug-app --persistent com.android.chrome +adb -s 4b504b4b4a393498 shell am start -n com.android.chrome/com.google.android.apps.chrome.Main + +#16 +adb -s 53534a4b4a393498 shell pm clear com.android.chrome +adb -s 53534a4b4a393498 shell am set-debug-app --persistent com.android.chrome +adb -s 53534a4b4a393498 shell am start -n com.android.chrome/com.google.android.apps.chrome.Main + +#17 +adb -s 5634563639393498 shell pm clear com.android.chrome +adb -s 5634563639393498 shell am set-debug-app --persistent com.android.chrome +adb -s 5634563639393498 shell am start -n com.android.chrome/com.google.android.apps.chrome.Main + +#18 +adb -s 344d395044413098 shell pm clear com.android.chrome +adb -s 344d395044413098 shell am set-debug-app --persistent com.android.chrome +adb -s 344d395044413098 shell am start -n com.android.chrome/com.google.android.apps.chrome.Main + +#18 +adb -s emulator-5562 shell pm clear com.android.chrome +adb -s emulator-5562 shell am set-debug-app --persistent com.android.chrome +adb -s emulator-5562 shell am start -n com.android.chrome/com.google.android.apps.chrome.Main + + +#18 +adb -s emulator-5558 shell pm clear com.android.chrome +adb -s emulator-5558 shell am set-debug-app --persistent com.android.chrome +adb -s emulator-5558 shell am start -n com.android.chrome/com.google.android.apps.chrome.Main + +adb -s emulator-5560 shell pm clear com.android.chrome +adb -s emulator-5560 shell am set-debug-app --persistent com.android.chrome +adb -s emulator-5560 shell am start -n com.android.chrome/com.google.android.apps.chrome.Main + +#18 +adb -s 192.168.0.37:5555 shell pm clear com.android.chrome +adb -s 192.168.0.37:5555 shell am set-debug-app --persistent com.android.chrome +adb -s 192.168.0.37:5555 shell am start -n com.android.chrome/com.google.android.apps.chrome.Main + +#18 +adb -s 192.168.0.27:5555 shell pm clear com.android.chrome +adb -s 192.168.0.27:5555 shell am set-debug-app --persistent com.android.chrome +adb -s 192.168.0.27:5555 shell am start -n com.android.chrome/com.google.android.apps.chrome.Main + +#18 +adb -s emulator-5560 shell pm clear com.android.chrome +adb -s emulator-5560 shell am set-debug-app --persistent com.android.chrome +adb -s emulator-5560 shell am start -n com.android.chrome/com.google.android.apps.chrome.Main \ No newline at end of file diff --git a/index.html b/index.html index 15523f4..fc0df77 100644 --- a/index.html +++ b/index.html @@ -44,13 +44,23 @@
-
连接的手机
+
连接的设备

+
+
+ +
+ +
+ + +
+
-
diff --git a/main.js b/main.js index 5f481f0..436ebb6 100644 --- a/main.js +++ b/main.js @@ -1,6 +1,6 @@ const {app, BrowserWindow, ipcMain} = require('electron') const {_android: android} = require('playwright'); -const startBookWithNumbers = require('./src/appointment') +const {startBookWithNumbers, scheduleBookWithNumbers} = require('./src/appointment') const path = require("path"); const homedir = require('os').homedir(); const loadIniFile = require('read-ini-file') @@ -22,6 +22,9 @@ const createWindow = () => { ipcMain.on('start-book', (event, startNumber, endNumber, selectedStore, audioAnalyse, alertBeep) => { startBook(startNumber, endNumber, selectedStore, audioAnalyse, alertBeep) }) + ipcMain.on('schedule-book', (event, startNumber, endNumber, selectedStore, audioAnalyse, alertBeep) => { + scheduleBook(startNumber, endNumber, selectedStore, audioAnalyse, alertBeep) + }) ipcMain.on('clearAllBrowsers', (event) => { clearAllBrowsers() }) @@ -83,6 +86,20 @@ function startBook(startNumber, endNumber, selectedStore, audioAnalyse, alertBee }) } +function scheduleBook(startNumber, endNumber, selectedStore, audioAnalyse, alertBeep) { + console.log("scheduleBook: " + startNumber); + console.log("endNumber: " + endNumber); + console.log("selectedStore: " + selectedStore); + console.log("audioAnalyse: " + audioAnalyse); + //load config.ini file + let config = loadIniFile.sync(configFilePath); + console.log(config); + let contactExcelFilePath = config.DEFAULT.contact_list_file; + scheduleBookWithNumbers(startNumber, endNumber, selectedStore, contactExcelFilePath, audioAnalyse, alertBeep).then(() => { + console.log("stop") + }) +} + async function scanDevices() { exec("adb devices ", (error, stdout, stderr) => { if (error) { diff --git a/preload.js b/preload.js index 565c766..bd4f43a 100644 --- a/preload.js +++ b/preload.js @@ -2,6 +2,13 @@ const {contextBridge, ipcRenderer} = require('electron') contextBridge.exposeInMainWorld('appointment', { startBook: (startNumber, endNumber, selectedStore, audioAnalyse, alertBeep) => ipcRenderer.send('start-book', startNumber, endNumber, selectedStore, audioAnalyse, alertBeep), + scheduleBook: (startNumber, endNumber, selectedStore, audioAnalyse, alertBeep) => ipcRenderer.send('schedule-book', startNumber, endNumber, selectedStore, audioAnalyse, alertBeep), clearAllBrowsers: () => ipcRenderer.send('clearAllBrowsers'), scanDevices: () => ipcRenderer.invoke('scan-devices') -}) \ No newline at end of file +}) + +// contextBridge.exposeInMainWorld('appointment', { +// startBook: (startNumber, endNumber, selectedStore, audioAnalyse, alertBeep) => ipcRenderer.send('schedule-book', startNumber, endNumber, selectedStore, audioAnalyse, alertBeep), +// clearAllBrowsers: () => ipcRenderer.send('clearAllBrowsers'), +// scanDevices: () => ipcRenderer.invoke('scan-devices') +// }) \ No newline at end of file diff --git a/renderer.js b/renderer.js index bd04efc..2ad6c3c 100644 --- a/renderer.js +++ b/renderer.js @@ -5,14 +5,17 @@ let selectedStore = 'random'; window.addEventListener('load', () => { window.appointment.scanDevices().then((deviceList) => { // Make the list - let listElement = document.getElementById('device_list'); + let deviceListSection = document.getElementById('device_list'); + let deviceNumberInfo = document.createElement("div") + deviceNumberInfo.innerHTML = "连接的设备数:" + deviceList.length; + deviceListSection.appendChild(deviceNumberInfo); for (i = 0; i < deviceList.length; ++i) { // Create an item for each one let listItem = document.createElement('li'); // Add the item text listItem.innerHTML = deviceList[i].join(" : "); // Add listItem to the listElement - listElement.appendChild(listItem); + deviceListSection.appendChild(listItem); } }) document.getElementById("start_book_btn").addEventListener('click', () => { @@ -21,6 +24,12 @@ window.addEventListener('load', () => { window.appointment.startBook(startNumber, endNumber, selectedStore, audioAnalyse, alertBeep); }) + document.getElementById("scheduler_book_btn").addEventListener('click', () => { + let audioAnalyse = document.getElementById("audio_analyse").checked; + let alertBeep = document.getElementById("alert_beep").checked; + window.appointment.scheduleBook(startNumber, endNumber, selectedStore, audioAnalyse, alertBeep); + }) + document.getElementById("clear_all_browsers").addEventListener('click', () => { window.appointment.clearAllBrowsers(); }) diff --git a/src/appointment.js b/src/appointment.js index 2744fb7..dbd69d1 100644 --- a/src/appointment.js +++ b/src/appointment.js @@ -3,12 +3,14 @@ const ExcelUtil = require("./excel/ExcelUtil"); const CommandorPage = require("./workers/CommandorPage"); const {MongoManager, formatDate} = require("./workers/mongo_manager"); const alert = require('alert'); +const schedule = require("node-schedule"); const mongoManager = new MongoManager(); const SEVEN_DAYS_IN_S = 3600 * 24 * 7; -const THIRTY_DAYS_IN_S = 3600 * 24 * 30; +const NINETY_DAYS_IN_S = 3600 * 24 * 30 * 3; let excelUtil = new ExcelUtil(); let collectionName = formatDate(new Date()) +device_to_excludes = ["47e7e36b", "e30eb015"] async function filterAlreadyBookedContacts(contactList) { let alreadyBookedContacts = await mongoManager.getAllSuccessfulItemsForDay(collectionName); @@ -31,7 +33,7 @@ async function filterAlreadyAccepteddContacts(contactList) { console.log("=====handle already accepted item before booking===="); console.log("accepted_at is " + acceptedItem.accepted_at); console.log("accepted email is " + acceptedItem.email); - needToBook = acceptedItem.accepted_at + THIRTY_DAYS_IN_S <= (new Date()) / 1000; + needToBook = acceptedItem.accepted_at + NINETY_DAYS_IN_S <= (new Date()) / 1000; if (!needToBook) { console.log("already accepted appointment --> skip"); } @@ -98,7 +100,7 @@ async function needToBook(contact, mongoManager) { 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 + THIRTY_DAYS_IN_S <= (new Date()) / 1000; + needToBook = acceptedItem.accepted_at + NINETY_DAYS_IN_S <= (new Date()) / 1000; if (!needToBook) { console.log("already accepted appointment --> skip"); } @@ -132,7 +134,18 @@ async function startWithList(contacts, device, selectedStore, audioAnalyse, aler }, Promise.resolve()); } -async function startBookWithNumbers(startNumber, endNumber, selectedStore, pathToExcelFile = '/Users/lpan/Desktop/contact_all.xlsx', audioAnalyse = false, alertBeep = false) { +async function scheduleBookWithNumbers(startNumber, endNumber, selectedStore, pathToExcelFile = '/Users/lpan/Desktop/contact_all.xlsx', audioAnalyse = true, alertBeep = false) { + console.log("scheduleBookWithNumbers() called") + alert("定时成功") + schedule.scheduleJob('30 10 * * *', function () { + console.log("start startBookWithNumbers") + startBookWithNumbers(startNumber, endNumber, selectedStore, pathToExcelFile, audioAnalyse, alertBeep) + }) +} + +async function startBookWithNumbers(startNumber, endNumber, selectedStore, pathToExcelFile = '/Users/lpan/Desktop/contact_all.xlsx', audioAnalyse = true, alertBeep = false) { + console.log("startBookWithNumbers() called, with alertBeep:" + alertBeep) + console.log("startBookWithNumbers() called, with audioAnalyse:" + audioAnalyse) let allContactList = excelUtil.readContacts(pathToExcelFile); let contactList; if (endNumber <= allContactList.length) { @@ -145,27 +158,28 @@ async function startBookWithNumbers(startNumber, endNumber, selectedStore, pathT return } mongoManager.connect().then(r => { - filterAlreadyBookedContacts(contactList).then((listToBook)=>{ + filterAlreadyBookedContacts(contactList).then((listToBook) => { filterAlreadyAccepteddContacts(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 segmentNumber = listWithoutBlackContact.length / devices.length; - console.log("connected device number:" + devices.length) - console.log("segmentNumber:" + segmentNumber) - for (let i = 0; i < devices.length; i++) { - startWithList(listWithoutBlackContact.slice(i * segmentNumber, segmentNumber * (i + 1)), devices[i], selectedStore, audioAnalyse, alertBeep); - } - }) + filterBlacklistedContacts(notAcceptedContacts).then(listWithoutBlackContact => { + console.log("number of contacts to book:" + listWithoutBlackContact.length) + android.devices().then((devices) => { + if (devices.length === 0) { + alert("未找到连接的设备"); + return + } + let 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++) { + startWithList(listWithoutBlackContact.slice(i * segmentNumber, segmentNumber * (i + 1)), filteredDeviceList[i], selectedStore, audioAnalyse, alertBeep); + } }) - } - ) - }) - }); + }) + } + ) + }) + }); } -module.exports = startBookWithNumbers \ No newline at end of file +module.exports = {startBookWithNumbers, scheduleBookWithNumbers} \ No newline at end of file diff --git a/src/excel/ExcelUtil.js b/src/excel/ExcelUtil.js index a8451c1..b1d336c 100644 --- a/src/excel/ExcelUtil.js +++ b/src/excel/ExcelUtil.js @@ -8,8 +8,6 @@ class ExcelUtil { let contactList = []; workSheetsFromFile[0].data.forEach( (info, index, list) => { - // console.log("info:" + info) - // console.log("index:" + index) if (index > 0 && info.length > 0) { // console.log(info) let name = info[0].split(" ") diff --git a/src/workers/CommandorPage.js b/src/workers/CommandorPage.js index 16a7199..e024bd9 100644 --- a/src/workers/CommandorPage.js +++ b/src/workers/CommandorPage.js @@ -7,7 +7,7 @@ const { shell } = require('electron') const GeoCaptchaSolver = require("./GeoCaptchaSolver"); -// const RDV_URL = "http://192.168.0.41:8000/test_appointment.html" +// const RDV_URL = "http://192.168.0.13:8000/test_appointment.html"; const RDV_URL = "https://rendezvousparis.hermes.com/client/register"; const BLANK_URL = "about:blank" const ERROR_CAPTCHA_UNSOLVABLE = "ERROR_CAPTCHA_UNSOLVABLE"; @@ -36,7 +36,7 @@ const CAPTCHA_ERROR_MESSAGE = "Error verifying captcha, please try again" const CAPTCHA_ERROR_MESSAGE_FR = "La vérification du captcha a échoué" const REGEX_RDV_URL = "https:\/\/rendezvousparis\.hermes\.com\/client\/register\/[A-Z0-9]+" const DEFAULT_STORE = 'faubourg'; -const searchTexts = ['hermes+rdv', 'hermes+rendezvous', 'hermes+appointment', 'hermes+appointment+online', 'appointment+hermes', 'hermes+rendez+vous', 'online+appointment+hermes', 'hermes+online+appointment'] +const searchTexts = ['hermes+rdv', 'hermes+rendezvous', 'hermes+appointment', 'hermes+appointment+online', 'appointment+hermes', 'hermes+rendez+vous','hermes+rendez+vous+paris', 'online+appointment+hermes', 'hermes+online+appointment', 'paris+hermes+online+appointment'] function delay(delayInMs) { return new Promise(resolve => { @@ -95,22 +95,24 @@ class CommandorPage { }) try { const item = searchTexts[Math.floor(Math.random() * searchTexts.length)]; - await this.page.goto("https://www.google.com/search?q=" + item, {timeout: 90 * 1000}); + await this.page.goto("https://www.google.com/search?q=" + item + "&lr=lang_en", {timeout: 90 * 1000}); // await this.page.goto(RDV_URL, {timeout: 90 * 1000}); } catch (e) { log(e) this.isTerminated = true } try { - this.page.locator('button:has-text("Tout accepter")').click() - } catch (e) { - log(e) - } - try { - this.page.locator('button:has-text("Accept all")').click() + if (this.page.url().includes("google")) + this.page.locator('button >> nth=3').click() + // this.page.locator('button:has-text("Tout accepter")').click() } catch (e) { log(e) } + // try { + // this.page.locator('button:has-text("Accept all")').click() + // } catch (e) { + // log(e) + // } try { this.page.locator(':nth-match(:text("Online Appointment"), 1)').click() } catch (e) { @@ -259,7 +261,6 @@ class CommandorPage { log(e); this.isTerminated = true; } - // await page.click(PREFER_STORE); } @@ -311,27 +312,34 @@ class CommandorPage { await this.push_message_to_queue(PublishType.SUCCESS) return } - this.captchaSolver = new SolveCaptcha(page); - await this.captchaSolver.start((solution) => { - log("solution is: " + solution); - if (solution !== ERROR_CAPTCHA_UNSOLVABLE && solution !== TWO_CAPTCHA_CONNECTION_FAILED) { - try { - if (!page.isClosed()) { - page.evaluate((solution) => { - let element = document.getElementById("g-recaptcha-response"); - if (element != null) - document.getElementById("g-recaptcha-response").innerHTML = solution; - }, solution) - this.clickValid(); + //check whether there is captcha + let pageContent = await page.content() + let hasCaptcha = pageContent.includes("g-recaptcha-response") + if (hasCaptcha) { + this.captchaSolver = new SolveCaptcha(page); + await this.captchaSolver.start((solution) => { + log("solution is: " + solution); + if (solution !== ERROR_CAPTCHA_UNSOLVABLE && solution !== TWO_CAPTCHA_CONNECTION_FAILED) { + try { + if (!page.isClosed()) { + page.evaluate((solution) => { + let element = document.getElementById("g-recaptcha-response"); + if (element != null) + document.getElementById("g-recaptcha-response").innerHTML = solution; + }, solution) + this.clickValid(); + } + } catch (e) { + log(e) + this.isTerminated = true; } - } catch (e) { - log(e) + } else { this.isTerminated = true; } - } else { - this.isTerminated = true; - } - }) + }) + } else { + await this.clickValid(); + } } async isBlocked() { @@ -357,6 +365,8 @@ class CommandorPage { } } log("发现datadome"); + } else if (currentPage.url().includes("sorry")) { + await this.resetBrowser() } else { if (currentPage.url() === RDV_URL) { await this.fillFields(this.page); diff --git a/src/workers/GeoCaptchaSolver.js b/src/workers/GeoCaptchaSolver.js index 0bb365c..8eba16f 100644 --- a/src/workers/GeoCaptchaSolver.js +++ b/src/workers/GeoCaptchaSolver.js @@ -10,6 +10,7 @@ const CAPTCHA_CONTAINER = "#captcha-container"; const WAV_URL_REGEX = "https:.+.wav"; const re = new RegExp(WAV_URL_REGEX); const SPEECH_TO_TEXT_HOST = "http://appointment.lpaconsulting.fr:8000" + // const SPEECH_TO_TEXT_HOST = "http://127.0.0.1:8000" function delay(delayInMs) { @@ -66,6 +67,17 @@ class GeoCaptchaSolver { this.device = device; } + async clearLastDigit(iframeHandler) { + let selector = "#captcha__audio > div.audio-captcha-input-container > input:nth-child(" + 6 + ")" + let lastDigit = await iframeHandler.locator(selector).inputValue() + if (lastDigit !== "") { + console.log(this.device.model() + ":last digit is not empty, clear it") + await iframeHandler.locator(selector).fill("") + } else { + console.log(this.device.model() + ":last digit is empty, do nothing") + } + } + async solve(onResult) { console.log(this.device.model() + ":solve() called.") console.log(this.device.model() + ":play audio") @@ -89,6 +101,9 @@ class GeoCaptchaSolver { // console.log("selector is " + selector) try { await iframeHandler.locator(selector).focus() + if (i === 5) { + await this.clearLastDigit(iframeHandler) + } await iframeHandler.locator(selector).fill("" + number_list[i - 1]) } catch (e) { console.log(e) @@ -100,7 +115,7 @@ class GeoCaptchaSolver { try { let content = await captcha_container.innerHTML() - console.log("inner container is " + content) + console.log(this.device.model() + ":inner container is " + content) try { if (number_list.length === 0) { onResult(false) @@ -144,7 +159,7 @@ class GeoCaptchaSolver { } async resetBrowser() { - console.log("will reset browser") + console.log(this.device.model() + ":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") diff --git a/start_avds.sh b/start_avds.sh index cc95daa..5a927e8 100644 --- a/start_avds.sh +++ b/start_avds.sh @@ -6,4 +6,7 @@ emulator -avd Pixel_2_API_30_4 & emulator -avd Pixel_2_API_30_5 & emulator -avd Pixel_2_API_30_6 & emulator -avd Pixel_2_API_30_7 & -emulator -avd Pixel_2_API_30_8 & \ No newline at end of file +emulator -avd Pixel_2_API_30_8 & +emulator -avd Pixel_2_API_30_9 & +emulator -avd Pixel_2_API_30_10 & +emulator -avd Pixel_2_API_30_11 & \ No newline at end of file diff --git a/start_avds_13.sh b/start_avds_13.sh new file mode 100644 index 0000000..2aacf69 --- /dev/null +++ b/start_avds_13.sh @@ -0,0 +1,4 @@ +emulator -avd Pixel_0 & +emulator -avd Pixel_1 & +emulator -avd Pixel_2 & +emulator -avd Pixel_3 & \ No newline at end of file