15 Commits

Author SHA1 Message Date
panleicim 1d5d6534cb generated more action before validating rdv 2024-12-20 18:19:58 +01:00
panleicim 56347a83f1 add bindSerial param 2024-12-15 11:31:07 +01:00
panleicim f44b83375d support new version 2024-12-04 15:58:09 +01:00
panleicim 703ca3d694 change include mode 2024-12-04 10:59:45 +01:00
panleicim 7cc4f87e0b stop when need to refresh captcha 2024-11-15 22:20:03 +01:00
panleicim 5a2b88139e add appointment mode 2024-11-12 00:22:51 +01:00
panleicim 6ce3a56ce2 support Mi note 10 2024-11-06 14:06:37 +01:00
panleicim f3a7188b31 Merge branch 'master' of bitbucket.org:panleicim/puppeteerjs 2024-10-11 09:33:06 +02:00
panleicim 24f95842ba add shuffle before booking 2024-10-11 09:32:22 +02:00
panleicim 9657007a5b Merge branch 'feature/list_according_serail' 2024-10-05 16:49:15 +02:00
panleicim 9d70bf7097 do not need to bind contact list with mobiles 2024-10-05 16:48:25 +02:00
Lei PAN 9cfa650b31 correction for moto 2024-10-05 08:35:18 +02:00
Lei PAN 87eca37d8b Merge branch 'feature/custom_adb' into feature/list_according_serail 2024-10-01 23:29:00 +02:00
Lei PAN a04ec8373d support moto 2024-10-01 23:28:09 +02:00
panleicim 842f87c784 bind contact list with phone serial 2024-10-01 22:58:32 +02:00
6 changed files with 95 additions and 66 deletions
+49 -30
View File
@@ -8,18 +8,18 @@ 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 excludeMode = DeviceExcludeMode.ZERO
let includeMode = DeviceExcludeMode.ZERO
// let includeMode = DeviceExcludeMode.APPOINTMENT
let three_to_excludes = []
let four_to_excludes = ["bec11752", "4e8ca027", "hi7ljr5xduyt9pfi", "EPHUT20825001518"]
let three_to_include = []
let four_to_include = ["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"]
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"]
// 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"]
attributedPorts = []
const device_port_info = new Map();
startPort = 9000
@@ -63,7 +63,7 @@ async function needToBook(contact, mongoManager, alreadyBooked) {
return needToBook
}
async function startBook(contactPojo, device, sender, selectedStore, audioAnalyse, alertBeep, port) {
async function startBook(contactPojo, device, sender, selectedStore, alertBeep, port) {
console.log(`model: ${device.model}`);
console.log(`serial: ${device.serial}`);
let alreadyBooked = await mongoManager.getAllSuccessfulItemsForDay(collectionName);
@@ -74,7 +74,7 @@ async function startBook(contactPojo, device, sender, selectedStore, audioAnalys
return
}
if (await needToBook(contactPojo, mongoManager, alreadyBooked)) {
let commandor = new CommandorPage(contactPojo, device, sender, mongoManager, selectedStore, audioAnalyse, alertBeep, port);
let commandor = new CommandorPage(contactPojo, device, sender, mongoManager, selectedStore, alertBeep, port);
//read contacts form excel
return await commandor.loadPage();
} else {
@@ -82,14 +82,14 @@ async function startBook(contactPojo, device, sender, selectedStore, audioAnalys
}
}
async function startWithList(contacts, device, sender, selectedStore, audioAnalyse, alertBeep, port) {
async function startWithList(contacts, device, sender, selectedStore, 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, audioAnalyse, alertBeep, port);
const contents = await startBook(contactPojo, device, sender, selectedStore, alertBeep, port);
console.log(contents);
}, Promise.resolve());
}
@@ -118,9 +118,17 @@ function shuffle(array) {
return array;
}
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)
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) {
let allContactList = excelUtil.readContacts(pathToExcelFile);
let contactList;
if (endNumber <= allContactList.length) {
@@ -151,8 +159,6 @@ async function startBookWithNumbers(startNumber, endNumber, selectedStore, pathT
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
}
@@ -170,28 +176,41 @@ async function startBookWithNumbers(startNumber, endNumber, selectedStore, pathT
alert("未找到连接的设备");
return
}
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) {
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) {
device_to_excludes = seven_to_excludes
} else if (excludeMode === DeviceExcludeMode.SIX) {
device_to_excludes = six_to_excludes
} else if (excludeMode === DeviceExcludeMode.ZERO) {
device_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))
}
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)
startWithList(listWithoutBlackContact.slice(i * segmentNumber, segmentNumber * (i + 1)), device, sender, selectedStore, audioAnalyse, alertBeep, port);
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);
}
})
+3 -2
View File
@@ -19,11 +19,12 @@ class ExcelUtil {
if (store === undefined || store.length === 0) {
store = "random"
}
let ipCountry = info[5];
let serial = info[5];
let ipCountry = info[6];
if (ipCountry === undefined || ipCountry.length === 0) {
ipCountry = "FR"
}
let newContact = new ContactPojo(phoneNumber, passportNumber, lastName, firstName, mail, store, ipCountry);
let newContact = new ContactPojo(phoneNumber, passportNumber, lastName, firstName, mail, store, ipCountry, serial);
contactList.push(newContact);
}
}
+2 -1
View File
@@ -1,6 +1,6 @@
class ContactPojo {
constructor(phoneNumber, passportNumber, lastName, firstName, mail, store, ipCountry) {
constructor(phoneNumber, passportNumber, lastName, firstName, mail, store, ipCountry, serial) {
this.phoneNumber = phoneNumber;
this.passportNumber = passportNumber;
this.lastName = lastName;
@@ -8,6 +8,7 @@ class ContactPojo {
this.mail = mail;
this.store = store;
this.ipCountry = ipCountry;
this.serial = serial;
}
}
+3 -2
View File
@@ -1,9 +1,10 @@
const DeviceExcludeMode = {
const DeviceIncludeMode = {
ZERO: Symbol("ZERO"),
NINE: Symbol("NINE"),
THREE: Symbol("THREE"),
SIX: Symbol("SIX"),
SEVEN: Symbol("SEVEN"),
APPOINTMENT: Symbol("APPOINTMENT"),
FOUR: Symbol("FOUR")
}
module.exports = DeviceExcludeMode
module.exports = DeviceIncludeMode
+31 -25
View File
@@ -11,6 +11,7 @@ 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"
@@ -50,6 +51,12 @@ 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
}
@@ -77,7 +84,7 @@ function logWithDevice(message, device) {
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, audioAnalyse = false, alertBeep = false, port = 9000, shareCookiesWithRequests = true) {
constructor(contact, device, sender, mongoManager, selectedStore = DEFAULT_STORE, 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
@@ -401,12 +408,12 @@ class CommandorPage {
// 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) => {
@@ -422,7 +429,6 @@ class CommandorPage {
let field = document.getElementById("name");
if (field) {
field.value = firstName;
// field.value = ""
}
}, this.contact.firstName)
// await page.keyboard.type(this.contact.firstName);
@@ -505,10 +511,8 @@ 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
@@ -581,9 +585,15 @@ class CommandorPage {
}
}
async clickValid() {
logWithDevice("clickValid() called.", this.device);
await delay(getRandomWaitTime())
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()) {
@@ -612,7 +622,7 @@ class CommandorPage {
this.contact.firstName = raw.firstName
}
await this.page.evaluate(() => {
document.getElementsByClassName("btn")[0].click();
document.getElementsByTagName("button")[1].click();
})
if (this.firstStart) {
this.disconnectBrowser();
@@ -886,9 +896,11 @@ class CommandorPage {
this.isTerminated = true;
break;
case OCRResult.SLIDING_CAPTCHA_REFRESH:
await this.connect_to_browser(checkResult)
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)
@@ -901,7 +913,7 @@ class CommandorPage {
await this.checkResultWithOcr()
}
})
// await delay(5 * 1000)
await delay(5 * 1000)
break;
case OCRResult.FILL_FIELD:
logWithDevice("FILL_FIELD", this.device)
@@ -964,8 +976,6 @@ class CommandorPage {
}
})
await this.page.bringToFront();
// this.page = pages;
// this.page.await
await this.fillFields(this.page)
await delay(2 * 1000);
}
@@ -1341,12 +1351,6 @@ class CommandorPage {
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") {
this.device.shell("input tap " + 900 + " " + 1532)
@@ -1354,8 +1358,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 if (this.device.model === "moto_g51_5G") {
this.device.shell("input tap " + 950 + " " + 1434)
} else
this.device.shell("input tap " + 933 + " " + 1538)
await delay(2000);
@@ -1417,7 +1421,7 @@ class CommandorPage {
this.device.shell("input tap " + 818 + " " + 2140)
await delay(1000);
} else if (model === "moto_g51_5G") {
await this.tapForDevice(this.device, 800, 2215)
this.device.shell("input tap " + 806 + " " + 2230)
await delay(2000);
this.device.shell("input tap " + 800 + " " + 2215)
await delay(1000);
@@ -1465,6 +1469,8 @@ class CommandorPage {
this.device.shell("input tap " + 510 + " " + 1975)
} 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);
+7 -6
View File
@@ -17,6 +17,7 @@ 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 WRONG_PHONE_NUMBER = "Veuillez renseigner vote numéro de téléphone"
@@ -47,7 +48,7 @@ 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_5 = "demande de rendez-vous pour le"
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"
@@ -100,7 +101,10 @@ 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.includes(MESSAGE_URL_VALIDATION_FR_2)) {
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)) {
await this.deleteFile(fileName)
return OCRResult.SUCCESS
} else if (result.includes(BRAVE_NOTIFICATION)) {
@@ -121,7 +125,7 @@ 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.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.toLowerCase().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)) {
@@ -148,9 +152,6 @@ class OCRChecker {
} 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)
) {