do not duplicate contacts
This commit is contained in:
+4
-2
@@ -10,7 +10,8 @@ const SEVEN_DAYS_IN_S = 3600 * 24 * 7;
|
||||
const NINETY_DAYS_IN_S = 3600 * 24 * 30 * 3;
|
||||
let excelUtil = new ExcelUtil();
|
||||
let collectionName = formatDate(new Date())
|
||||
device_to_excludes = ["47e7e36b", "e30eb015"]
|
||||
// device_to_excludes = ["47e7e36b", "e30eb015"]
|
||||
device_to_excludes = ["47e7e36b"]
|
||||
|
||||
async function filterAlreadyBookedContacts(contactList) {
|
||||
let alreadyBookedContacts = await mongoManager.getAllSuccessfulItemsForDay(collectionName);
|
||||
@@ -123,7 +124,8 @@ async function startBook(contactPojo, device, selectedStore, audioAnalyse, alert
|
||||
}
|
||||
|
||||
async function startWithList(contacts, device, selectedStore, audioAnalyse, alertBeep) {
|
||||
let duplicatedList = [].concat(contacts).concat(contacts).concat(contacts)
|
||||
// let duplicatedList = [].concat(contacts).concat(contacts).concat(contacts)
|
||||
let duplicatedList = [].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
|
||||
|
||||
@@ -182,7 +182,7 @@ class CommandorPage {
|
||||
if (!page.isClosed()) {
|
||||
if (!this.isPhoneInput) {
|
||||
await page.locator(PHONE_NUMBER).focus();
|
||||
await page.locator(PHONE_NUMBER).fill("0" + this.contact.phoneNumber);
|
||||
await page.locator(PHONE_NUMBER).fill("+330" + this.contact.phoneNumber);
|
||||
this.isPhoneInput = true;
|
||||
}
|
||||
}
|
||||
@@ -391,17 +391,10 @@ class CommandorPage {
|
||||
//try to sliding capthca at first
|
||||
let slidingCaptchaSolver = new SlidingCaptchaSolver(this.device);
|
||||
await slidingCaptchaSolver.solve(this.page, async (isSuccessful) => {
|
||||
console.log("check isAlwaysBlocked")
|
||||
let isAlwaysBlocked = await this.isBlocked();
|
||||
if (isAlwaysBlocked) {
|
||||
let audioBtn = await this.page.frameLocator("iframe").locator("#captcha__audio__button");
|
||||
log("audioBtn found")
|
||||
audioBtn.click()
|
||||
let captchaSolver = new GeoCaptchaSolver(this.page, this.device, this.isTerminated)
|
||||
await captchaSolver.solve((isSuccessful) => {
|
||||
if (!isSuccessful) {
|
||||
this.isTerminated = true
|
||||
}
|
||||
})
|
||||
await this.resolveByAudio();
|
||||
}
|
||||
})
|
||||
} else {
|
||||
@@ -412,6 +405,18 @@ class CommandorPage {
|
||||
}
|
||||
}
|
||||
|
||||
async resolveByAudio() {
|
||||
let audioBtn = await this.page.frameLocator("iframe").locator("#captcha__audio__button");
|
||||
log("audioBtn found")
|
||||
audioBtn.click()
|
||||
let captchaSolver = new GeoCaptchaSolver(this.page, this.device, this.isTerminated)
|
||||
await captchaSolver.solve((isSuccessful) => {
|
||||
if (!isSuccessful) {
|
||||
this.isTerminated = true
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
async onResponse(response) {
|
||||
// let rex = new RegExp(REGEX_RDV_URL)
|
||||
// log("onResponse with url:" + response.url())
|
||||
|
||||
@@ -40,43 +40,52 @@ class SlidingCaptchaSolver {
|
||||
|
||||
async take_screen_shot(name, device) {
|
||||
// let stdout1 = await exec("adb -s " + device.serial() + " shell screencap -p /sdcard/" + name)
|
||||
let stdout1 = await exec("adb -s " + device.serial() + " exec-out screencap -p > " + name)
|
||||
console.log("take screenshot " + name);
|
||||
await device.screenshot({path: name});
|
||||
// let stdout1 = await exec("adb -s " + device.serial() + " exec-out screencap -p > " + name)
|
||||
await delay(1000);
|
||||
console.log(`stdout: ${stdout1}`);
|
||||
// console.log(`stdout: ${stdout1}`);
|
||||
}
|
||||
|
||||
|
||||
async sliding_captcha(device, onResult) {
|
||||
// take screenshot
|
||||
console.log("take screenshot")
|
||||
let blockedFileName = uuidv4();
|
||||
let blockedImageFileName = "blocked_" + blockedFileName
|
||||
let blockedImageFileName = "blocked_" + blockedFileName + ".png"
|
||||
await this.take_screen_shot(blockedImageFileName, device)
|
||||
//get resolution of screen
|
||||
let dimensions = await sizeOf(blockedImageFileName)
|
||||
console.log(dimensions.width, dimensions.height);
|
||||
await this.sendRequest(blockedImageFileName, async (detectedPosition) => {
|
||||
console.log("detectedPosition is " + detectedPosition);
|
||||
let startPosition = positionInfo.get(device.model())
|
||||
if (startPosition === undefined) {
|
||||
startPosition = new Position(210, dimensions.height * 0.7125)
|
||||
}
|
||||
if (startPosition !== undefined) {
|
||||
let y0 = startPosition.y;
|
||||
let x0 = startPosition.x;
|
||||
let x1 = detectedPosition.x1;
|
||||
let x2 = detectedPosition.x2;
|
||||
let width = x2 - detectedPosition.x1;
|
||||
let randomTime = randomIntFromInterval(100, 500)
|
||||
let cmd = `adb -s ${device.serial()} shell input swipe ${x0} ${y0} ${x1 + width * 0.8} ${y0} ${1000 + randomTime}`
|
||||
await delay(2000);
|
||||
console.log("cmd is " + cmd);
|
||||
console.log("will slide captcha");
|
||||
await exec(cmd);
|
||||
await delay(3000);
|
||||
onResult(true);
|
||||
await this.sendRequest(blockedImageFileName, async (detectedPositionList) => {
|
||||
console.log("detectedPosition is " + detectedPositionList);
|
||||
if (detectedPositionList.length === 2) {
|
||||
// #xiaomi
|
||||
let startPosition = detectedPositionList.filter((positionInfo) => {
|
||||
return positionInfo.label === "origin"
|
||||
})[0]
|
||||
let targetPosition = detectedPositionList.filter((positionInfo) => {
|
||||
return positionInfo.label === "target"
|
||||
})[0]
|
||||
if (startPosition !== undefined) {
|
||||
let y0 = (startPosition.y2 + startPosition.y1) / 2.0;
|
||||
let x0 = (startPosition.x2 + startPosition.x1) / 2.0;
|
||||
let y1 = (targetPosition.y2 + targetPosition.y1) / 2.0;
|
||||
let x1 = (targetPosition.x2 + targetPosition.x1) / 2.0;
|
||||
let width = targetPosition.x2 - targetPosition.x1;
|
||||
let randomTime = randomIntFromInterval(100, 500)
|
||||
let cmd = `adb -s ${device.serial()} shell input swipe ${x0} ${y0} ${x1 + width * 0.5} ${y0} ${1000 + randomTime}`
|
||||
await delay(2000);
|
||||
console.log("cmd is " + cmd);
|
||||
console.log("will slide captcha");
|
||||
await exec(cmd);
|
||||
await delay(5000);
|
||||
onResult(true)
|
||||
} else {
|
||||
console.log("startPosition not found for " + device.model())
|
||||
onResult(false)
|
||||
}
|
||||
} else {
|
||||
console.log("startPosition not found for " + device.model())
|
||||
onResult(false);
|
||||
onResult(false)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -89,7 +98,7 @@ class SlidingCaptchaSolver {
|
||||
'Content-Type': 'wav',
|
||||
'Authorization': 'Bearer 97e36f7e-340e-4c02-b329-9415faee38c3'
|
||||
},
|
||||
timeout: 90 * 1000
|
||||
timeout: 30 * 1000
|
||||
}).catch(err => {
|
||||
console.log(err.code);
|
||||
console.log(err.stack);
|
||||
@@ -111,8 +120,7 @@ class SlidingCaptchaSolver {
|
||||
// })
|
||||
} else {
|
||||
console.log("error");
|
||||
await callback({});
|
||||
console.log("will delete wav file: " + fileName);
|
||||
await callback([]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user