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;
|
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"]
|
// device_to_excludes = ["47e7e36b", "e30eb015"]
|
||||||
|
device_to_excludes = ["47e7e36b"]
|
||||||
|
|
||||||
async function filterAlreadyBookedContacts(contactList) {
|
async function filterAlreadyBookedContacts(contactList) {
|
||||||
let alreadyBookedContacts = await mongoManager.getAllSuccessfulItemsForDay(collectionName);
|
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) {
|
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) => {
|
await duplicatedList.reduce(async (promise, contactPojo) => {
|
||||||
// This line will wait for the last async function to finish.
|
// This line will wait for the last async function to finish.
|
||||||
// The first iteration uses an already resolved Promise
|
// The first iteration uses an already resolved Promise
|
||||||
|
|||||||
@@ -182,7 +182,7 @@ class CommandorPage {
|
|||||||
if (!page.isClosed()) {
|
if (!page.isClosed()) {
|
||||||
if (!this.isPhoneInput) {
|
if (!this.isPhoneInput) {
|
||||||
await page.locator(PHONE_NUMBER).focus();
|
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;
|
this.isPhoneInput = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -391,8 +391,21 @@ class CommandorPage {
|
|||||||
//try to sliding capthca at first
|
//try to sliding capthca at first
|
||||||
let slidingCaptchaSolver = new SlidingCaptchaSolver(this.device);
|
let slidingCaptchaSolver = new SlidingCaptchaSolver(this.device);
|
||||||
await slidingCaptchaSolver.solve(this.page, async (isSuccessful) => {
|
await slidingCaptchaSolver.solve(this.page, async (isSuccessful) => {
|
||||||
|
console.log("check isAlwaysBlocked")
|
||||||
let isAlwaysBlocked = await this.isBlocked();
|
let isAlwaysBlocked = await this.isBlocked();
|
||||||
if (isAlwaysBlocked) {
|
if (isAlwaysBlocked) {
|
||||||
|
await this.resolveByAudio();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
log("audioBtn not found")
|
||||||
|
console.log("audioBtn not found")
|
||||||
|
console.log("we are blocked")
|
||||||
|
await this.resetBrowser()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async resolveByAudio() {
|
||||||
let audioBtn = await this.page.frameLocator("iframe").locator("#captcha__audio__button");
|
let audioBtn = await this.page.frameLocator("iframe").locator("#captcha__audio__button");
|
||||||
log("audioBtn found")
|
log("audioBtn found")
|
||||||
audioBtn.click()
|
audioBtn.click()
|
||||||
@@ -403,14 +416,6 @@ class CommandorPage {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
|
||||||
} else {
|
|
||||||
log("audioBtn not found")
|
|
||||||
console.log("audioBtn not found")
|
|
||||||
console.log("we are blocked")
|
|
||||||
await this.resetBrowser()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async onResponse(response) {
|
async onResponse(response) {
|
||||||
// let rex = new RegExp(REGEX_RDV_URL)
|
// let rex = new RegExp(REGEX_RDV_URL)
|
||||||
|
|||||||
@@ -40,43 +40,52 @@ class SlidingCaptchaSolver {
|
|||||||
|
|
||||||
async take_screen_shot(name, device) {
|
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() + " 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);
|
await delay(1000);
|
||||||
console.log(`stdout: ${stdout1}`);
|
// console.log(`stdout: ${stdout1}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async sliding_captcha(device, onResult) {
|
async sliding_captcha(device, onResult) {
|
||||||
// take screenshot
|
// take screenshot
|
||||||
|
console.log("take screenshot")
|
||||||
let blockedFileName = uuidv4();
|
let blockedFileName = uuidv4();
|
||||||
let blockedImageFileName = "blocked_" + blockedFileName
|
let blockedImageFileName = "blocked_" + blockedFileName + ".png"
|
||||||
await this.take_screen_shot(blockedImageFileName, device)
|
await this.take_screen_shot(blockedImageFileName, device)
|
||||||
//get resolution of screen
|
//get resolution of screen
|
||||||
let dimensions = await sizeOf(blockedImageFileName)
|
await this.sendRequest(blockedImageFileName, async (detectedPositionList) => {
|
||||||
console.log(dimensions.width, dimensions.height);
|
console.log("detectedPosition is " + detectedPositionList);
|
||||||
await this.sendRequest(blockedImageFileName, async (detectedPosition) => {
|
if (detectedPositionList.length === 2) {
|
||||||
console.log("detectedPosition is " + detectedPosition);
|
// #xiaomi
|
||||||
let startPosition = positionInfo.get(device.model())
|
let startPosition = detectedPositionList.filter((positionInfo) => {
|
||||||
if (startPosition === undefined) {
|
return positionInfo.label === "origin"
|
||||||
startPosition = new Position(210, dimensions.height * 0.7125)
|
})[0]
|
||||||
}
|
let targetPosition = detectedPositionList.filter((positionInfo) => {
|
||||||
|
return positionInfo.label === "target"
|
||||||
|
})[0]
|
||||||
if (startPosition !== undefined) {
|
if (startPosition !== undefined) {
|
||||||
let y0 = startPosition.y;
|
let y0 = (startPosition.y2 + startPosition.y1) / 2.0;
|
||||||
let x0 = startPosition.x;
|
let x0 = (startPosition.x2 + startPosition.x1) / 2.0;
|
||||||
let x1 = detectedPosition.x1;
|
let y1 = (targetPosition.y2 + targetPosition.y1) / 2.0;
|
||||||
let x2 = detectedPosition.x2;
|
let x1 = (targetPosition.x2 + targetPosition.x1) / 2.0;
|
||||||
let width = x2 - detectedPosition.x1;
|
let width = targetPosition.x2 - targetPosition.x1;
|
||||||
let randomTime = randomIntFromInterval(100, 500)
|
let randomTime = randomIntFromInterval(100, 500)
|
||||||
let cmd = `adb -s ${device.serial()} shell input swipe ${x0} ${y0} ${x1 + width * 0.8} ${y0} ${1000 + randomTime}`
|
let cmd = `adb -s ${device.serial()} shell input swipe ${x0} ${y0} ${x1 + width * 0.5} ${y0} ${1000 + randomTime}`
|
||||||
await delay(2000);
|
await delay(2000);
|
||||||
console.log("cmd is " + cmd);
|
console.log("cmd is " + cmd);
|
||||||
console.log("will slide captcha");
|
console.log("will slide captcha");
|
||||||
await exec(cmd);
|
await exec(cmd);
|
||||||
await delay(3000);
|
await delay(5000);
|
||||||
onResult(true);
|
onResult(true)
|
||||||
} else {
|
} else {
|
||||||
console.log("startPosition not found for " + device.model())
|
console.log("startPosition not found for " + device.model())
|
||||||
onResult(false);
|
onResult(false)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.log("startPosition not found for " + device.model())
|
||||||
|
onResult(false)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -89,7 +98,7 @@ class SlidingCaptchaSolver {
|
|||||||
'Content-Type': 'wav',
|
'Content-Type': 'wav',
|
||||||
'Authorization': 'Bearer 97e36f7e-340e-4c02-b329-9415faee38c3'
|
'Authorization': 'Bearer 97e36f7e-340e-4c02-b329-9415faee38c3'
|
||||||
},
|
},
|
||||||
timeout: 90 * 1000
|
timeout: 30 * 1000
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
console.log(err.code);
|
console.log(err.code);
|
||||||
console.log(err.stack);
|
console.log(err.stack);
|
||||||
@@ -111,8 +120,7 @@ class SlidingCaptchaSolver {
|
|||||||
// })
|
// })
|
||||||
} else {
|
} else {
|
||||||
console.log("error");
|
console.log("error");
|
||||||
await callback({});
|
await callback([]);
|
||||||
console.log("will delete wav file: " + fileName);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user