Merge branch 'master' of bitbucket.org:panleicim/appointment_tool_js

This commit is contained in:
2023-03-09 09:11:41 +01:00
14 changed files with 441 additions and 66 deletions
+28
View File
@@ -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);
});
+50
View File
@@ -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}`);
});
})
}
)
+92 -1
View File
@@ -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 set-debug-app --persistent com.android.chrome
adb -s APU7N16321020182 shell am start -n com.android.chrome/com.google.android.apps.chrome.Main adb -s APU7N16321020182 shell am start -n com.android.chrome/com.google.android.apps.chrome.Main
#huawei mate 8 #huawei mate 8
adb -s emulator-5554 shell pm clear com.android.chrome 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 set-debug-app --persistent com.android.chrome
adb -s emulator-5554 shell am start -n com.android.chrome/com.google.android.apps.chrome.Main 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
+120 -1
View File
@@ -175,4 +175,123 @@ adb -s emulator-5556 shell am start -n com.android.chrome/com.google.android.app
#huawei mate 8 #huawei mate 8
adb -s APU7N16321020182 shell pm clear com.android.chrome 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 set-debug-app --persistent com.android.chrome
adb -s APU7N16321020182 shell am start -n com.android.chrome/com.google.android.apps.chrome.Main 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
+13 -3
View File
@@ -44,13 +44,23 @@
</div> </div>
<br> <br>
<div class="row"> <div class="row">
<h5>连接的手机</h5> <h5>连接的设备</h5>
<div id="device_list"/> <div id="device_list"/>
</div> </div>
<br/> <br/>
<div class="row">
<div class="col-md-4">
<button id="start_book_btn" type="button" class="btn btn-primary">开始约会
</button>
</div>
<div class="col-md-4">
<button id="scheduler_book_btn" type="button" class="btn btn-primary">10点30开始
</button>
</div>
</div>
<button id="start_book_btn" type="button" class="btn btn-primary">开始约会
</button>
<script src="./renderer.js"></script> <script src="./renderer.js"></script>
</div> </div>
</body> </body>
+18 -1
View File
@@ -1,6 +1,6 @@
const {app, BrowserWindow, ipcMain} = require('electron') const {app, BrowserWindow, ipcMain} = require('electron')
const {_android: android} = require('playwright'); const {_android: android} = require('playwright');
const startBookWithNumbers = require('./src/appointment') const {startBookWithNumbers, scheduleBookWithNumbers} = require('./src/appointment')
const path = require("path"); const path = require("path");
const homedir = require('os').homedir(); const homedir = require('os').homedir();
const loadIniFile = require('read-ini-file') const loadIniFile = require('read-ini-file')
@@ -22,6 +22,9 @@ const createWindow = () => {
ipcMain.on('start-book', (event, startNumber, endNumber, selectedStore, audioAnalyse, alertBeep) => { ipcMain.on('start-book', (event, startNumber, endNumber, selectedStore, audioAnalyse, alertBeep) => {
startBook(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) => { ipcMain.on('clearAllBrowsers', (event) => {
clearAllBrowsers() 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() { async function scanDevices() {
exec("adb devices ", (error, stdout, stderr) => { exec("adb devices ", (error, stdout, stderr) => {
if (error) { if (error) {
+8 -1
View File
@@ -2,6 +2,13 @@ const {contextBridge, ipcRenderer} = require('electron')
contextBridge.exposeInMainWorld('appointment', { contextBridge.exposeInMainWorld('appointment', {
startBook: (startNumber, endNumber, selectedStore, audioAnalyse, alertBeep) => ipcRenderer.send('start-book', startNumber, endNumber, selectedStore, audioAnalyse, alertBeep), 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'), clearAllBrowsers: () => ipcRenderer.send('clearAllBrowsers'),
scanDevices: () => ipcRenderer.invoke('scan-devices') scanDevices: () => ipcRenderer.invoke('scan-devices')
}) })
// 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')
// })
+11 -2
View File
@@ -5,14 +5,17 @@ let selectedStore = 'random';
window.addEventListener('load', () => { window.addEventListener('load', () => {
window.appointment.scanDevices().then((deviceList) => { window.appointment.scanDevices().then((deviceList) => {
// Make the list // 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) { for (i = 0; i < deviceList.length; ++i) {
// Create an item for each one // Create an item for each one
let listItem = document.createElement('li'); let listItem = document.createElement('li');
// Add the item text // Add the item text
listItem.innerHTML = deviceList[i].join(" : "); listItem.innerHTML = deviceList[i].join(" : ");
// Add listItem to the listElement // Add listItem to the listElement
listElement.appendChild(listItem); deviceListSection.appendChild(listItem);
} }
}) })
document.getElementById("start_book_btn").addEventListener('click', () => { document.getElementById("start_book_btn").addEventListener('click', () => {
@@ -21,6 +24,12 @@ window.addEventListener('load', () => {
window.appointment.startBook(startNumber, endNumber, selectedStore, audioAnalyse, alertBeep); 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', () => { document.getElementById("clear_all_browsers").addEventListener('click', () => {
window.appointment.clearAllBrowsers(); window.appointment.clearAllBrowsers();
}) })
+38 -24
View File
@@ -3,12 +3,14 @@ const ExcelUtil = require("./excel/ExcelUtil");
const CommandorPage = require("./workers/CommandorPage"); const CommandorPage = require("./workers/CommandorPage");
const {MongoManager, formatDate} = require("./workers/mongo_manager"); const {MongoManager, formatDate} = require("./workers/mongo_manager");
const alert = require('alert'); const alert = require('alert');
const schedule = require("node-schedule");
const mongoManager = new MongoManager(); const mongoManager = new MongoManager();
const SEVEN_DAYS_IN_S = 3600 * 24 * 7; 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 excelUtil = new ExcelUtil();
let collectionName = formatDate(new Date()) let collectionName = formatDate(new Date())
device_to_excludes = ["47e7e36b", "e30eb015"]
async function filterAlreadyBookedContacts(contactList) { async function filterAlreadyBookedContacts(contactList) {
let alreadyBookedContacts = await mongoManager.getAllSuccessfulItemsForDay(collectionName); let alreadyBookedContacts = await mongoManager.getAllSuccessfulItemsForDay(collectionName);
@@ -31,7 +33,7 @@ async function filterAlreadyAccepteddContacts(contactList) {
console.log("=====handle already accepted item before booking===="); console.log("=====handle already accepted item before booking====");
console.log("accepted_at is " + acceptedItem.accepted_at); console.log("accepted_at is " + acceptedItem.accepted_at);
console.log("accepted email is " + acceptedItem.email); 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) { if (!needToBook) {
console.log("already accepted appointment --> skip"); console.log("already accepted appointment --> skip");
} }
@@ -98,7 +100,7 @@ async function needToBook(contact, mongoManager) {
console.log("=====handle already accepted item===="); console.log("=====handle already accepted item====");
console.log("accepted_at is " + acceptedItem.accepted_at); console.log("accepted_at is " + acceptedItem.accepted_at);
console.log("accepted email is " + acceptedItem.email); 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) { if (!needToBook) {
console.log("already accepted appointment --> skip"); console.log("already accepted appointment --> skip");
} }
@@ -132,7 +134,18 @@ async function startWithList(contacts, device, selectedStore, audioAnalyse, aler
}, Promise.resolve()); }, 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 allContactList = excelUtil.readContacts(pathToExcelFile);
let contactList; let contactList;
if (endNumber <= allContactList.length) { if (endNumber <= allContactList.length) {
@@ -145,27 +158,28 @@ async function startBookWithNumbers(startNumber, endNumber, selectedStore, pathT
return return
} }
mongoManager.connect().then(r => { mongoManager.connect().then(r => {
filterAlreadyBookedContacts(contactList).then((listToBook)=>{ filterAlreadyBookedContacts(contactList).then((listToBook) => {
filterAlreadyAccepteddContacts(listToBook).then(notAcceptedContacts => { filterAlreadyAccepteddContacts(listToBook).then(notAcceptedContacts => {
filterBlacklistedContacts(notAcceptedContacts).then(listWithoutBlackContact => { filterBlacklistedContacts(notAcceptedContacts).then(listWithoutBlackContact => {
console.log("number of contacts to book:" + listWithoutBlackContact.length) console.log("number of contacts to book:" + listWithoutBlackContact.length)
android.devices().then((devices) => { android.devices().then((devices) => {
if (devices.length === 0) { if (devices.length === 0) {
alert("未找到连接的设备"); alert("未找到连接的设备");
return return
} }
let segmentNumber = listWithoutBlackContact.length / devices.length; let filteredDeviceList = devices.filter(device => !device_to_excludes.includes(device.serial()))
console.log("connected device number:" + devices.length) let segmentNumber = listWithoutBlackContact.length / filteredDeviceList.length;
console.log("segmentNumber:" + segmentNumber) console.log("connected device number:" + filteredDeviceList.length)
for (let i = 0; i < devices.length; i++) { console.log("segmentNumber:" + segmentNumber)
startWithList(listWithoutBlackContact.slice(i * segmentNumber, segmentNumber * (i + 1)), devices[i], selectedStore, audioAnalyse, alertBeep); for (let i = 0; i < filteredDeviceList.length; i++) {
} startWithList(listWithoutBlackContact.slice(i * segmentNumber, segmentNumber * (i + 1)), filteredDeviceList[i], selectedStore, audioAnalyse, alertBeep);
}) }
}) })
} })
) }
}) )
}); })
});
} }
module.exports = startBookWithNumbers module.exports = {startBookWithNumbers, scheduleBookWithNumbers}
-2
View File
@@ -8,8 +8,6 @@ class ExcelUtil {
let contactList = []; let contactList = [];
workSheetsFromFile[0].data.forEach( workSheetsFromFile[0].data.forEach(
(info, index, list) => { (info, index, list) => {
// console.log("info:" + info)
// console.log("index:" + index)
if (index > 0 && info.length > 0) { if (index > 0 && info.length > 0) {
// console.log(info) // console.log(info)
let name = info[0].split(" ") let name = info[0].split(" ")
+38 -28
View File
@@ -7,7 +7,7 @@ const {
shell shell
} = require('electron') } = require('electron')
const GeoCaptchaSolver = require("./GeoCaptchaSolver"); 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 RDV_URL = "https://rendezvousparis.hermes.com/client/register";
const BLANK_URL = "about:blank" const BLANK_URL = "about:blank"
const ERROR_CAPTCHA_UNSOLVABLE = "ERROR_CAPTCHA_UNSOLVABLE"; 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 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 REGEX_RDV_URL = "https:\/\/rendezvousparis\.hermes\.com\/client\/register\/[A-Z0-9]+"
const DEFAULT_STORE = 'faubourg'; 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) { function delay(delayInMs) {
return new Promise(resolve => { return new Promise(resolve => {
@@ -95,22 +95,24 @@ class CommandorPage {
}) })
try { try {
const item = searchTexts[Math.floor(Math.random() * searchTexts.length)]; 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}); // await this.page.goto(RDV_URL, {timeout: 90 * 1000});
} catch (e) { } catch (e) {
log(e) log(e)
this.isTerminated = true this.isTerminated = true
} }
try { try {
this.page.locator('button:has-text("Tout accepter")').click() if (this.page.url().includes("google"))
} catch (e) { this.page.locator('button >> nth=3').click()
log(e) // this.page.locator('button:has-text("Tout accepter")').click()
}
try {
this.page.locator('button:has-text("Accept all")').click()
} catch (e) { } catch (e) {
log(e) log(e)
} }
// try {
// this.page.locator('button:has-text("Accept all")').click()
// } catch (e) {
// log(e)
// }
try { try {
this.page.locator(':nth-match(:text("Online Appointment"), 1)').click() this.page.locator(':nth-match(:text("Online Appointment"), 1)').click()
} catch (e) { } catch (e) {
@@ -259,7 +261,6 @@ class CommandorPage {
log(e); log(e);
this.isTerminated = true; this.isTerminated = true;
} }
// await page.click(PREFER_STORE);
} }
@@ -311,27 +312,34 @@ class CommandorPage {
await this.push_message_to_queue(PublishType.SUCCESS) await this.push_message_to_queue(PublishType.SUCCESS)
return return
} }
this.captchaSolver = new SolveCaptcha(page); //check whether there is captcha
await this.captchaSolver.start((solution) => { let pageContent = await page.content()
log("solution is: " + solution); let hasCaptcha = pageContent.includes("g-recaptcha-response")
if (solution !== ERROR_CAPTCHA_UNSOLVABLE && solution !== TWO_CAPTCHA_CONNECTION_FAILED) { if (hasCaptcha) {
try { this.captchaSolver = new SolveCaptcha(page);
if (!page.isClosed()) { await this.captchaSolver.start((solution) => {
page.evaluate((solution) => { log("solution is: " + solution);
let element = document.getElementById("g-recaptcha-response"); if (solution !== ERROR_CAPTCHA_UNSOLVABLE && solution !== TWO_CAPTCHA_CONNECTION_FAILED) {
if (element != null) try {
document.getElementById("g-recaptcha-response").innerHTML = solution; if (!page.isClosed()) {
}, solution) page.evaluate((solution) => {
this.clickValid(); 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) { } else {
log(e)
this.isTerminated = true; this.isTerminated = true;
} }
} else { })
this.isTerminated = true; } else {
} await this.clickValid();
}) }
} }
async isBlocked() { async isBlocked() {
@@ -357,6 +365,8 @@ class CommandorPage {
} }
} }
log("发现datadome"); log("发现datadome");
} else if (currentPage.url().includes("sorry")) {
await this.resetBrowser()
} else { } else {
if (currentPage.url() === RDV_URL) { if (currentPage.url() === RDV_URL) {
await this.fillFields(this.page); await this.fillFields(this.page);
+17 -2
View File
@@ -10,6 +10,7 @@ const CAPTCHA_CONTAINER = "#captcha-container";
const WAV_URL_REGEX = "https:.+.wav"; const WAV_URL_REGEX = "https:.+.wav";
const re = new RegExp(WAV_URL_REGEX); const re = new RegExp(WAV_URL_REGEX);
const SPEECH_TO_TEXT_HOST = "http://appointment.lpaconsulting.fr:8000" const SPEECH_TO_TEXT_HOST = "http://appointment.lpaconsulting.fr:8000"
// const SPEECH_TO_TEXT_HOST = "http://127.0.0.1:8000" // const SPEECH_TO_TEXT_HOST = "http://127.0.0.1:8000"
function delay(delayInMs) { function delay(delayInMs) {
@@ -66,6 +67,17 @@ class GeoCaptchaSolver {
this.device = device; 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) { async solve(onResult) {
console.log(this.device.model() + ":solve() called.") console.log(this.device.model() + ":solve() called.")
console.log(this.device.model() + ":play audio") console.log(this.device.model() + ":play audio")
@@ -89,6 +101,9 @@ class GeoCaptchaSolver {
// console.log("selector is " + selector) // console.log("selector is " + selector)
try { try {
await iframeHandler.locator(selector).focus() await iframeHandler.locator(selector).focus()
if (i === 5) {
await this.clearLastDigit(iframeHandler)
}
await iframeHandler.locator(selector).fill("" + number_list[i - 1]) await iframeHandler.locator(selector).fill("" + number_list[i - 1])
} catch (e) { } catch (e) {
console.log(e) console.log(e)
@@ -100,7 +115,7 @@ class GeoCaptchaSolver {
try { try {
let content = await captcha_container.innerHTML() let content = await captcha_container.innerHTML()
console.log("inner container is " + content) console.log(this.device.model() + ":inner container is " + content)
try { try {
if (number_list.length === 0) { if (number_list.length === 0) {
onResult(false) onResult(false)
@@ -144,7 +159,7 @@ class GeoCaptchaSolver {
} }
async resetBrowser() { 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 this.device.shell("pm clear com.android.chrome")
await delay(1000) await delay(1000)
await this.device.shell("am set-debug-app --persistent com.android.chrome") await this.device.shell("am set-debug-app --persistent com.android.chrome")
+4 -1
View File
@@ -6,4 +6,7 @@ emulator -avd Pixel_2_API_30_4 &
emulator -avd Pixel_2_API_30_5 & emulator -avd Pixel_2_API_30_5 &
emulator -avd Pixel_2_API_30_6 & emulator -avd Pixel_2_API_30_6 &
emulator -avd Pixel_2_API_30_7 & emulator -avd Pixel_2_API_30_7 &
emulator -avd Pixel_2_API_30_8 & 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 &
+4
View File
@@ -0,0 +1,4 @@
emulator -avd Pixel_0 &
emulator -avd Pixel_1 &
emulator -avd Pixel_2 &
emulator -avd Pixel_3 &