not work on xiaomi

This commit is contained in:
2023-05-18 11:06:41 +02:00
parent 0e868536df
commit 465861a5ab
3 changed files with 57 additions and 44 deletions
+2
View File
@@ -20,6 +20,8 @@
"node-wget": "^0.4.3", "node-wget": "^0.4.3",
"node-xlsx": "^0.21.0", "node-xlsx": "^0.21.0",
"playwright": "^1.32.1", "playwright": "^1.32.1",
"puppeteer": "^1.13.0",
"ws": "^6.2.0",
"read-ini-file": "^3.0.1", "read-ini-file": "^3.0.1",
"uuid": "^9.0.0", "uuid": "^9.0.0",
"winston": "^3.8.2", "winston": "^3.8.2",
+4 -2
View File
@@ -11,7 +11,8 @@ const NINETY_DAYS_IN_S = 3600 * 24 * 30 * 3;
let excelUtil = new ExcelUtil(); let excelUtil = new ExcelUtil();
let collectionName = formatDate(new Date()) let collectionName = formatDate(new Date())
// device_to_excludes = ["47e7e36b", "e30eb015"] // device_to_excludes = ["47e7e36b", "e30eb015"]
device_to_excludes = ["47e7e36b"] // device_to_excludes = ["47e7e36b"]
device_to_excludes = []
async function filterAlreadyBookedContacts(contactList) { async function filterAlreadyBookedContacts(contactList) {
let alreadyBookedContacts = await mongoManager.getAllSuccessfulItemsForDay(collectionName); let alreadyBookedContacts = await mongoManager.getAllSuccessfulItemsForDay(collectionName);
@@ -117,7 +118,8 @@ async function startBook(contactPojo, device, selectedStore, audioAnalyse, alert
if (await needToBook(contactPojo, mongoManager)) { if (await needToBook(contactPojo, mongoManager)) {
let commandor = new CommandorPage(contactPojo, device, mongoManager, selectedStore, audioAnalyse, alertBeep); let commandor = new CommandorPage(contactPojo, device, mongoManager, selectedStore, audioAnalyse, alertBeep);
//read contacts form excel //read contacts form excel
return await commandor.loadPage(); let port = 9222;
return await commandor.loadPage(port);
} else { } else {
console.log("do not send request --> skip") console.log("do not send request --> skip")
} }
+51 -42
View File
@@ -3,13 +3,16 @@ const ReserveResultPojo = require("../models/ReserveResultPojo");
const BlackListContactPojo = require("../models/BlackListContactPojo"); const BlackListContactPojo = require("../models/BlackListContactPojo");
const appointmentLogger = require("../utiles/LoggerUtils") const appointmentLogger = require("../utiles/LoggerUtils")
const PublishType = require("../models/PublishType"); const PublishType = require("../models/PublishType");
const puppeteer = require('puppeteer');
const { const {
shell shell
} = require('electron') } = require('electron')
const GeoCaptchaSolver = require("./GeoCaptchaSolver"); const GeoCaptchaSolver = require("./GeoCaptchaSolver");
const SlidingCaptchaSolver = require("./SlidingCaptchaSolver"); const SlidingCaptchaSolver = require("./SlidingCaptchaSolver");
// const RDV_URL = "http://192.168.0.41:8000/test_appointment.html" const {de} = require("yarn/lib/cli");
const RDV_URL = "https://rendezvousparis.hermes.com/client/register"; 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" const BLANK_URL = "about:blank"
const ERROR_CAPTCHA_UNSOLVABLE = "ERROR_CAPTCHA_UNSOLVABLE"; const ERROR_CAPTCHA_UNSOLVABLE = "ERROR_CAPTCHA_UNSOLVABLE";
@@ -83,15 +86,15 @@ class CommandorPage {
} }
async loadPage() { async loadPage(port) {
// Connect to the device. // Connect to the device.
log("loadPage() called"); log("loadPage() called");
// await this.device.shell('am force-stop com.android.chrome');
try { try {
this.context = await this.device.launchBrowser(); this.browser = await puppeteer.connect({browserWSEndpoint: 'ws://127.0.0.1:9002/devtools/browser',})
// await context.clearCookies() // await context.clearCookies()
// Use BrowserContext as usual. // Use BrowserContext as usual.
this.page = await this.context.newPage(); this.page = await this.browser.newPage();
this.page.on("load", (loadedPage) => { this.page.on("load", (loadedPage) => {
this.onPageLoad(loadedPage) this.onPageLoad(loadedPage)
}) })
@@ -100,26 +103,31 @@ class CommandorPage {
this.onResponse(response) this.onResponse(response)
}) })
} catch (e) { } catch (e) {
log(e) console.log(e)
this.isTerminated = true this.isTerminated = true
} }
try { try {
console.log("will open google")
const item = searchTexts[Math.floor(Math.random() * searchTexts.length)]; const item = searchTexts[Math.floor(Math.random() * searchTexts.length)];
await this.page.goto("https://www.google.com/search?q=" + item + "&lr=lang_en", {timeout: 90 * 1000}); await this.page.goto("https://www.google.com/search?q=" + item + "&lr=lang_en", {timeout: 90 * 1000});
// await this.page.goto(RDV_URL, {timeout: 90 * 1000});
} catch (e) { } catch (e) {
log(e) log(e)
this.isTerminated = true this.isTerminated = true
} }
try { try {
if (this.page.url().includes("google")) if (this.page.url().includes("google")) {
this.page.locator('button >> nth=3').click() this.page.focus('button >> nth=3')
this.page.click()
}
} catch (e) { } catch (e) {
log(e) log(e)
} }
try { try {
// await this.setUpCookies() // await this.setUpCookies()
this.page.locator(':nth-match(:text("rendezvousparis"), 1)').click() await this.page.focus(':nth-match(:text("rendezvousparis"), 1)')
await this.page.click()
} catch (e) { } catch (e) {
log(e) log(e)
if (!this.page.url().includes(RDV_URL)) { if (!this.page.url().includes(RDV_URL)) {
@@ -131,13 +139,13 @@ class CommandorPage {
const intervalTask = setInterval(() => { const intervalTask = setInterval(() => {
if (this.isTerminated) { if (this.isTerminated) {
log(this.device.model() + ":request terminated, will close device"); log(this.device.model() + ":request terminated, will close device");
if (this.context !== undefined) if (this.browser !== undefined)
this.context.close(); this.browser.close();
// this.page.close() // this.page.close()
// this.device.close() // this.device.close()
clearInterval(intervalTask) clearInterval(intervalTask)
cancel() cancel()
return this.context return this.browser
} else { } else {
if (this.page.url() === RDV_URL) { if (this.page.url() === RDV_URL) {
if (!this.isFillingFields) if (!this.isFillingFields)
@@ -158,11 +166,11 @@ class CommandorPage {
if (!page.isClosed()) { if (!page.isClosed()) {
try { try {
if (!this.isCountryChoosen) { if (!this.isCountryChoosen) {
await page.locator(COUNTRY_ID).focus(); await page.focus(COUNTRY_ID);
await delay(getRandomWaitTime()) await delay(getRandomWaitTime())
await page.click(COUNTRY_ID); await page.click(COUNTRY_ID);
await delay(getRandomWaitTime()) await delay(getRandomWaitTime())
await page.selectOption(COUNTRY_ID, 'FR'); await page.select(COUNTRY_ID, 'FR');
await delay(getRandomWaitTime()) await delay(getRandomWaitTime())
this.isCountryChoosen = true; this.isCountryChoosen = true;
} }
@@ -177,9 +185,9 @@ class CommandorPage {
try { try {
if (!page.isClosed()) { if (!page.isClosed()) {
if (!this.isEmailFilled) { if (!this.isEmailFilled) {
await page.locator(EMAIL_ID).focus(); await page.focus(EMAIL_ID);
await delay(getRandomWaitTime()) await delay(getRandomWaitTime())
await page.locator(EMAIL_ID).fill(this.contact.mail); await page.keyboard.type(this.contact.mail);
this.isEmailFilled = true; this.isEmailFilled = true;
} }
} }
@@ -192,8 +200,8 @@ class CommandorPage {
try { try {
if (!page.isClosed()) { if (!page.isClosed()) {
if (!this.isPhoneInput) { if (!this.isPhoneInput) {
await page.locator(PHONE_NUMBER).focus(); await page.focus(PHONE_NUMBER);
await page.locator(PHONE_NUMBER).fill("+330" + this.contact.phoneNumber); await page.keyboard.type("+330" + this.contact.phoneNumber);
this.isPhoneInput = true; this.isPhoneInput = true;
} }
} }
@@ -208,13 +216,13 @@ class CommandorPage {
try { try {
if (!page.isClosed()) { if (!page.isClosed()) {
if (!this.isNameInput) { if (!this.isNameInput) {
await page.locator(LAST_NAME).focus() await page.focus(LAST_NAME);
await delay(getRandomWaitTime()) await delay(getRandomWaitTime());
await page.locator(LAST_NAME).fill(this.contact.lastName) await page.keyboard.type(this.contact.lastName);
await page.locator(FIRST_NAME).focus() await page.focus(FIRST_NAME);
await delay(getRandomWaitTime()) await delay(getRandomWaitTime());
await page.locator(FIRST_NAME).fill(this.contact.firstName) await page.keyboard.type(this.contact.firstName);
this.isNameInput = true this.isNameInput = true;
} }
} }
} catch (e) { } catch (e) {
@@ -227,9 +235,9 @@ class CommandorPage {
try { try {
if (!page.isClosed()) { if (!page.isClosed()) {
if (!this.isPasspordInput) { if (!this.isPasspordInput) {
await page.locator(PASSPORT_ID).focus(); await page.focus(PASSPORT_ID);
await delay(getRandomWaitTime()); await delay(getRandomWaitTime());
await page.locator(PASSPORT_ID).fill(this.contact.passportNumber.toString()); await page.keyboard.type(this.contact.passportNumber.toString())
this.isPasspordInput = true; this.isPasspordInput = true;
} }
} }
@@ -244,11 +252,11 @@ class CommandorPage {
try { try {
if (!page.isClosed()) { if (!page.isClosed()) {
if (!this.cguChecked) { if (!this.cguChecked) {
await page.locator(CGU_ID).focus() await page.focus(CGU_ID);
await page.locator(CGU_ID).click() await page.click(CGU_ID);
await delay(getRandomWaitTime()) await delay(getRandomWaitTime());
await page.locator(PROCESSING_ID).focus() await page.focus(PROCESSING_ID);
await page.locator(PROCESSING_ID).click() await page.click(PROCESSING_ID)
this.cguChecked = true; this.cguChecked = true;
} }
} }
@@ -262,12 +270,12 @@ class CommandorPage {
try { try {
if (!page.isClosed()) { if (!page.isClosed()) {
if (this.selectedStore !== "random") { if (this.selectedStore !== "random") {
await page.locator(PREFER_STORE).focus() page.focus(PREFER_STORE);
await delay(1000) await delay(1000)
await page.click(PREFER_STORE); page.click(PREFER_STORE);
let stores = this.selectedStore.split(":") let stores = this.selectedStore.split(":")
this.choosedStore = stores[Math.floor(Math.random() * stores.length)] this.choosedStore = stores[Math.floor(Math.random() * stores.length)]
await page.selectOption(PREFER_STORE, this.choosedStore); await page.select(PREFER_STORE, this.choosedStore);
} }
} }
} catch (e) { } catch (e) {
@@ -326,7 +334,8 @@ class CommandorPage {
async resolveCaptcha(page) { async resolveCaptcha(page) {
if (RDV_URL.includes("192")) { if (RDV_URL.includes("192")) {
await this.push_message_to_queue(PublishType.SUCCESS) // await this.push_message_to_queue(PublishType.SUCCESS)
await delay(100000)
return return
} }
//check whether there is captcha //check whether there is captcha
@@ -552,11 +561,11 @@ class CommandorPage {
this.isTerminated = true; this.isTerminated = true;
} else { } else {
try { try {
let errorItem = this.page.locator("div.alert"); // let errorItem = this.page.locator("div.alert");
if (errorItem) { // if (errorItem) {
let errorContent = await errorItem.innerHTML(); // let errorContent = await errorItem.innerHTML();
await this.handleError(errorContent); // await this.handleError(errorContent);
} // }
} catch (e) { } catch (e) {
log(e); log(e);
} }