Merge branch 'feature/share_cookies'
This commit is contained in:
+2
-1
@@ -12,6 +12,7 @@
|
||||
"dependencies": {
|
||||
"@nodegui/nodegui": "^0.57.1",
|
||||
"alert": "^5.1.1",
|
||||
"amqplib": "^0.10.3",
|
||||
"axios": "^0.27.2",
|
||||
"jimp": "^0.22.8",
|
||||
"mongodb": "^4.9.1",
|
||||
@@ -21,7 +22,7 @@
|
||||
"node-wget": "^0.4.3",
|
||||
"node-xlsx": "^0.21.0",
|
||||
"playwright": "^1.39.0",
|
||||
"puppeteer": "^15.5.0",
|
||||
"puppeteer": "^15.2.0",
|
||||
"read-ini-file": "^3.0.1",
|
||||
"uuid": "^9.0.0",
|
||||
"winston": "^3.8.2",
|
||||
|
||||
+56
-44
@@ -5,19 +5,20 @@ const {MongoManager, formatDate} = require("./workers/mongo_manager");
|
||||
const alert = require('alert');
|
||||
const schedule = require("node-schedule");
|
||||
const DeviceExcludeMode = require("./models/DeviceExcludeMode");
|
||||
const Sender = require("./queue/Sender");
|
||||
const mongoManager = new MongoManager();
|
||||
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;
|
||||
const NINETY_DAYS_IN_S = 30 * 3;
|
||||
let excelUtil = new ExcelUtil();
|
||||
let collectionName = formatDate(new Date())
|
||||
let excludeMode = DeviceExcludeMode.SIX
|
||||
let three_to_excludes = ["bec11752", "4e8ca027", "hi7ljr5xduyt9pfi", "EPHUT20825001518"]
|
||||
let four_to_excludes = ["bec11752", "4e8ca027", "hi7ljr5xduyt9pfi", "e30eb015", "EPHUT20825001518"]
|
||||
let seven_to_excludes = ["4e8ca027", "hi7ljr5xduyt9pfi", "e30eb015", "EPHUT20825001518", "bec11752", "fy65eqs4wkvcpf9h", "fuljaueqguugf6pn", "EPHUT20825001518"]
|
||||
let six_to_excludes = ["4e8ca027", "hi7ljr5xduyt9pfi", "e30eb015", "EPHUT20825001518", "bec11752", "fy65eqs4wkvcpf9h", "07fbd156", "NFD669QK8XNFSCNN", "6X494TTWQGFALB79","71a0371d"]
|
||||
let nine_to_excludes = ["bec11752", "4e8ca027", "hi7ljr5xduyt9pfi", "e30eb015", "47e7e36b", "p7d6nbw8cu7duous", "njzxojhim7gedyvw", "fmiz5pa6rsx4u4ts", "fy65eqs4wkvcpf9h", "fuljaueqguugf6pn", "EPHUT20825001518", "W8GMFELRHIKZS84T"]
|
||||
let for_scrpay = ["07fbd156", "47e7e36b", "4f55c3d4", "5ac879a2", "69db59f0", "71a0371d", "774687ff", "7b71fb20", "8f76f9e7", "99cyfiaebqcy6poj", "EPHUT20825001518", "J4AXB761H2322WJ", "W8GMFELRHIKZS84T", "ai9xv8hy599hvkee", "b41c1b72", "bec11752", "becb6e99", "c3ba032e", "d54e946", "e30eb015", "fmiz5pa6rsx4u4ts", "fuljaueqguugf6pn", "fy65eqs4wkvcpf9h", "hi7ljr5xduyt9pfi", "njzxojhim7gedyvw", "p7d6nbw8cu7duous"]
|
||||
let four_to_excludes = ["bec11752", "4e8ca027", "hi7ljr5xduyt9pfi", "EPHUT20825001518"]
|
||||
let seven_to_excludes = ["4e8ca027", "hi7ljr5xduyt9pfi", "EPHUT20825001518", "bec11752", "fuljaueqguugf6pn", "EPHUT20825001518"]
|
||||
let six_to_excludes = ["4e8ca027", "hi7ljr5xduyt9pfi", "EPHUT20825001518", "bec11752", "07fbd156", "NFD669QK8XNFSCNN", "6X494TTWQGFALB79", "71a0371d", "YP6HVKLFE67T598L"]
|
||||
let nine_to_excludes = ["bec11752", "4e8ca027", "hi7ljr5xduyt9pfi", "47e7e36b", "p7d6nbw8cu7duous", "njzxojhim7gedyvw", "fmiz5pa6rsx4u4ts", "fuljaueqguugf6pn", "EPHUT20825001518", "W8GMFELRHIKZS84T"]
|
||||
let for_scrpay = ["07fbd156", "47e7e36b", "4f55c3d4", "5ac879a2", "69db59f0", "71a0371d", "774687ff", "7b71fb20", "8f76f9e7", "99cyfiaebqcy6poj", "EPHUT20825001518", "J4AXB761H2322WJ", "W8GMFELRHIKZS84T", "ai9xv8hy599hvkee", "b41c1b72", "bec11752", "becb6e99", "c3ba032e", "d54e946", "fmiz5pa6rsx4u4ts", "fuljaueqguugf6pn", "fy65eqs4wkvcpf9h", "hi7ljr5xduyt9pfi", "njzxojhim7gedyvw", "p7d6nbw8cu7duous"]
|
||||
attributedPorts = []
|
||||
const device_port_info = new Map();
|
||||
startPort = 9000
|
||||
@@ -121,12 +122,18 @@ async function needToBook(contact, mongoManager, alreadyBooked) {
|
||||
return needToBook
|
||||
}
|
||||
|
||||
async function startBook(contactPojo, device, selectedStore, audioAnalyse, alertBeep, port) {
|
||||
async function startBook(contactPojo, device, sender, selectedStore, audioAnalyse, alertBeep, port) {
|
||||
console.log(`model: ${device.model()}`);
|
||||
console.log(`serial: ${device.serial()}`);
|
||||
let alreadyBooked = await mongoManager.getAllSuccessfulItemsForDay(collectionName);
|
||||
const d = new Date();
|
||||
let hour = d.getHours();
|
||||
if (hour >= 19) {
|
||||
console.log("do not continue after 19h")
|
||||
return
|
||||
}
|
||||
if (await needToBook(contactPojo, mongoManager, alreadyBooked)) {
|
||||
let commandor = new CommandorPage(contactPojo, device, mongoManager, selectedStore, audioAnalyse, alertBeep, port);
|
||||
let commandor = new CommandorPage(contactPojo, device, sender, mongoManager, selectedStore, audioAnalyse, alertBeep, port);
|
||||
//read contacts form excel
|
||||
return await commandor.loadPage();
|
||||
} else {
|
||||
@@ -134,14 +141,14 @@ async function startBook(contactPojo, device, selectedStore, audioAnalyse, alert
|
||||
}
|
||||
}
|
||||
|
||||
async function startWithList(contacts, device, selectedStore, audioAnalyse, alertBeep, port) {
|
||||
async function startWithList(contacts, device, sender, selectedStore, audioAnalyse, 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, selectedStore, audioAnalyse, alertBeep, port);
|
||||
const contents = await startBook(contactPojo, device, sender, selectedStore, audioAnalyse, alertBeep, port);
|
||||
console.log(contents);
|
||||
}, Promise.resolve());
|
||||
}
|
||||
@@ -207,41 +214,46 @@ async function startBookWithNumbers(startNumber, endNumber, selectedStore, pathT
|
||||
return attributedPort
|
||||
}
|
||||
|
||||
mongoManager.connect().then(r => {
|
||||
filterAlreadyBookedContacts(contactList).then((listToBook) => {
|
||||
filterAlreadyAcceptedContacts(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 device_to_excludes = three_to_excludes;
|
||||
if (excludeMode === DeviceExcludeMode.FOUR) {
|
||||
device_to_excludes = four_to_excludes;
|
||||
} else if (excludeMode === DeviceExcludeMode.NINE) {
|
||||
device_to_excludes = nine_to_excludes;
|
||||
} else if (excludeMode === DeviceExcludeMode.SEVEN) {
|
||||
device_to_excludes = seven_to_excludes
|
||||
} else if (excludeMode === DeviceExcludeMode.SIX) {
|
||||
device_to_excludes = six_to_excludes
|
||||
}
|
||||
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++) {
|
||||
let device = filteredDeviceList[i];
|
||||
let port = startForwordingForDevice(device)
|
||||
startWithList(listWithoutBlackContact.slice(i * segmentNumber, segmentNumber * (i + 1)), device, selectedStore, audioAnalyse, alertBeep, port);
|
||||
}
|
||||
let sender = new Sender()
|
||||
sender.initConnection().then((r) => {
|
||||
console.log("queue connected")
|
||||
mongoManager.connect().then(r => {
|
||||
filterAlreadyBookedContacts(contactList).then((listToBook) => {
|
||||
filterAlreadyAcceptedContacts(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 device_to_excludes = three_to_excludes;
|
||||
if (excludeMode === DeviceExcludeMode.FOUR) {
|
||||
device_to_excludes = four_to_excludes;
|
||||
} else if (excludeMode === DeviceExcludeMode.NINE) {
|
||||
device_to_excludes = nine_to_excludes;
|
||||
} else if (excludeMode === DeviceExcludeMode.SEVEN) {
|
||||
device_to_excludes = seven_to_excludes
|
||||
} else if (excludeMode === DeviceExcludeMode.SIX) {
|
||||
device_to_excludes = six_to_excludes
|
||||
}
|
||||
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++) {
|
||||
let device = filteredDeviceList[i];
|
||||
let port = startForwordingForDevice(device)
|
||||
startWithList(listWithoutBlackContact.slice(i * segmentNumber, segmentNumber * (i + 1)), device, sender, selectedStore, audioAnalyse, alertBeep, port);
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
)
|
||||
})
|
||||
});
|
||||
}
|
||||
)
|
||||
})
|
||||
});
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
module.exports = {startBookWithNumbers, scheduleBookWithNumbers}
|
||||
@@ -19,7 +19,11 @@ class ExcelUtil {
|
||||
if (store === undefined || store.length === 0) {
|
||||
store = "random"
|
||||
}
|
||||
let newContact = new ContactPojo(phoneNumber, passportNumber, lastName, firstName, mail, store);
|
||||
let ipCountry = info[5];
|
||||
if (ipCountry === undefined || ipCountry.length === 0) {
|
||||
ipCountry = "FR"
|
||||
}
|
||||
let newContact = new ContactPojo(phoneNumber, passportNumber, lastName, firstName, mail, store, ipCountry);
|
||||
contactList.push(newContact);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
class ContactPojo {
|
||||
|
||||
constructor(phoneNumber, passportNumber, lastName, firstName, mail, store) {
|
||||
constructor(phoneNumber, passportNumber, lastName, firstName, mail, store, ipCountry) {
|
||||
this.phoneNumber = phoneNumber;
|
||||
this.passportNumber = passportNumber;
|
||||
this.lastName = lastName;
|
||||
this.firstName = firstName;
|
||||
this.mail = mail;
|
||||
this.store = store;
|
||||
this.ipCountry = ipCountry;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
module.exports = ContactPojo
|
||||
@@ -3,6 +3,8 @@ const OCRResult = {
|
||||
TO_REFRESH: Symbol("TO_REFRESH"),
|
||||
BLOCKED: Symbol("BLOCKED"),
|
||||
SLIDING_CAPTCHA: Symbol("SLIDING_CAPTCHA"),
|
||||
SSL_CERT_ERROR: Symbol("SSL_CERT_ERROR"),
|
||||
SLIDING_CAPTCHA_LOADING: Symbol("SLIDING_CAPTCHA_LOADING"),
|
||||
SLIDING_CAPTCHA_REFRESH: Symbol("SLIDING_CAPTCHA_REFRESH"),
|
||||
FILL_FIELD: Symbol("FILL_FIELD"),
|
||||
NEED_TO_CLICK_LATE_BTN: Symbol("NEED_TO_CLICK_LATE_BTN"),
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
const amqp = require("amqplib");
|
||||
|
||||
const QUEUE_HOST = "amqp://appointment:ZyuhJZ2xEYWhElhpJjy7YEpZGZwNYJz2fHIu@appointment.lpaconsulting.fr:5672"
|
||||
const REQUEST_DATA_QUEUE_FR = 'REQUEST_DATA';
|
||||
const REQUEST_DATA_QUEUE_DE = 'REQUEST_DATA_DE';
|
||||
|
||||
class Sender {
|
||||
channel;
|
||||
connection;
|
||||
|
||||
async initConnection() {
|
||||
this.connection = await amqp.connect(QUEUE_HOST);
|
||||
this.channel = await this.connection.createChannel();
|
||||
await this.channel.assertQueue(REQUEST_DATA_QUEUE_FR, {persistent: true});
|
||||
}
|
||||
|
||||
sendMessage(msg, queue_name = REQUEST_DATA_QUEUE_FR) {
|
||||
this.channel.sendToQueue(queue_name, Buffer.from(msg))
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Sender
|
||||
|
||||
// let sender = new Sender()
|
||||
// sender.initConnection().then((r) => {
|
||||
// console.log(r)
|
||||
// sender.sendMessage("test")
|
||||
// })
|
||||
+126
-113
@@ -32,8 +32,8 @@ const MESSAGE_URL_VALIDATION_FR = "Nous avons envoyé un lien par e-mail."
|
||||
const MESSAGE_URL_VALIDATION_EN = "Please click on the link we sent by email"
|
||||
const REGEX_RDV_URL = "https:\/\/rendezvousparis\.hermes\.com\/client\/register\/[A-Z0-9]+"
|
||||
const DEFAULT_STORE = 'faubourg';
|
||||
|
||||
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']
|
||||
const timeout = (prom, time) =>
|
||||
Promise.race([prom, new Promise((_r, rej) => setTimeout(rej, time))]);
|
||||
|
||||
function delay(delayInMs) {
|
||||
return new Promise(resolve => {
|
||||
@@ -72,13 +72,14 @@ function logWithDevice(message, device) {
|
||||
}
|
||||
|
||||
class CommandorPage {
|
||||
constructor(contact, device, mongoManager, selectedStore = DEFAULT_STORE, audioAnalyse = false, alertBeep = false, port = 9000) {
|
||||
constructor(contact, device, sender, mongoManager, selectedStore = DEFAULT_STORE, audioAnalyse = false, alertBeep = false, port = 9000) {
|
||||
this.contact = contact;
|
||||
this.device = device;
|
||||
this.mongoManager = mongoManager;
|
||||
this.selectedStore = selectedStore;
|
||||
this.choosedStore = selectedStore;
|
||||
this.port = port;
|
||||
this.sender = sender;
|
||||
this.ocrChecker = new OCRChecker(this.device, this.contact);
|
||||
this.browserPackageName = "com.brave.browser";
|
||||
// this.browserPackageName = "com.android.chrome";
|
||||
@@ -92,31 +93,6 @@ class CommandorPage {
|
||||
this.firstStart = true;
|
||||
}
|
||||
|
||||
async getActivePage(browser, timeout) {
|
||||
const start = new Date().getTime();
|
||||
while (new Date().getTime() - start < timeout) {
|
||||
logWithDevice("get pages", this.device)
|
||||
let pages = await browser.pages();
|
||||
try {
|
||||
pages.forEach((currentPage) => {
|
||||
if (currentPage.url() === RDV_URL) {
|
||||
return currentPage;
|
||||
} else {
|
||||
try {
|
||||
currentPage.close()
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
}
|
||||
}
|
||||
})
|
||||
} catch (e) {
|
||||
this.isTerminated = true;
|
||||
console.log(e)
|
||||
}
|
||||
}
|
||||
throw "Unable to get active page";
|
||||
}
|
||||
|
||||
async connect_to_browser(ocrResult) {
|
||||
console.log("connect_to_browser() called");
|
||||
if (this.browser === undefined) {
|
||||
@@ -193,19 +169,17 @@ class CommandorPage {
|
||||
await this.enableDisableAirPlanMode();
|
||||
// await delay(10 * 1000);
|
||||
await openUrlWithAdb(RDV_URL, this.device)
|
||||
await delay(5000)
|
||||
await delay(10 * 1000)
|
||||
await this.checkResultWithOcr()
|
||||
// await this.clickOnlineAppointment();
|
||||
// } else {
|
||||
// this.isTerminated = true;
|
||||
// }
|
||||
|
||||
let cancel
|
||||
const intervalTask = setInterval(async () => {
|
||||
if (this.isTerminated) {
|
||||
log(this.device.model() + ":request terminated, send cancel()");
|
||||
try {
|
||||
await this.page.close()
|
||||
if (this.page !== undefined) {
|
||||
await this.page.close()
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
}
|
||||
@@ -698,10 +672,10 @@ class CommandorPage {
|
||||
|
||||
async slidingCaptcha(onResult) {
|
||||
logWithDevice("slidingCaptcha", this.device);
|
||||
if (this.device.model() === "MI 5s" || this.device.model() === "ASUS_X00QD") {
|
||||
if (this.device.model() === "MI 5s" || this.device.model() === "ASUS_X00QD" || this.device.model() === "ASUS_Z012D" || this.device.model() === "HUAWEI NXT-TL00") {
|
||||
let cmd = `adb -s ${this.device.serial()} shell input touchscreen swipe 900 495 900 195`
|
||||
await exec(cmd);
|
||||
await delay(1000);
|
||||
await delay(5000);
|
||||
}
|
||||
let slidingCaptchaSolver = new SlidingCaptchaSolver(this.device);
|
||||
await slidingCaptchaSolver.solve(this.page, async (isSuccessful) => {
|
||||
@@ -742,31 +716,22 @@ class CommandorPage {
|
||||
let reserve = ReserveResultPojo.create_from_contact(this.contact, id, url, this.choosedStore, publishType);
|
||||
reserve.source_from = this.device.model();
|
||||
await this.mongoManager.saveReserveToDb(reserve.to_mongo_dict())
|
||||
await this.page.close();
|
||||
if (!this.page.isClosed()) {
|
||||
try {
|
||||
await this.page.close();
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
}
|
||||
}
|
||||
// await this.deleteFromBlackList()
|
||||
// await this.resetBrowser()
|
||||
this.isTerminated = true
|
||||
}
|
||||
|
||||
async deleteFromBlackList() {
|
||||
await this.mongoManager.removeFromBlackList(this.contact)
|
||||
}
|
||||
|
||||
async getErrors() {
|
||||
logWithDevice("getErrors", this.device);
|
||||
await this.checkResultWithOcr();
|
||||
if (this.page.url() === BLANK_URL) {
|
||||
this.isTerminated = true;
|
||||
} else {
|
||||
try {
|
||||
// let errorItem = this.page.locator("div.alert");
|
||||
// if (errorItem) {
|
||||
// let errorContent = await errorItem.innerHTML();
|
||||
// await this.handleError(errorContent);
|
||||
// }
|
||||
} catch (e) {
|
||||
log(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -788,7 +753,7 @@ class CommandorPage {
|
||||
logWithDevice("resetBrowser", this.device);
|
||||
this.isFillingFields = false;
|
||||
this.cguChecked = false;
|
||||
this.isNameInput = false;
|
||||
this.isNameInputing = false;
|
||||
this.isEmailFilled = false;
|
||||
this.isCountryChoosen = false;
|
||||
this.isPhoneInput = false;
|
||||
@@ -826,7 +791,6 @@ class CommandorPage {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async checkResultWithOcr() {
|
||||
logWithDevice("checkResultWithOcr() called.", this.device)
|
||||
if (this.device.model() === "M2006C3LG")
|
||||
@@ -843,18 +807,30 @@ class CommandorPage {
|
||||
checkResult = await this.ocrChecker.get_result();
|
||||
}
|
||||
while (checkResult === OCRResult.SLIDING_CAPTCHA) {
|
||||
logWithDevice("will call this.slidingCaptcha()", this.device)
|
||||
await this.slidingCaptcha(async (isSuccessful) => {
|
||||
logWithDevice("SLIDING_CAPTCHA result is " + isSuccessful, this.device)
|
||||
console.log(checkResult);
|
||||
if (isSuccessful) {
|
||||
checkResult = await this.ocrChecker.get_result();
|
||||
await delay(5 * 1000)
|
||||
// checkResult = await this.ocrChecker.get_result();
|
||||
await this.checkResultWithOcr()
|
||||
} else {
|
||||
checkResult = OCRResult.TERMINAED
|
||||
this.isTerminated = true
|
||||
if (checkResult === OCRResult.SLIDING_CAPTCHA) {
|
||||
checkResult = OCRResult.TERMINAED
|
||||
this.isTerminated = true
|
||||
}
|
||||
}
|
||||
})
|
||||
await delay(10 * 1000)
|
||||
}
|
||||
switch (checkResult) {
|
||||
case OCRResult.SLIDING_CAPTCHA_LOADING:
|
||||
this.isTerminated = true;
|
||||
break;
|
||||
case OCRResult.SSL_CERT_ERROR:
|
||||
await this.resetBrowser()
|
||||
break;
|
||||
case OCRResult.TERMINAED:
|
||||
this.isTerminated = true;
|
||||
break;
|
||||
@@ -870,29 +846,74 @@ class CommandorPage {
|
||||
browserWSEndpoint: "ws://127.0.0.1:" + this.port + "/devtools/browser",
|
||||
headless: false, defaultViewport: null
|
||||
})
|
||||
logWithDevice("get pages", this.device)
|
||||
let pages = await this.browser.pages();
|
||||
|
||||
try {
|
||||
logWithDevice("get pages", this.device)
|
||||
// add listeners
|
||||
let pages = await timeout(this.browser.pages(), 5 * 1000);
|
||||
pages.forEach((currentPage) => {
|
||||
if (currentPage.url() === RDV_URL) {
|
||||
this.page = currentPage;
|
||||
} else {
|
||||
try {
|
||||
currentPage.close()
|
||||
if (!this.isTerminated)
|
||||
currentPage.close()
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
}
|
||||
}
|
||||
})
|
||||
} catch (e) {
|
||||
this.isTerminated = true;
|
||||
console.log(e)
|
||||
}
|
||||
logWithDevice("this.page.bringToFront();", this.device)
|
||||
logWithDevice("this.page.bringToFront();", this.device)
|
||||
const cookiesSet = await this.page.cookies();
|
||||
let cookiesString = ""
|
||||
cookiesSet.forEach((cookie) => {
|
||||
cookiesString = cookiesString + cookie.name + "=" + cookie.value + ";"
|
||||
})
|
||||
console.log(cookiesString);
|
||||
|
||||
if (this.contact.ipCountry === "DE")
|
||||
this.sender.sendMessage(cookiesString, "REQUEST_DATA_DE")
|
||||
else
|
||||
this.sender.sendMessage(cookiesString)
|
||||
// let content = await this.page.content()
|
||||
// console.log(content)
|
||||
await this.page.bringToFront();
|
||||
await this.fillFields(this.page)
|
||||
await delay(2 * 1000);
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
await this.resetBrowser()
|
||||
// this.isTerminated = true;
|
||||
}
|
||||
// try {
|
||||
// for (const currentPage of pages) {
|
||||
// if (currentPage.url() === RDV_URL) {
|
||||
// logWithDevice("get content", this.device)
|
||||
// let pageContent = await currentPage.content()
|
||||
// logWithDevice("content:" + pageContent, this.device)
|
||||
// if (!pageContent.includes("geo.captcha-delivery.com")) {
|
||||
// this.page = currentPage;
|
||||
// break
|
||||
// } else {
|
||||
// try {
|
||||
// await currentPage.close()
|
||||
// } catch (e) {
|
||||
// console.log(e)
|
||||
// }
|
||||
// }
|
||||
// } else {
|
||||
// try {
|
||||
// await currentPage.close()
|
||||
// } catch (e) {
|
||||
// console.log(e)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// } catch (e) {
|
||||
// this.isTerminated = true;
|
||||
// console.log(e)
|
||||
// }
|
||||
|
||||
await this.page.bringToFront();
|
||||
await this.fillFields(this.page)
|
||||
await delay(2 * 1000);
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
this.isTerminated = true
|
||||
@@ -901,27 +922,7 @@ class CommandorPage {
|
||||
logWithDevice("this.browser.isConnected() is " + this.browser.isConnected(), this.device)
|
||||
try {
|
||||
if (this.browser.isConnected()) {
|
||||
// logWithDevice("get pages", this.device)
|
||||
// let pages = await this.browser.pages();
|
||||
logWithDevice("will use old page", this.device)
|
||||
// try {
|
||||
// pages.forEach((currentPage) => {
|
||||
// if (currentPage.url() === RDV_URL) {
|
||||
// this.page = currentPage;
|
||||
// } else {
|
||||
// // try {
|
||||
// // if (!currentPage.isClosed()) {
|
||||
// // currentPage.close()
|
||||
// // }
|
||||
// // } catch (e) {
|
||||
// // console.log(e)
|
||||
// // }
|
||||
// }
|
||||
// })
|
||||
// } catch (e) {
|
||||
// this.isTerminated = true
|
||||
// console.log(e)
|
||||
// }
|
||||
logWithDevice("this.page.bringToFront();", this.device)
|
||||
await this.page.bringToFront();
|
||||
// this.page = pages;
|
||||
@@ -951,12 +952,7 @@ class CommandorPage {
|
||||
break;
|
||||
case
|
||||
OCRResult.RECAPTCHA_ERROR:
|
||||
// if (!this.isFillingFields)
|
||||
this.isTerminated = true;
|
||||
// else {
|
||||
// await this.checkResultWithOcr();
|
||||
// }
|
||||
// await this.connect_to_browser(OCRResult.RECAPTCHA_ERROR)
|
||||
break;
|
||||
case
|
||||
OCRResult.BRAVE_SKIP:
|
||||
@@ -964,12 +960,17 @@ class CommandorPage {
|
||||
await this.checkResultWithOcr();
|
||||
break;
|
||||
case OCRResult.BRAVE_PRIVACY:
|
||||
if (this.device.model() === "MI 5s") {
|
||||
let model = this.device.model()
|
||||
if (model === "MI 5s" || this.device.model() === "SM-G965U1" || this.device.model() === "ASUS_Z012D") {
|
||||
await this.tapForDevice(this.device, 530, 970)
|
||||
} else if (model === "HUAWEI NXT-TL00") {
|
||||
await this.tapForDevice(this.device, 530, 950)
|
||||
} else if (this.device.model() === "ONEPLUS A6000") {
|
||||
await this.device.shell("input tap " + 530 + " " + 1064)
|
||||
await this.tapForDevice(this.device, 530, 1064)
|
||||
} else if (this.device.model() === "moto g51 5G") {
|
||||
await this.tapForDevice(this.device, 500, 1080)
|
||||
} else if (this.device.model() === "CPH2469") {
|
||||
await this.tapForDevice(this.device, 360, 820)
|
||||
} else if (this.device.model() === "M2006C3LG" || this.device.model() === "220233L2G") {
|
||||
await this.tapForDevice(this.device, 350, 777)
|
||||
} else if (this.device.model() === "KB2003" || this.device.model() === "DE2117") {
|
||||
@@ -986,8 +987,10 @@ class CommandorPage {
|
||||
await this.checkResultWithOcr();
|
||||
break;
|
||||
case OCRResult.BRAVE_PRIVACY_PUB:
|
||||
if (this.device.model() === "MI 5s") {
|
||||
if (this.device.model() === "MI 5s" || this.device.model() === "ASUS_Z012D") {
|
||||
await this.tapForDevice(this.device, 60, 1400)
|
||||
} else if (this.device.model() === "HUAWEI NXT-TL00") {
|
||||
await this.tapForDevice(this.device, 530, 950)
|
||||
} else
|
||||
await this.tapForDevice(this.device, 455, 1920)
|
||||
await delay(2000);
|
||||
@@ -999,6 +1002,8 @@ class CommandorPage {
|
||||
await this.tapForDevice(this.device, 540, 1611)
|
||||
} else if (this.device.model() === "22041219PG") {
|
||||
await this.tapForDevice(this.device, 530, 1600)
|
||||
} else if (this.device.model() === "CPH2469") {
|
||||
await this.tapForDevice(this.device, 322, 1146)
|
||||
} else
|
||||
await this.tapForDevice(this.device, 500, 1680)
|
||||
// await this.device.shell("input tap " + 500 + " " + 1680)
|
||||
@@ -1101,12 +1106,18 @@ class CommandorPage {
|
||||
let model = this.device.model()
|
||||
if (model === "CPH2219") {
|
||||
await this.device.shell("input tap " + 558 + " " + 1160)
|
||||
} else if (model === "MI 5s") {
|
||||
} else if (model === "MI 5s" || model === "ASUS_Z012D") {
|
||||
await this.tapForDevice(this.device, 530, 1000)
|
||||
} else if (model === "SM-G965U1") {
|
||||
await this.tapForDevice(this.device, 530, 1000)
|
||||
} else if (model === "HUAWEI NXT-TL00") {
|
||||
await this.tapForDevice(this.device, 530, 950)
|
||||
} else if (model === "M2006C3LG" || model === "220233L2G") {
|
||||
await this.tapForDevice(this.device, 360, 777)
|
||||
} else if (model === "ONEPLUS A6000") {
|
||||
await this.device.shell("input tap " + 530 + " " + 1106)
|
||||
await this.tapForDevice(this.device, 530, 1045)
|
||||
} else if (model === "CPH2469") {
|
||||
await this.tapForDevice(this.device, 360, 820)
|
||||
} else {
|
||||
logWithDevice("handleBraveSkipBtn", this.device)
|
||||
await this.tapForDevice(this.device, 470, 1160)
|
||||
@@ -1129,6 +1140,8 @@ class CommandorPage {
|
||||
this.device.shell("input tap " + 925 + " " + 1325)
|
||||
} else if (this.device.model() === "22041219PG") {
|
||||
this.device.shell("input tap " + 925 + " " + 1430)
|
||||
} else if (this.device.model() === "moto g51 5G") {
|
||||
await this.tapForDevice(this.device, 950, 1434)
|
||||
} else
|
||||
this.device.shell("input tap " + 933 + " " + 1538)
|
||||
await delay(2000);
|
||||
@@ -1193,21 +1206,21 @@ class CommandorPage {
|
||||
|
||||
async enableDisableAirPlanMode() {
|
||||
logWithDevice("will enable/disable airplane mode", this.device)
|
||||
try {
|
||||
// await this.device.shell("cmd connectivity airplane-mode enable")
|
||||
await exceutShellCmd(this.device, "cmd connectivity airplane-mode enable")
|
||||
await delay(1000)
|
||||
await exceutShellCmd(this.device, "cmd connectivity airplane-mode disable")
|
||||
// await this.device.shell("cmd connectivity airplane-mode disable")
|
||||
await delay(2000)
|
||||
} catch (e) {
|
||||
try {
|
||||
await this.device.shell("cmd connectivity airplane-mode disable")
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
}
|
||||
console.log(e)
|
||||
}
|
||||
// try {
|
||||
// // await this.device.shell("cmd connectivity airplane-mode enable")
|
||||
// await exceutShellCmd(this.device, "cmd connectivity airplane-mode enable")
|
||||
// await delay(1000)
|
||||
// await exceutShellCmd(this.device, "cmd connectivity airplane-mode disable")
|
||||
// // await this.device.shell("cmd connectivity airplane-mode disable")
|
||||
// await delay(2000)
|
||||
// } catch (e) {
|
||||
// try {
|
||||
// await this.device.shell("cmd connectivity airplane-mode disable")
|
||||
// } catch (e) {
|
||||
// console.log(e)
|
||||
// }
|
||||
// console.log(e)
|
||||
// }
|
||||
}
|
||||
|
||||
async tapGoogleDisconnectBtn() {
|
||||
|
||||
@@ -15,8 +15,9 @@ function delay(delayInMs) {
|
||||
const NO_INTERNET_FR = "Aucun accés a Internet"
|
||||
const NO_INTERNET_FR_2 = "Aucun accès à Internet"
|
||||
const BRAVE_VPN_SKIP = "Pare-feu + VPN Brave"
|
||||
const MESSAGE_URL_VALIDATION_FR = "envoyé un lien par e-mail."
|
||||
const MESSAGE_URL_VALIDATION_FR_2 = "un lien par e-mail"
|
||||
const MESSAGE_URL_VALIDATION_FR = "Vous recevrez un email de validation"
|
||||
const MESSAGE_URL_VALIDATION_FR_2 = "Merci de votre intérêt pour notre Maison"
|
||||
const SSL_CERT_ERROR = " Votre connexion n'est pas privée"
|
||||
const MESSAGE_URL_VALIDATION_EN = "Please click on the link we sent by email"
|
||||
const CHOOSE_POSITION_GOOGLE_FR = " Choisir la position pour les résultats de recherche"
|
||||
const CAPTCHA_ERROR_MESSAGE = "Error verifying captcha, please try again"
|
||||
@@ -31,16 +32,21 @@ const ERR_CACHE_MISS = "ERR_CACHE_MISS"
|
||||
const ERR_CACHE_MISS_2 = "ERR_CACHE-MISS"
|
||||
const ERR_CACHE_MISS_3 = "appuyer sur le bouton d'actualisation"
|
||||
const ERR_CACHE_MISS_4 = "renvoyer les données"
|
||||
const ERR_EMPTY_RESPONSE = "ERR_EMPTY_RESPONSE"
|
||||
const ERR_SSL_PROTOCOL = "SSL_PROTOCOL_ERROR"
|
||||
const SLIDING_CAPTCHA_FR = "Pourquoi cette vérification"
|
||||
const SLIDING_CAPTCHA_LOADING_FR = "Chargement."
|
||||
const SLIDING_CAPTCHA_FR_2 = "Glissez vers la droite pour"
|
||||
const SLIDING_CAPTCHA_FR_3 = "la droite pour completer le puzzle"
|
||||
const SLIDING_CAPTCHA_FR_4 = " s'assure qu'on s'adresse bien"
|
||||
const SLIDING_CAPTCHA_FR_5 = "On s'assure que c'est"
|
||||
const SLIDING_CAPTCHA_FR_6 = "s'assure que cest bien vous"
|
||||
const MESSAGE_FILL_FIELD_FR = "Demande de rendez-vous pour"
|
||||
const MESSAGE_FILL_FIELD_FR_2 = "des champs de données doivent étre complétés"
|
||||
const MESSAGE_FILL_FIELD_FR_3 = "Sans préféré"
|
||||
const MESSAGE_FILL_FIELD_FR_4 = "Magasin préféré"
|
||||
const MESSAGE_FILL_FIELD_FR_5 = "email vous sera envoyé pour vous"
|
||||
const MESSAGE_FILL_FIELD_FR_6 = "Prénom* Téléphone*"
|
||||
const WELCOME_MESSAGE_FR = "Bienvenue dans Chrome"
|
||||
const PAGE_OPTIMIZATION_CHROME_FR = "Vous pouvez changer d'avis a tout moment dans"
|
||||
const PAGE_OPTIMIZATION_CHROME_FR_6 = "Vous pouvez changer davis a tout moment"
|
||||
@@ -100,7 +106,10 @@ class OCRChecker {
|
||||
} else if (result.includes(BRAVE_VPN_SKIP)) {
|
||||
await this.deleteFile(fileName)
|
||||
return OCRResult.BRAVE_VPN_SKIP
|
||||
} else if (result.includes(MESSAGE_FILL_FIELD_FR) || result.includes(MESSAGE_FILL_FIELD_FR_2) || result.includes(MESSAGE_FILL_FIELD_FR_3) || result.includes(MESSAGE_FILL_FIELD_FR_4) || result.includes(MESSAGE_FILL_FIELD_FR_5)) {
|
||||
} else if (result.includes(SSL_CERT_ERROR)) {
|
||||
await this.deleteFile(fileName)
|
||||
return OCRResult.SSL_CERT_ERROR
|
||||
} else if (result.includes(MESSAGE_FILL_FIELD_FR) || result.includes(MESSAGE_FILL_FIELD_FR_2) || result.includes(MESSAGE_FILL_FIELD_FR_3) || result.includes(MESSAGE_FILL_FIELD_FR_4) || result.includes(MESSAGE_FILL_FIELD_FR_5) || result.includes(MESSAGE_FILL_FIELD_FR_6)) {
|
||||
await this.deleteFile(fileName)
|
||||
return OCRResult.FILL_FIELD
|
||||
} else if (result.includes(CAPTCHA_ERROR_MESSAGE) || result.includes(CAPTCHA_ERROR_MESSAGE_FR)) {
|
||||
@@ -108,7 +117,9 @@ class OCRChecker {
|
||||
} else if (result.includes(BLOCKED_MSG_EN) || result.includes(BLOCKED_MSG_FR) || result.includes(BLOCKED_MSG_FR_2) || result.includes(BLOCKED_MSG_FR_3)) {
|
||||
await this.deleteFile(fileName)
|
||||
return OCRResult.BLOCKED
|
||||
} else if (result.includes(ERR_CACHE_MISS) || result.includes(ERR_CACHE_MISS_2) || result.includes(ERR_CACHE_MISS_3) || result.includes(ERR_CACHE_MISS_4)) {
|
||||
} else if (result.includes(ERR_CACHE_MISS) || result.includes(ERR_CACHE_MISS_2) || result.includes(ERR_CACHE_MISS_3)
|
||||
|| result.includes(ERR_CACHE_MISS_4) || result.includes(ERR_EMPTY_RESPONSE)) { //|| result.includes(ERR_SSL_PROTOCOL)
|
||||
await this.deleteFile(fileName)
|
||||
return OCRResult.TO_REFRESH
|
||||
} else if (result.includes(CHECKING_MSG_FR) || result.includes(CHECKING_MSG_FR_2)) {
|
||||
await this.deleteFile(fileName)
|
||||
@@ -119,8 +130,11 @@ class OCRChecker {
|
||||
} else if (result.includes(BRAVE_SKIP_PUB) || result.includes(BRAVE_SKIP_PUB_2) || result.includes(BRAVE_SKIP_PUB_3) || result.includes(BRAVE_SKIP_PUB_4) || result.includes(BRAVE_SKIP_PUB_5)) {
|
||||
await this.deleteFile(fileName)
|
||||
return OCRResult.BRAVE_PRIVACY_PUB
|
||||
} else if (result.includes(SLIDING_CAPTCHA_FR) || result.includes(SLIDING_CAPTCHA_FR_2) || result.includes(SLIDING_CAPTCHA_FR_3) || result.includes(SLIDING_CAPTCHA_FR_4) || result.includes(SLIDING_CAPTCHA_FR_5)) {
|
||||
} else if (result.includes(SLIDING_CAPTCHA_FR) || result.includes(SLIDING_CAPTCHA_FR_2) || result.includes(SLIDING_CAPTCHA_FR_3) || result.includes(SLIDING_CAPTCHA_FR_4) || result.includes(SLIDING_CAPTCHA_FR_5) || result.includes(SLIDING_CAPTCHA_FR_6)) {
|
||||
await this.deleteFile(fileName)
|
||||
if (result.includes(SLIDING_CAPTCHA_LOADING_FR)) {
|
||||
return OCRResult.SLIDING_CAPTCHA_LOADING
|
||||
}
|
||||
// await this.deleteFile(screenShot)
|
||||
// if (result.includes("rac"))
|
||||
// return OCRResult.SLIDING_CAPTCHA_REFRESH
|
||||
@@ -184,6 +198,7 @@ class OCRChecker {
|
||||
async take_screen_shot() {
|
||||
let name = this.get_file_name()
|
||||
console.log("will take screenshot for " + this.device.model() + ":" + this.device.serial())
|
||||
console.log("name is " + name)
|
||||
let stdout1 = await exec("adb -s " + this.device.serial() + " exec-out screencap -p > " + name)
|
||||
await delay(5000);
|
||||
console.log(`stdout: ${stdout1}`);
|
||||
|
||||
@@ -34,17 +34,18 @@ class SlidingCaptchaSolver {
|
||||
let stdout1 = await exec("adb -s " + device.serial() + " exec-out screencap -p > " + name)
|
||||
// await delay(5000);
|
||||
console.log(`stdout: ${stdout1}`);
|
||||
await delay(1000);
|
||||
await delay(5000);
|
||||
}
|
||||
|
||||
|
||||
async sliding_captcha(device, onResult) {
|
||||
// take screenshot
|
||||
console.log("take screenshot")
|
||||
console.log("sliding_captcha.take screenshot")
|
||||
let blockedFileName = uuidv4();
|
||||
let blockedImageFileName = "blocked_" + blockedFileName + ".png"
|
||||
await this.take_screen_shot(blockedImageFileName, device)
|
||||
//get resolution of screen
|
||||
console.log("sliding_captcha.sendRequest:" + blockedImageFileName)
|
||||
await this.sendRequest(blockedImageFileName, async (detectedPositionList) => {
|
||||
console.log("detectedPosition: " + device.model() + ":" + detectedPositionList);
|
||||
if (detectedPositionList.length >= 2) {
|
||||
@@ -81,6 +82,7 @@ class SlidingCaptchaSolver {
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
async deleteFile(filename) {
|
||||
try {
|
||||
fs.unlinkSync(filename)
|
||||
@@ -89,6 +91,7 @@ class SlidingCaptchaSolver {
|
||||
return OCRResult.TERMINAED
|
||||
}
|
||||
}
|
||||
|
||||
async sendRequest(fileName, callback) {
|
||||
const fileStream = fs.createReadStream(fileName);
|
||||
let response = await axios.post(DEEPLEARNING_CAPTCHA_HOST, fileStream, {
|
||||
|
||||
Reference in New Issue
Block a user