1 Commits

Author SHA1 Message Date
panleicim 83d389e061 add some support for english version 2024-09-20 20:40:36 +02:00
13 changed files with 286 additions and 345 deletions
+1
View File
@@ -20,6 +20,7 @@
"node-tesseract-ocr": "^2.2.1",
"node-wget": "^0.4.3",
"node-xlsx": "^0.21.0",
"playwright": "^1.39.0",
"puppeteer": "^15.2.0",
"read-ini-file": "^3.0.1",
"uuid": "^9.0.0",
-81
View File
@@ -1,81 +0,0 @@
const {exec} = require("child_process");
DEVICE_REGEX = "(^[a-z0-9A-Z]*) .* model:([a-z0-9A-Z_]+)"
async function devices() {
return new Promise((resolve, reject) => {
exec("adb devices -l", (error, stdout, stderr) => {
if (error) {
console.log(`error: ${error.message}`);
return;
}
if (stderr) {
console.log(`stderr: ${stderr}`);
return;
}
console.log(`stdout: ${stdout}`);
let lines = stdout.split("\n");
let result = [];
for (let i = 1; i < lines.length; i++) {
currentLine = lines[i]
console.log("currentLine is " + currentLine)
if (currentLine.length > 0) {
const o = currentLine.split('\t')
findResult = currentLine.match(DEVICE_REGEX)
console.log(findResult)
try{
result.push(new AndroidDevice(findResult[1], findResult[2]));}
catch(e){
console.log(e)}
console.log(result[i])
}
}
resolve(result);
}
);
})
}
class AndroidDevice {
constructor(serial, model) {
this.serial = serial
this.model = model
}
async swipeForDevice(x0, y0, x1, y1) {
let cmd = `input swipe ${x0} ${y0} ${x1} ${y1}`
await this.shell(cmd);
}
async tapForDevice(x, y) {
let cmd = `input tap ${x} ${y}`
console.log("cmd is " + cmd)
try {
await this.shell(cmd);
} catch (e) {
console.log(e)
}
}
shell(cmd) {
return new Promise((resolve, reject) => {
exec("adb -s " + this.serial + " shell " + cmd, (error, stdout, stderr) => {
if (error) {
console.log(`error: ${error.message}`);
reject(error);
return;
}
if (stderr) {
console.log(`stderr: ${stderr}`);
reject(stderr);
return;
}
console.log(`stdout: ${stdout}`);
resolve(stdout);
}
);
})
}
}
module.exports = {AndroidDevice, devices}
+98 -56
View File
@@ -1,3 +1,4 @@
const {_android: android} = require('playwright');
const ExcelUtil = require("./excel/ExcelUtil");
const CommandorPage = require("./workers/CommandorPage");
const {MongoManager, formatDate} = require("./workers/mongo_manager");
@@ -5,21 +6,20 @@ const alert = require('alert');
const schedule = require("node-schedule");
const DeviceExcludeMode = require("./models/DeviceExcludeMode");
const {Sender} = require("./queue/Sender");
const {devices} = require("./android/adb");
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 = 30 * 3;
let excelUtil = new ExcelUtil();
let collectionName = formatDate(new Date())
let includeMode = DeviceExcludeMode.ZERO
// let includeMode = DeviceExcludeMode.APPOINTMENT
let excludeMode = DeviceExcludeMode.ZERO
let three_to_include = []
let four_to_include = ["bec11752", "4e8ca027", "hi7ljr5xduyt9pfi", "EPHUT20825001518"]
let three_to_excludes = ["e30eb015"]
let four_to_excludes = ["bec11752", "4e8ca027", "hi7ljr5xduyt9pfi", "EPHUT20825001518"]
let seven_to_excludes = ["4e8ca027", "hi7ljr5xduyt9pfi", "EPHUT20825001518", "bec11752", "fuljaueqguugf6pn", "EPHUT20825001518"]
// let appointment_to_include = ["ai9xv8hy599hvkee", "07fbd156", "71a0371d", "J4AXB761H2322WJ", "W8GMFELRHIKZS84T", "fy65eqs4wkvcpf9h", "p7d6nbw8cu7duous", "fuljaueqguugf6pn", "fmiz5pa6rsx4u4ts"]
let appointment_to_include = ["ai9xv8hy599hvkee", "07fbd156", "71a0371d", "J4AXB761H2322WJ", "W8GMFELRHIKZS84T", "fy65eqs4wkvcpf9h", "p7d6nbw8cu7duous", "fmiz5pa6rsx4u4ts"]
let nine_to_include = ["bec11752", "4e8ca027", "hi7ljr5xduyt9pfi", "47e7e36b", "p7d6nbw8cu7duous", "njzxojhim7gedyvw", "fmiz5pa6rsx4u4ts", "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"]
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
@@ -36,10 +36,58 @@ async function filterAlreadyBookedContacts(contactList) {
return contactsToBook;
}
async function filterAlreadyAcceptedContacts(contactList) {
let alreadyBookedContacts = await mongoManager.getAllAcceptedAppointments();
let contactsToBook = [];
contactList.forEach((contact) => {
let needToBook = true;
alreadyBookedContacts.forEach((acceptedItem) => {
if (acceptedItem.email === contact.mail) {
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 + NINETY_DAYS_IN_S <= (new Date()) / 1000;
if (!needToBook) {
console.log("already accepted appointment --> skip");
}
}
})
if (needToBook) {
contactsToBook.push(contact)
}
})
return contactsToBook;
}
async function filterBlacklistedContacts(contactList) {
let blackListedContacts = await mongoManager.getAllBlackedListItems();
let contactsToBook = [];
contactList.forEach((contact) => {
let needToBook = true;
blackListedContacts.forEach((blackListItem) => {
if (blackListItem.mail === contact.mail) {
console.log("=====handle blacklist item before booking=====");
console.log("update_at_s is " + blackListItem.update_at_in_s)
console.log("black list email is " + blackListItem.mail)
needToBook = blackListItem.update_at_in_s + SEVEN_DAYS_IN_S <= (new Date()) / 1000;
if (!needToBook) {
console.log("contact in blacklist -->skip");
}
}
})
if (needToBook) {
contactsToBook.push(contact)
}
})
return contactsToBook;
}
async function needToBook(contact, mongoManager, alreadyBooked) {
console.log("check contact with email " + contact.mail)
// let alreadyBooked = await mongoManager.getAllSuccessfulItemsForDay(collectionName);
// let blackListItems = await mongoManager.getAllBlackedListItems();
let blackListItems = [];
// let alreadyAcceptedItems = await mongoManager.getAllAcceptedAppointments();
let needToBook = true;
await alreadyBooked.forEach((bookedItem) => {
if (bookedItem.email === contact.mail) {
@@ -60,12 +108,25 @@ async function needToBook(contact, mongoManager, alreadyBooked) {
}
})
}
// if (needToBook) {
// await alreadyAcceptedItems.forEach((acceptedItem) => {
// if (acceptedItem.email === contact.mail) {
// 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 + NINETY_DAYS_IN_S <= (new Date()) / 1000;
// if (!needToBook) {
// console.log("already accepted appointment --> skip");
// }
// }
// })
// }
return needToBook
}
async function startBook(contactPojo, device, sender, selectedStore, alertBeep, port) {
console.log(`model: ${device.model}`);
console.log(`serial: ${device.serial}`);
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();
@@ -74,7 +135,7 @@ async function startBook(contactPojo, device, sender, selectedStore, alertBeep,
return
}
if (await needToBook(contactPojo, mongoManager, alreadyBooked)) {
let commandor = new CommandorPage(contactPojo, device, sender, mongoManager, selectedStore, alertBeep, port);
let commandor = new CommandorPage(contactPojo, device, sender, mongoManager, selectedStore, audioAnalyse, alertBeep, port);
//read contacts form excel
return await commandor.loadPage();
} else {
@@ -82,14 +143,14 @@ async function startBook(contactPojo, device, sender, selectedStore, alertBeep,
}
}
async function startWithList(contacts, device, sender, selectedStore, 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, sender, selectedStore, alertBeep, port);
const contents = await startBook(contactPojo, device, sender, selectedStore, audioAnalyse, alertBeep, port);
console.log(contents);
}, Promise.resolve());
}
@@ -118,17 +179,9 @@ function shuffle(array) {
return array;
}
function getContactListForDevice(device, allContactList) {
let contactList = [];
allContactList.forEach((contact) => {
if (contact.serial === device.serial) {
contactList.push(contact)
}
})
return contactList;
}
async function startBookWithNumbers(startNumber, endNumber, selectedStore, pathToExcelFile = '/Users/lpan/Desktop/contact_all.xlsx', bindSerial = true, alertBeep = false) {
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,20 +198,22 @@ async function startBookWithNumbers(startNumber, endNumber, selectedStore, pathT
console.log("startForwordingForDevice() called")
const execSync = require('child_process').execSync;
// get attributed port
let attributedPort = device_port_info[device.serial]
let attributedPort = device_port_info[device.serial()]
if (attributedPort) {
let cmd = 'adb -s ' + device.serial + " forward tcp:" + attributedPort + " localabstract:chrome_devtools_remote";
let cmd = 'adb -s ' + device.serial() + " forward tcp:" + attributedPort + " localabstract:chrome_devtools_remote";
console.log("cmd is " + cmd);
const output = execSync(cmd, {encoding: 'utf-8'}); // the default is 'buffer'
console.log('Output was:\n', output);
} else {
attributedPort = startPort;
startPort++;
let cmd = 'adb -s ' + device.serial + " forward tcp:" + attributedPort + " localabstract:chrome_devtools_remote";
let cmd = 'adb -s ' + device.serial() + " forward tcp:" + attributedPort + " localabstract:chrome_devtools_remote";
console.log("cmd is " + cmd);
const output = execSync(cmd, {encoding: 'utf-8'}); // the default is 'buffer'
console.log('Output was:\n', output);
}
// start chrome
// device.shell("am start -n com.brave.browser/com.google.android.apps.chrome.Main")
return attributedPort
}
@@ -171,46 +226,33 @@ async function startBookWithNumbers(startNumber, endNumber, selectedStore, pathT
filterAlreadyBookedContacts(contactList).then((listWithoutBlackContact) => {
console.log("will call filterAlreadyAcceptedContacts")
console.log("number of contacts to book:" + listWithoutBlackContact.length)
devices().then((devices) => {
android.devices().then((devices) => {
if (devices.length === 0) {
alert("未找到连接的设备");
return
}
let device_to_excludes = three_to_include;
if (includeMode === DeviceExcludeMode.FOUR) {
device_to_excludes = four_to_include;
} else if (includeMode === DeviceExcludeMode.THREE) {
device_to_excludes = three_to_include;
} else if (includeMode === DeviceExcludeMode.NINE) {
device_to_excludes = nine_to_include;
} else if (includeMode === DeviceExcludeMode.SEVEN) {
let device_to_excludes = three_to_excludes;
if (excludeMode === DeviceExcludeMode.FOUR) {
device_to_excludes = four_to_excludes;
} else if (excludeMode === DeviceExcludeMode.THREE) {
device_to_excludes = three_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 (includeMode === DeviceExcludeMode.APPOINTMENT) {
device_to_excludes = appointment_to_include
} else if (includeMode === DeviceExcludeMode.ZERO) {
device_to_excludes = ["127.0.0.1:6555"]
}
let filteredDeviceList;
if (includeMode === DeviceExcludeMode.ZERO) {
filteredDeviceList = devices
} else {
filteredDeviceList = devices.filter(device => device_to_excludes.includes(device.serial))
} else if (excludeMode === DeviceExcludeMode.SIX) {
device_to_excludes = six_to_excludes
} else if (excludeMode === DeviceExcludeMode.ZERO) {
device_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)
listWithoutBlackContact = shuffle(listWithoutBlackContact)
for (let i = 0; i < filteredDeviceList.length; i++) {
let device = filteredDeviceList[i];
let port = startForwordingForDevice(device)
let _contactList = []
if (bindSerial) {
_contactList = getContactListForDevice(device, listWithoutBlackContact)
} else {
_contactList = listWithoutBlackContact.slice(i * segmentNumber, segmentNumber * (i + 1))
}
console.log("contactList: for device:" + device.serial + " has " + _contactList.length)
startWithList(_contactList, device, sender, selectedStore, alertBeep, port);
startWithList(listWithoutBlackContact.slice(i * segmentNumber, segmentNumber * (i + 1)), device, sender, selectedStore, audioAnalyse, alertBeep, port);
}
})
+2 -3
View File
@@ -19,12 +19,11 @@ class ExcelUtil {
if (store === undefined || store.length === 0) {
store = "random"
}
let serial = info[5];
let ipCountry = info[6];
let ipCountry = info[5];
if (ipCountry === undefined || ipCountry.length === 0) {
ipCountry = "FR"
}
let newContact = new ContactPojo(phoneNumber, passportNumber, lastName, firstName, mail, store, ipCountry, serial);
let newContact = new ContactPojo(phoneNumber, passportNumber, lastName, firstName, mail, store, ipCountry);
contactList.push(newContact);
}
}
+1 -2
View File
@@ -1,6 +1,6 @@
class ContactPojo {
constructor(phoneNumber, passportNumber, lastName, firstName, mail, store, ipCountry, serial) {
constructor(phoneNumber, passportNumber, lastName, firstName, mail, store, ipCountry) {
this.phoneNumber = phoneNumber;
this.passportNumber = passportNumber;
this.lastName = lastName;
@@ -8,7 +8,6 @@ class ContactPojo {
this.mail = mail;
this.store = store;
this.ipCountry = ipCountry;
this.serial = serial;
}
}
+2 -3
View File
@@ -1,10 +1,9 @@
const DeviceIncludeMode = {
const DeviceExcludeMode = {
ZERO: Symbol("ZERO"),
NINE: Symbol("NINE"),
THREE: Symbol("THREE"),
SIX: Symbol("SIX"),
SEVEN: Symbol("SEVEN"),
APPOINTMENT: Symbol("APPOINTMENT"),
FOUR: Symbol("FOUR")
}
module.exports = DeviceIncludeMode
module.exports = DeviceExcludeMode
+1
View File
@@ -8,6 +8,7 @@ const OCRResult = {
SLIDING_CAPTCHA_LOADING: Symbol("SLIDING_CAPTCHA_LOADING"),
SLIDING_CAPTCHA_REFRESH: Symbol("SLIDING_CAPTCHA_REFRESH"),
FILL_FIELD: Symbol("FILL_FIELD"),
FILL_FIELD_EN: Symbol("FILL_FIELD_EN"),
NEED_TO_CLICK_LATE_BTN: Symbol("NEED_TO_CLICK_LATE_BTN"),
ONLINE_APPOINTMENT: Symbol("Online Appointment"),
PAGE_OPTIMIZATION: Symbol("PAGE_OPTIMIZATION"),
+1 -3
View File
@@ -19,7 +19,6 @@ class ReserveResultPojo {
this.hostName = hostName
this.currentIp = ""
this.created_at = new Date().toLocaleString()
this.browserInfo = ""
}
to_mongo_dict() {
@@ -36,8 +35,7 @@ class ReserveResultPojo {
serial: this.serial,
created_at: this.created_at,
hostName: this.hostName,
current_ip: this.currentIp,
browserInfo: this.browserInfo
current_ip: this.currentIp
}
}
+2 -2
View File
@@ -37,8 +37,8 @@ function cmdExecute(command) {
async function openUrlWithAdb(url, device) {
// do not continue if device is blocked
console.log("load url on device " + device.model + " url=" + url)
let cmd = "adb -s " + device.serial + " shell am start -a android.intent.action.VIEW -d " + url
console.log("load url on device " + device.model() + " url=" + url)
let cmd = "adb -s " + device.serial() + " shell am start -a android.intent.action.VIEW -d " + url
try {
let output = await cmdExecute(cmd);
console.log(`stdout: ${output}`);
+128 -155
View File
@@ -11,7 +11,6 @@ const {exec} = require("child_process");
const {openUrlWithAdb} = require("../utiles/CmdUtils");
const RequestDataPojo = require("../models/RequestDataPojo");
const {REQUEST_DATA_OBJECT, TEST_QUEUE} = require("../queue/Sender");
const {page} = require("yarn/lib/cli");
// const RDV_URL = "http://192.168.0.44:8000/test_appointment.html"
const RDV_URL = "https://rendezvousparis.hermes.com/client/register";
const BLANK_URL = "about:blank"
@@ -51,12 +50,6 @@ function getRandom() {
return Math.floor(Math.random() * 3);
}
function getRandomId() {
let _list = [PASSPORT_ID, EMAIL_ID, FIRST_NAME, LAST_NAME];
let index = Math.floor(Math.random() * _list.length);
return _list[index];
}
function getRandomWaitTime() {
return getRandom() * 1000
}
@@ -66,25 +59,25 @@ function log(message) {
}
async function clearApp(device, packageName) {
let cmd = `adb -s ${device.serial} shell pm clear ${packageName}`
let cmd = `adb -s ${device.serial()} shell pm clear ${packageName}`
logWithDevice("cmd is " + cmd, device)
await exec(cmd);
}
async function exceutShellCmd(device, cmdToExecut) {
let cmd = `adb -s ${device.serial} shell ${cmdToExecut}`
let cmd = `adb -s ${device.serial()} shell ${cmdToExecut}`
logWithDevice("cmd is " + cmd, device)
await exec(cmd);
}
function logWithDevice(message, device) {
appointmentLogger.log({level: "info", message: device.model + ":" + device.serial + ":" + message})
appointmentLogger.log({level: "info", message: device.model() + ":" + device.serial() + ":" + message})
}
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']
class CommandorPage {
constructor(contact, device, sender, mongoManager, selectedStore = DEFAULT_STORE, alertBeep = false, port = 9000, shareCookiesWithRequests = true) {
constructor(contact, device, sender, mongoManager, selectedStore = DEFAULT_STORE, audioAnalyse = false, alertBeep = false, port = 9000, shareCookiesWithRequests = true) {
this.contact = contact;
// to remove this line if we want to use store in contacts
// this.contact.store = DEFAULT_STORE
@@ -95,10 +88,9 @@ class CommandorPage {
this.shareCookiesWithRequests = shareCookiesWithRequests;
this.port = port;
this.sender = sender;
this.slidingCaptchaSolver = new SlidingCaptchaSolver(this.device);
this.ocrChecker = new OCRChecker(this.device, this.contact);
// this.browserPackageName = "com.brave.browser";
this.browserPackageName = "com.android.chrome";
this.browserPackageName = "com.brave.browser";
// this.browserPackageName = "com.android.chrome";
this.isFillingFields = false;
this.isTerminated = false;
this.cguChecked = false;
@@ -203,9 +195,9 @@ class CommandorPage {
}
async loadPage() {
logWithDevice(this.device.serial + ":loadPage() called, with port:" + this.port, this.device);
logWithDevice(this.device.serial() + ":loadPage() called, with port:" + this.port, this.device);
try {
// let cmd = 'adb -s ' + device.serial + " forward tcp:" + attributedPort + " localabstract:chrome_devtools_remote";
// let cmd = 'adb -s ' + device.serial() + " forward tcp:" + attributedPort + " localabstract:chrome_devtools_remote";
await exceutShellCmd(this.device, " forward tcp:" + this.port + " localabstract:chrome_devtools_remote")
await delay(1 * 1000);
// await this.startPage(this.device, this.browserPackageName + "/com.google.android.apps.chrome.Main")
@@ -226,7 +218,7 @@ class CommandorPage {
let cancel
const intervalTask = setInterval(async () => {
if (this.isTerminated) {
logWithDevice(":request terminated, send cancel()", this.device)
log(this.device.model() + ":request terminated, send cancel()");
try {
if (this.page !== undefined && !this.page.isClosed()) {
await this.page.close()
@@ -323,7 +315,9 @@ class CommandorPage {
// await delay(getRandomWaitTime())
// await page.click(COUNTRY_ID);
// await delay(getRandomWaitTime())
await page.select(COUNTRY_ID, 'FR');
await page.evaluate(() => {
document.getElementById("phone_country").value = "FR"
})
await delay(getRandomWaitTime())
this.isCountryChoosen = true;
}
@@ -405,15 +399,15 @@ class CommandorPage {
logWithDevice("input name called with this.isNameInput=" + this.isNameInput, this.device)
if (this.browser.isConnected() && !this.isTerminated && !this.page.isClosed()) {
if (!this.isNameInput) {
// await page.focus(LAST_NAME);
await page.focus(LAST_NAME);
await delay(getRandomWaitTime());
console.log("will clear surname field");
// await page.evaluate(() => {
// let field = document.getElementById("surname");
// if (field) {
// field.value = ""
// }
// })
await page.evaluate(() => {
let field = document.getElementById("surname");
if (field) {
field.value = ""
}
})
await delay(1000);
// await page.keyboard.type(this.contact.lastName);
await page.evaluate((lastName) => {
@@ -429,6 +423,7 @@ class CommandorPage {
let field = document.getElementById("name");
if (field) {
field.value = firstName;
// field.value = ""
}
}, this.contact.firstName)
// await page.keyboard.type(this.contact.firstName);
@@ -511,8 +506,10 @@ class CommandorPage {
document.querySelector("#cgu").checked = true
}
});
// await page.click(CGU_ID);
await delay(getRandomWaitTime());
await page.focus(PROCESSING_ID);
// await page.click(PROCESSING_ID)
await page.evaluate(() => {
if (!document.querySelector("#processing").checked) {
document.querySelector("#processing").checked = true
@@ -553,7 +550,7 @@ class CommandorPage {
}
async fillFields(page) {
async fillFields(page, checkResult) {
logWithDevice("fillFields called for contact: " + this.contact.mail, this.device)
logWithDevice("this.isFillingFields: " + this.isFillingFields, this.device);
logWithDevice("this.isTerminated: " + this.isTerminated, this.device);
@@ -561,7 +558,9 @@ class CommandorPage {
this.isFillingFields = true;
await this.chooseStore(page);
await this.inputName(page);
// await this.chooseCountry(page);
// if (checkResult === OCRResult.FILL_FIELD_EN) {
await this.chooseCountry(page);
// }
await this.inputPhoneNumber(page)
await this.fillEmail(page)
await this.inputPassportId(page)
@@ -585,15 +584,9 @@ class CommandorPage {
}
}
async clickValid() {
logWithDevice("clickValid() called.", this.device);
for (let i = 0; i < 3; i++) {
let _id_to_click = getRandomId()
await this.page.click(_id_to_click)
await delay(getRandomWaitTime())
}
this.isFillingFields = false
try {
if (!this.page.isClosed()) {
@@ -622,7 +615,7 @@ class CommandorPage {
this.contact.firstName = raw.firstName
}
await this.page.evaluate(() => {
document.getElementsByTagName("button")[1].click();
document.getElementsByClassName("btn")[0].click();
})
if (this.firstStart) {
this.disconnectBrowser();
@@ -645,6 +638,11 @@ class CommandorPage {
async resolveCaptcha(page) {
logWithDevice("resolveCaptcha", this.device)
if (RDV_URL.includes("192")) {
// await this.push_message_to_queue(PublishType.SUCCESS)
await delay(100000)
return
}
try {
//check whether there is captcha
let pageContent = await page.content()
@@ -738,13 +736,14 @@ class CommandorPage {
async slidingCaptcha(onResult) {
logWithDevice("slidingCaptcha", this.device);
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`
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(5000);
}
await this.slidingCaptchaSolver.solve(this.page, async (isSuccessful) => {
logWithDevice("check isAlwaysBlocked", this.device)
let slidingCaptchaSolver = new SlidingCaptchaSolver(this.device);
await slidingCaptchaSolver.solve(this.page, async (isSuccessful) => {
console.log("check isAlwaysBlocked")
this.isFillingFields = false
onResult(isSuccessful)
})
@@ -783,17 +782,11 @@ class CommandorPage {
if (url === "https://rendezvousparis.hermes.com/client/welcome") {
return
}
let browserInfo = await this.page.evaluate(() => {
const ua = navigator.userAgent;
return ua
})
console.log(browserInfo); // outputs: `Chrome 62`
// save to mongoDb
let reserve = ReserveResultPojo.create_from_contact(this.contact, id, url, this.choosedStore, publishType);
reserve.source_from = this.device.model;
reserve.source_from = this.device.model();
reserve.currentIp = currentIp
reserve.serial = this.device.serial;
reserve.browserInfo = browserInfo;
reserve.serial = this.device.serial();
await this.mongoManager.saveReserveToDb(reserve.to_mongo_dict())
if (!this.page.isClosed()) {
try {
@@ -857,7 +850,7 @@ class CommandorPage {
}
async connectBrowserIfNecessary() {
if (this.browser === undefined || !this.browser.isConnected()) {
if (this.browser == undefined || !this.browser.isConnected()) {
try {
this.browser = await puppeteer.connect({
browserWSEndpoint: "ws://127.0.0.1:" + this.port + "/devtools/browser",
@@ -872,7 +865,7 @@ class CommandorPage {
async checkResultWithOcr() {
logWithDevice("checkResultWithOcr() called.", this.device)
if (this.device.model === "M2006C3LG")
if (this.device.model() === "M2006C3LG")
await delay(6000);
else {
await delay(4000);
@@ -885,6 +878,25 @@ class CommandorPage {
logWithDevice("will recheck OCR", this.device)
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) {
await delay(5 * 1000)
checkResult = await this.ocrChecker.get_result();
// await this.checkResultWithOcr()
} else {
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;
@@ -896,26 +908,10 @@ class CommandorPage {
this.isTerminated = true;
break;
case OCRResult.SLIDING_CAPTCHA_REFRESH:
this.isTerminated = true;
break;
case OCRResult.SLIDING_CAPTCHA:
this.isAlreadyRefresh = true;
// await this.generateRandomActions()
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) {
await delay(5 * 1000)
// checkResult = await this.ocrChecker.get_result();
await this.checkResultWithOcr()
} else {
await this.checkResultWithOcr()
}
})
await delay(5 * 1000)
await this.connect_to_browser(checkResult)
break;
case OCRResult.FILL_FIELD:
case OCRResult.FILL_FIELD_EN:
logWithDevice("FILL_FIELD", this.device)
if (this.browser === undefined || !this.browser.isConnected()) {
logWithDevice("trying to connect to browser", this.device)
@@ -930,7 +926,6 @@ class CommandorPage {
// add listeners
let pages = await timeout(this.browser.pages(), 5 * 1000);
pages.forEach((currentPage) => {
logWithDevice("current url is " + currentPage.url(), this.device)
if (currentPage.url() === RDV_URL) {
this.page = currentPage;
} else {
@@ -945,7 +940,7 @@ class CommandorPage {
logWithDevice("this.page.bringToFront();", this.device)
// await this.sendCookiesToQueue();
await this.page.bringToFront();
await this.fillFields(this.page)
await this.fillFields(this.page, checkResult)
await delay(2 * 1000);
} catch (e) {
console.log(e)
@@ -962,20 +957,9 @@ class CommandorPage {
if (this.browser.isConnected()) {
logWithDevice("will use old page", this.device)
logWithDevice("this.page.bringToFront();", this.device)
let pages = await timeout(this.browser.pages(), 5 * 1000);
pages.forEach((currentPage) => {
if (currentPage.url() === RDV_URL) {
this.page = currentPage;
} else {
try {
if (!this.isTerminated)
currentPage.close()
} catch (e) {
console.log(e)
}
}
})
await this.page.bringToFront();
// this.page = pages;
// this.page.await
await this.fillFields(this.page)
await delay(2 * 1000);
}
@@ -1004,23 +988,23 @@ class CommandorPage {
await this.checkResultWithOcr();
break;
case OCRResult.BRAVE_PRIVACY:
let model = this.device.model
if (model === "MI_5s" || this.device.model === "SM-G965U1" || this.device.model === "ASUS_Z012D") {
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") {
} else if (this.device.model() === "ONEPLUS A6000") {
await this.tapForDevice(this.device, 530, 1064)
} else if (this.device.model === "moto g51 5G") {
} else if (this.device.model() === "moto g51 5G") {
await this.tapForDevice(this.device, 500, 1080)
} else if (this.device.model === "CPH2469") {
} else if (this.device.model() === "CPH2469") {
await this.tapForDevice(this.device, 360, 820)
} else if (this.device.model === "M2006C3LG" || this.device.model === "220233L2G") {
} else if (this.device.model() === "M2006C3LG" || this.device.model() === "220233L2G") {
await this.tapForDevice(this.device, 350, 777)
} else if (this.device.model === "KB2003") {
} else if (this.device.model() === "KB2003") {
await this.tapForDevice(this.device, 500, 1200)
await this.tapForDevice(this.device, 500, 1120)
} else if (this.device.model === "DE2117") {
} else if (this.device.model() === "DE2117") {
await this.tapForDevice(this.device, 545, 1130)
} else
try {
@@ -1033,9 +1017,9 @@ class CommandorPage {
await this.checkResultWithOcr();
break;
case OCRResult.BRAVE_PRIVACY_PUB:
if (this.device.model === "MI_5s" || this.device.model === "ASUS_Z012D") {
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") {
} else if (this.device.model() === "HUAWEI NXT-TL00") {
await this.tapForDevice(this.device, 530, 950)
} else
await this.tapForDevice(this.device, 455, 1920)
@@ -1050,11 +1034,11 @@ class CommandorPage {
break
case OCRResult.BRAVE_NOTIFICATION:
logWithDevice("BRAVE_NOTIFICATION", this.device)
if (this.device.model === "21091116C") {
if (this.device.model() === "21091116C") {
await this.tapForDevice(this.device, 540, 1611)
} else if (this.device.model === "22041219PG") {
} else if (this.device.model() === "22041219PG") {
await this.tapForDevice(this.device, 530, 1600)
} else if (this.device.model === "CPH2469") {
} else if (this.device.model() === "CPH2469") {
await this.tapForDevice(this.device, 322, 1146)
} else
await this.tapForDevice(this.device, 500, 1680)
@@ -1071,21 +1055,18 @@ class CommandorPage {
break;
case OCRResult.BRAVE_VPN_SKIP:
logWithDevice("BRAVE_VPN_SKIP", this.device)
if (this.device.model === "M2006C3LG") {
if (this.device.model() === "M2006C3LG") {
await this.tapForDevice(this.device, 580, 445)
}
break;
case OCRResult.TO_SKIP
:
logWithDevice("TO_SKIP", this.device)
if (this.device.model === "21091116C" || this.device.model === "22041219PG") {
await this.tapForDevice(this.device, 530, 1742)
await delay(1000);
await this.tapForDevice(this.device, 530, 1742)
} else
await this.tapForDevice(this.device, 488, 1848)
if (this.device.model() === "21091116C")
await this.device.shell("input tap " + 530 + " " + 1742)
else
await this.device.shell("input tap " + 488 + " " + 1848)
await delay(2000);
await this.checkResultWithOcr();
break;
case
OCRResult.TO_REFRESH
@@ -1136,8 +1117,8 @@ class CommandorPage {
OCRResult.NEED_TO_CLICK_LATE_BTN
:
await this.tapLaterBtn()
await delay(5000)
await this.checkResultWithOcr();
this.firstStart = true;
await this.loadPage()
break;
case
OCRResult.CLOSED
@@ -1314,10 +1295,10 @@ class CommandorPage {
}
async handleBraveSkipBtn() {
let model = this.device.model
let model = this.device.model()
if (model === "CPH2219") {
await this.tapForDevice(this.device, 558, 1160)
} else if (model === "MI_5s" || model === "ASUS_Z012D") {
} 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)
@@ -1325,7 +1306,7 @@ class CommandorPage {
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") {
} else if (model === "ONEPLUS A6000") {
await this.tapForDevice(this.device, 530, 1045)
} else if (model === "CPH2469") {
await this.tapForDevice(this.device, 360, 820)
@@ -1339,27 +1320,33 @@ class CommandorPage {
}
async tapForDevice(device, x, y) {
let cmd = `adb -s ${device.serial} shell input tap ${x} ${y}`
let cmd = `adb -s ${device.serial()} shell input tap ${x} ${y}`
logWithDevice("cmd is " + cmd, this.device)
await exec(cmd);
}
async swipeForDevice(device, x0, y0, x1, y1) {
// let swipCmd = "input swipe " + x + " " + y0 + " " + x + " 1522"
let cmd = `adb -s ${device.serial} shell input swipe ${x0} ${y0} ${x1} ${y1}`
let cmd = `adb -s ${device.serial()} shell input swipe ${x0} ${y0} ${x1} ${y1}`
logWithDevice("cmd is " + cmd, this.device)
await exec(cmd);
}
async inputForDevice(device, text) {
let cmd = `adb -s ${device.serial()} shell input text ${text}`
logWithDevice("cmd is " + cmd, this.device)
await exec(cmd);
}
async clickOnConfirmBtn() {
if (this.device.model === "CPH2219") {
if (this.device.model() === "CPH2219") {
this.device.shell("input tap " + 900 + " " + 1532)
} else if (this.device.model === "MI_5s") {
} else if (this.device.model() === "MI 5s") {
this.device.shell("input tap " + 925 + " " + 1325)
} else if (this.device.model === "22041219PG") {
} else if (this.device.model() === "22041219PG") {
this.device.shell("input tap " + 925 + " " + 1430)
} else if (this.device.model === "moto_g51_5G") {
this.device.shell("input tap " + 950 + " " + 1434)
} 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);
@@ -1367,35 +1354,35 @@ class CommandorPage {
async clickOnHomeBtn() {
// await this.enableDisableAirPlanMode()
if (this.device.model === "22041219PG") {
if (this.device.model() === "22041219PG") {
await this.tapForDevice(this.device, 110, 2208)
await delay(2000);
await openUrlWithAdb(RDV_URL, this.device)
} else if (this.device.model === "KB2003") {
} else if (this.device.model() === "KB2003") {
await this.tapForDevice(this.device, 100, 2289)
await delay(2000);
await openUrlWithAdb(RDV_URL, this.device)
} else if (this.device.model === "21091116C") {
} else if (this.device.model() === "21091116C") {
await this.tapForDevice(this.device, 107, 2193)
await delay(2000);
await openUrlWithAdb(RDV_URL, this.device)
} else if (this.device.model === "MI_5s") {
} else if (this.device.model() === "MI 5s") {
await this.tapForDevice(this.device, 110, 1842)
await delay(2000);
await openUrlWithAdb(RDV_URL, this.device)
} else if (this.device.model === "ASUS_X00QD" || this.device.model === "CPH2219") {
} else if (this.device.model() === "ASUS_X00QD" || this.device.model() === "CPH2219") {
await this.tapForDevice(this.device, 112, 2172)
await delay(2000);
await openUrlWithAdb(RDV_URL, this.device)
} else if (this.device.model === "moto g51 5G") {
} else if (this.device.model() === "moto g51 5G") {
await this.tapForDevice(this.device, 103, 2283)
await delay(2000);
await openUrlWithAdb(RDV_URL, this.device)
} else if (this.device.model === "ONEPLUS_A6000") {
} else if (this.device.model() === "ONEPLUS A6000") {
await this.tapForDevice(this.device, 122, 2172)
await delay(2000);
await openUrlWithAdb(RDV_URL, this.device)
} else if (this.device.model === "DE2117") {
} else if (this.device.model() === "DE2117") {
await this.tapForDevice(this.device, 122, 2172)
await delay(2000);
await openUrlWithAdb(RDV_URL, this.device)
@@ -1409,27 +1396,22 @@ class CommandorPage {
async skipOptimizationPage() {
logWithDevice("skipOptimizationPage", this.device)
let model = this.device.model;
let model = this.device.model();
if (model === "ASUS_X00QD") {
this.device.shell("input tap " + 800 + " " + 2100)
await delay(2000);
this.device.shell("input tap " + 800 + " " + 2100)
await delay(1000);
} else if (model === "ONEPLUS_A6000") {
} else if (model === "ONEPLUS A6000") {
this.device.shell("input tap " + 818 + " " + 2140)
await delay(2000);
this.device.shell("input tap " + 818 + " " + 2140)
await delay(1000);
} else if (model === "moto_g51_5G") {
this.device.shell("input tap " + 806 + " " + 2230)
await delay(2000);
this.device.shell("input tap " + 800 + " " + 2215)
await delay(1000);
} else if (model === "CPH2219") {
this.device.shell("input tap " + 772 + " " + 2146)
await delay(2000);
this.device.shell("input tap " + 772 + " " + 2146)
} else if (model === "MI_5s") {
} else if (model === "MI 5s") {
this.device.shell("input tap " + 786 + " " + 1780)
await delay(2000);
this.device.shell("input tap " + 790 + " " + 1807)
@@ -1444,33 +1426,22 @@ class CommandorPage {
async tapLaterBtn() {
logWithDevice("tapLaterBtn", this.device)
let model = this.device.model;
let model = this.device.model();
log("model is " + model);
if (model === "CPH2219") {
this.device.shell("input tap " + 385 + " " + 1930)
} else if (model === "ASUS_X00QD") {
this.device.shell("input tap " + 490 + " " + 1910)
} else if (model === "RMX3151") {
this.device.shell("input tap " + 492 + " " + 1960)
} else if (model === "Mi Note 10") {
this.device.shell("input tap " + 550 + " " + 1920)
} else if (model === "ONEPLUS_A6000") {
log("will tap on " + model + ": " + 535 + " " + 1930)
this.device.shell("input tap " + 535 + " " + 1930)
await delay(1000);
this.device.shell("input tap " + 535 + " " + 1930)
} else if (model === "DE2117") {
await this.tapForDevice(this.device, 529, 2050)
await delay(1000)
await this.tapForDevice(this.device, 529, 2050)
} else if (model === "ONEPLUS A6000") {
this.device.shell("input tap " + 535 + " " + 1945)
} else if (model === "22041219PG") {
this.device.shell("input tap " + 540 + " " + 1985)
} else if (model === "21091116C") {
this.device.shell("input tap " + 510 + " " + 1975)
} else if (model === "MI_5s") {
} else if (model === "MI 5s") {
this.device.shell("input tap " + 510 + " " + 1615)
} else if (model === "Mi_Note_10") {
await this.tapForDevice(this.device, 498, 1910)
} else
this.device.shell("input tap " + 385 + " " + 2050)
await delay(1000);
@@ -1479,9 +1450,11 @@ 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 {
@@ -1494,27 +1467,27 @@ class CommandorPage {
}
async tapGoogleDisconnectBtn() {
if (this.device.model === "MI_5s") {
if (this.device.model() === "MI 5s") {
if (this.browserPackageName.includes("brave")) {
await this.tapForDevice(this.device, 535, 1629)
} else
await this.device.shell("input tap " + 550 + " " + 1740)
} else {
if (this.browserPackageName.includes("brave") && this.device.model === "CPH2219") {
if (this.browserPackageName.includes("brave") && this.device.model() === "CPH2219") {
await this.device.shell("input tap " + 411 + " " + 1977)
} else if (this.browserPackageName.includes("brave") && this.device.model === "RMX3151") {
} else if (this.browserPackageName.includes("brave") && this.device.model() === "RMX3151") {
await this.device.shell("input tap " + 411 + " " + 1977)
} else if (this.browserPackageName.includes("brave") && this.device.model === "ONEPLUS_A6000") {
} else if (this.browserPackageName.includes("brave") && this.device.model() === "ONEPLUS A6000") {
await this.device.shell("input tap " + 411 + " " + 1970)
} else if (this.browserPackageName.includes("brave") && this.device.model === "ASUS_X00QD") {
} else if (this.browserPackageName.includes("brave") && this.device.model() === "ASUS_X00QD") {
await this.device.shell("input tap " + 411 + " " + 1970)
} else if (this.browserPackageName.includes("brave") && this.device.model === "22041219PG") {
} else if (this.browserPackageName.includes("brave") && this.device.model() === "22041219PG") {
await this.tapForDevice(this.device, 411, 2020)
} else if (this.browserPackageName.includes("brave") && this.device.model === "21091116C") {
} else if (this.browserPackageName.includes("brave") && this.device.model() === "21091116C") {
await this.tapForDevice(this.device, 411, 2020)
} else if (this.browserPackageName.includes("brave") && this.device.model === "M2006C3LG") {//redmi 9a
} else if (this.browserPackageName.includes("brave") && this.device.model() === "M2006C3LG") {//redmi 9a
await this.tapForDevice(this.device, 411, 1300)
} else if (this.browserPackageName.includes("brave") && this.device.model === "220233L2G") {//redmi 9a
} else if (this.browserPackageName.includes("brave") && this.device.model() === "220233L2G") {//redmi 9a
await this.tapForDevice(this.device, 411, 1300)
} else {
await this.tapForDevice(this.device, 411, 2100)
@@ -1542,7 +1515,7 @@ class CommandorPage {
}
async handleBravePushNotification() {
let model = this.device.model
let model = this.device.model()
if (model === "KB2003" || model === "22041219PG" || model === "DE2117" || model === "21091116C") {
await this.tapForDevice(this.device, 545, 1448)
} else
+40 -28
View File
@@ -17,14 +17,13 @@ const NO_INTERNET_FR_2 = "Aucun accès à Internet"
const BRAVE_VPN_SKIP = "Pare-feu + VPN Brave"
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 MESSAGE_URL_VALIDATION_FR_3 = "vous allez recevoir un courriel de notre part"
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 MESSAGE_URL_VALIDATION_EN = "You will receive an email to validate"
const WRONG_PHONE_NUMBER = "Veuillez renseigner vote numéro de téléphone"
const CHOOSE_POSITION_GOOGLE_FR = " Choisir la position pour les résultats de recherche"
const CAPTCHA_ERROR_MESSAGE = "Error verifying captcha, please try again"
const CAPTCHA_ERROR_MESSAGE_FR = "La vérification du captcha a échoué"
const BLOCKED_MSG_EN = "have been blocked"
const BLOCKED_MSG_EN = "has been blocked"
const BLOCKED_MSG_FR = "avez été bloqué"
const BLOCKED_MSG_FR_3 = "a été bloqué"
const BLOCKED_MSG_FR_2 = "Pourquoi ce blocage"
@@ -35,9 +34,8 @@ 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_RETRY_FR = "RÉESSAYER"
const SLIDING_CAPTCHA_EN = "Slide right to complete the puzzle"
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"
@@ -45,14 +43,14 @@ 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_EN = "Appointment request for"
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 = "demande de rendez-vous pour le"
const MESSAGE_FILL_FIELD_EN_4 = "Favorite store"
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 WELCOME_MESSAGE_FR_2 = "Chrome Connectez-vous"
const WELCOME_MESSAGE_FR_3 = "Connectez-Vou's pour"
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"
const PAGE_OPTIMIZATION_CHROME_FR_2 = "Vous pouvez modifier vos options a tout moment"
@@ -77,11 +75,14 @@ const BRAVE_SKIP_PUB_5 = "aucune traceur"
const BRAVE_SKIP_PUB_4 = "aucune publicité"
const BRAVE_SKIP_DEFAULT_PAGE = "confidentialité de Brave"
const BRAVE_SKIP_DEFAULT_PAGE_2 = "définissant Brave"
const BRAVE_SKIP_DEFAULT_PAGE_EN = "With Brave as default"
const BRAVE_SKIP_PRIVACY_PAGE = "Partagez des informations"
const BRAVE_SKIP_PRIVACY_PAGE_EN = "make Brave better"
const BRAVE_SKIP_PRIVACY_PAGE_3 = "Partagez de informations"
const BRAVE_SKIP_PRIVACY_PAGE_2 = "Partagez des renseignements"
const PUSH_NOTIFICATION_1 = "Brave à vous envoyer des notifications"
const PUSH_NOTIFICATION_EN_1 = "Brave to send you notifications"
class OCRChecker {
@@ -101,16 +102,13 @@ class OCRChecker {
try {
let result = await findText(fileName)
console.log(result)
if (result.includes(MESSAGE_URL_VALIDATION_EN)
|| result.includes(MESSAGE_URL_VALIDATION_FR)
|| result.toLowerCase().includes(MESSAGE_URL_VALIDATION_FR_3)
|| result.includes(MESSAGE_URL_VALIDATION_FR_2)) {
if (result.includes(MESSAGE_URL_VALIDATION_EN) || result.includes(MESSAGE_URL_VALIDATION_FR) || result.includes(MESSAGE_URL_VALIDATION_FR_2)) {
await this.deleteFile(fileName)
return OCRResult.SUCCESS
} else if (result.includes(BRAVE_NOTIFICATION)) {
await this.deleteFile(fileName)
return OCRResult.BRAVE_NOTIFICATION
} else if (result.includes(PUSH_NOTIFICATION_1)) {
} else if (result.includes(PUSH_NOTIFICATION_1) || result.includes(PUSH_NOTIFICATION_EN_1)) {
await this.deleteFile(fileName)
return OCRResult.BRAVE_PUSH_NOTIFICATION
} else if (result.includes(CHOOSE_POSITION_GOOGLE_FR)) {
@@ -125,9 +123,21 @@ class OCRChecker {
} else if (result.includes(WRONG_PHONE_NUMBER)) {
await this.deleteFile(fileName)
return OCRResult.WRONG_PHONE_NUMBER
} 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.toLowerCase().includes(MESSAGE_FILL_FIELD_FR_5) || result.includes(MESSAGE_FILL_FIELD_FR_6)) {
} 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_EN_4)
|| result.includes(MESSAGE_FILL_FIELD_FR_5)
|| result.includes(MESSAGE_FILL_FIELD_EN)
|| result.includes(MESSAGE_FILL_FIELD_FR_6)) {
await this.deleteFile(fileName)
return OCRResult.FILL_FIELD
} else if (result.includes(MESSAGE_FILL_FIELD_EN_4)
|| result.includes(MESSAGE_FILL_FIELD_EN)
) {
await this.deleteFile(fileName)
return OCRResult.FILL_FIELD_EN
} else if (result.includes(CAPTCHA_ERROR_MESSAGE) || result.includes(CAPTCHA_ERROR_MESSAGE_FR)) {
return OCRResult.RECAPTCHA_ERROR
} 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)) {
@@ -146,21 +156,20 @@ class OCRChecker {
} else if (result.includes(BRAVE_NOTIFICATION)) {
await this.deleteFile(fileName)
return OCRResult.BRAVE_NOTIFICATION
} 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)) {
} else if (result.includes(SLIDING_CAPTCHA_FR)
|| result.includes(SLIDING_CAPTCHA_EN)
|| 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)) {
if (result.includes(SLIDING_CAPTCHA_LOADING_FR)) {
return OCRResult.SLIDING_CAPTCHA_LOADING
} else {
await this.deleteFile(fileName)
}
// await this.deleteFile(screenShot)
// if (result.includes("rac"))
// return OCRResult.SLIDING_CAPTCHA_REFRESH
return OCRResult.SLIDING_CAPTCHA
} else if (result.includes(SLIDING_CAPTCHA_RETRY_FR)
) {
await this.deleteFile(fileName)
return OCRResult.TERMINAED
} else if (result.includes(WELCOME_MESSAGE_FR)
|| result.includes(WELCOME_MESSAGE_FR_2)
|| result.includes(WELCOME_MESSAGE_FR_3)
) {
} else if (result.includes(WELCOME_MESSAGE_FR)) {
await this.deleteFile(fileName)
return OCRResult.NEED_TO_CLICK_LATE_BTN
} else if (result.includes(GOOGLE_DISCONNECT_FR) || result.includes(GOOGLE_DISCONNECT_FR_1)) {
@@ -192,10 +201,13 @@ class OCRChecker {
} else if (result.includes(NO_INTERNET_FR) || result.includes(NO_INTERNET_FR_2)) {
await this.deleteFile(fileName)
return OCRResult.NO_INTERNET
} else if (result.includes(BRAVE_SKIP_DEFAULT_PAGE) || result.includes(BRAVE_SKIP_DEFAULT_PAGE_2)) {
} else if (result.includes(BRAVE_SKIP_DEFAULT_PAGE) || result.includes(BRAVE_SKIP_DEFAULT_PAGE_EN) || result.includes(BRAVE_SKIP_DEFAULT_PAGE_2)) {
await this.deleteFile(fileName)
return OCRResult.BRAVE_SKIP
} else if (result.includes(BRAVE_SKIP_PRIVACY_PAGE) || result.includes(BRAVE_SKIP_PRIVACY_PAGE_2) || result.includes(BRAVE_SKIP_PRIVACY_PAGE_3)) {
} else if (result.includes(BRAVE_SKIP_PRIVACY_PAGE)
|| result.includes(BRAVE_SKIP_PRIVACY_PAGE_2)
|| result.includes(BRAVE_SKIP_PRIVACY_PAGE_EN)
|| result.includes(BRAVE_SKIP_PRIVACY_PAGE_3)) {
await this.deleteFile(fileName)
return OCRResult.BRAVE_PRIVACY
} else {
@@ -218,9 +230,9 @@ 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("OCRChecker.name is " + name)
let stdout1 = await exec("adb -s " + this.device.serial + " exec-out screencap -p > " + 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}`);
return name
+8 -10
View File
@@ -5,10 +5,8 @@ const axios = require("axios");
const {v4: uuidv4} = require('uuid');
const OCRResult = require("../models/OCRResult");
const DEEPLEARNING_CAPTCHA_HOST = "http://appointment.lpaconsulting.fr:9000"
// const DEEPLEARNING_CAPTCHA_HOST = "http://192.168.1.200:9000"
//const DEEPLEARNING_CAPTCHA_HOST = "http://192.168.0.35:9000"
const DEEPLEARNING_CAPTCHA_HOST = "http://appointment.lpaconsulting.fr:9000"
// const DEEPLEARNING_CAPTCHA_HOST = "http://192.168.0.36:9000"
function delay(delayInMs) {
return new Promise(resolve => {
@@ -32,8 +30,8 @@ class SlidingCaptchaSolver {
}
async take_screen_shot(name, device) {
console.log("will take screenshot for " + device.model + ":" + device.serial)
let stdout1 = await exec("adb -s " + device.serial + " exec-out screencap -p > " + name)
console.log("will take screenshot for " + device.model() + ":" + device.serial())
let stdout1 = await exec("adb -s " + device.serial() + " exec-out screencap -p > " + name)
// await delay(5000);
console.log(`stdout: ${stdout1}`);
await delay(5000);
@@ -49,7 +47,7 @@ class SlidingCaptchaSolver {
//get resolution of screen
console.log("sliding_captcha.sendRequest:" + blockedImageFileName)
await this.sendRequest(blockedImageFileName, async (detectedPositionList) => {
console.log("detectedPosition: " + device.model + ":" + detectedPositionList);
console.log("detectedPosition: " + device.model() + ":" + detectedPositionList);
if (detectedPositionList.length >= 2) {
// #xiaomi
let startPosition = detectedPositionList.filter((positionInfo) => {
@@ -65,7 +63,7 @@ class SlidingCaptchaSolver {
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 touchscreen swipe ${x0} ${y0} ${x1 + width * 0.5} ${y0} ${600 + randomTime}`
let cmd = `adb -s ${device.serial()} shell input touchscreen swipe ${x0} ${y0} ${x1 + width * 0.5} ${y0} ${600 + randomTime}`
await delay(2000);
console.log("cmd is " + cmd);
console.log("will slide captcha");
@@ -74,11 +72,11 @@ class SlidingCaptchaSolver {
await this.deleteFile(blockedImageFileName)
onResult(true)
} else {
console.log("startPosition not found for " + device.model)
console.log("startPosition not found for " + device.model())
onResult(false)
}
} else {
console.log("startPosition not found for " + device.model)
console.log("startPosition not found for " + device.model())
onResult(false)
}
})
+1 -1
View File
@@ -2,6 +2,6 @@ const {startBookWithNumbers} = require('./src/appointment')
const {homedir} = require("os");
homeDir = homedir()
//faubourg, random
startBookWithNumbers(0, 10000, "random", homeDir + "/Desktop/16_04_to_test.xlsx", true, false).then((r) => {
startBookWithNumbers(0, 10000, "random", homeDir + "/Desktop/contact_list_2024-09-19.xlsx", true, false).then((r) => {
console.log(r)
})