can send appointment request
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
const {_android: android} = require("playwright");
|
||||
const SolveCaptcha = require("./SolveCaptcha");
|
||||
const ReserveResultPojo = require("../models/ReserveResultPojo");
|
||||
const PublishType = require("../models/PublishType");
|
||||
const {aws4} = require("mongodb/src/deps");
|
||||
|
||||
// const RDV_URL = "http://192.168.0.44:8000/test_appointment.html"
|
||||
const RDV_URL = "https://rendezvousparis.hermes.com/client/register";
|
||||
@@ -41,34 +44,36 @@ function getRandomWaitTime() {
|
||||
}
|
||||
|
||||
class CommandorPage {
|
||||
constructor(contact) {
|
||||
constructor(contact, device, mongoManager) {
|
||||
this.contact = contact;
|
||||
this.device = device;
|
||||
this.mongoManager = mongoManager;
|
||||
this.isFillingFields = false;
|
||||
}
|
||||
|
||||
async loadPage() {
|
||||
// Connect to the device.
|
||||
const [device] = await android.devices();
|
||||
console.log(`Model: ${device.model()}`);
|
||||
console.log(`Serial: ${device.serial()}`);
|
||||
{
|
||||
// --------------------- Browser -----------------------
|
||||
// Launch Chrome browser.
|
||||
await device.shell('am force-stop com.android.chrome');
|
||||
const context = await device.launchBrowser({command: '--incognito'});
|
||||
console.log("loadPage() called");
|
||||
|
||||
// --------------------- Browser -----------------------
|
||||
// Launch Chrome browser.
|
||||
await this.device.shell('am force-stop com.android.chrome');
|
||||
const context = await this.device.launchBrowser({command: '--incognito'});
|
||||
|
||||
// Use BrowserContext as usual.
|
||||
this.page = await context.newPage();
|
||||
this.page.on("load", (loaddePage) => {
|
||||
this.onPageLoad(loaddePage)
|
||||
})
|
||||
await this.page.goto(RDV_URL);
|
||||
// await this.fillFields(page)
|
||||
console.log(await this.page.evaluate(() => window.location.href));
|
||||
//wait 10 mins
|
||||
await delay(10 * 60 * 1000);
|
||||
|
||||
// Use BrowserContext as usual.
|
||||
const page = await context.newPage();
|
||||
this.page = page
|
||||
page.on("load", this.onPageLoad)
|
||||
await page.goto(RDV_URL);
|
||||
// await this.fillFields(page)
|
||||
console.log(await page.evaluate(() => window.location.href));
|
||||
//wait 10 mins
|
||||
await delay(10 * 60 * 1000);
|
||||
}
|
||||
|
||||
// Close the device.
|
||||
await device.close();
|
||||
await this.device.close();
|
||||
}
|
||||
|
||||
async chooseCountry(page) {
|
||||
@@ -78,7 +83,7 @@ class CommandorPage {
|
||||
await delay(getRandomWaitTime())
|
||||
await page.selectOption(COUNTRY_ID, 'FR');
|
||||
await delay(getRandomWaitTime())
|
||||
await page.click(COUNTRY_ID);
|
||||
// await page.click(COUNTRY_ID);
|
||||
}
|
||||
|
||||
async fillEmail(page) {
|
||||
@@ -125,26 +130,29 @@ class CommandorPage {
|
||||
|
||||
|
||||
async fillFields(page) {
|
||||
await this.chooseStore(page)
|
||||
await this.inputName(page)
|
||||
await this.chooseCountry(page);
|
||||
await this.inputPhoneNumber(page)
|
||||
await this.fillEmail(page)
|
||||
await this.inputPhoneNumber(page)
|
||||
await this.inputPassportId(page)
|
||||
await this.checkCGU(page)
|
||||
await this.resolveCaptcha(page)
|
||||
await delay(100 * 1000)
|
||||
if (!this.isFillingFields) {
|
||||
this.isFillingFields = true;
|
||||
await this.chooseStore(page);
|
||||
await this.inputName(page);
|
||||
await this.chooseCountry(page);
|
||||
await this.inputPhoneNumber(page)
|
||||
await this.fillEmail(page)
|
||||
await this.inputPhoneNumber(page)
|
||||
await this.inputPassportId(page)
|
||||
await this.checkCGU(page)
|
||||
await this.resolveCaptcha(page)
|
||||
await delay(100 * 1000)
|
||||
}
|
||||
}
|
||||
|
||||
async clickValid(page) {
|
||||
await delay(getRandomWaitTime())
|
||||
try {
|
||||
page.evaluate(() => {
|
||||
this.page.evaluate(() => {
|
||||
document.getElementsByClassName("btn")[0].focus();
|
||||
})
|
||||
await delay(getRandomWaitTime())
|
||||
page.evaluate(() => {
|
||||
this.page.evaluate(() => {
|
||||
document.getElementsByClassName("btn")[0].click();
|
||||
})
|
||||
} catch (e) {
|
||||
@@ -163,30 +171,32 @@ class CommandorPage {
|
||||
})
|
||||
}
|
||||
|
||||
async onPageLoad() {
|
||||
let content = await this.page.content();
|
||||
async onPageLoad(currentPage) {
|
||||
let content = await currentPage.content();
|
||||
let captcha_url = "geo.captcha-delivery.com/captcha"
|
||||
|
||||
if (content.toString().includes(captcha_url)) {
|
||||
console.log("we are blockeds")
|
||||
console.log("we are blocked")
|
||||
} else {
|
||||
if (this.page.url() === RDV_URL) {
|
||||
await this.fillFields()
|
||||
if (currentPage.url() === RDV_URL) {
|
||||
await this.fillFields(this.page)
|
||||
} else {
|
||||
if (content.includes(MESSAGE_URL_VALIDATION_FR)) {
|
||||
console.log("successful")
|
||||
this.push_message_to_queue(PublishType.SUCCESS)
|
||||
await this.push_message_to_queue(PublishType.SUCCESS)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
push_message_to_queue(publishType) {
|
||||
async push_message_to_queue(publishType) {
|
||||
let url = this.page.url()
|
||||
if (url === "https://rendezvousparis.hermes.com/client/welcome") {
|
||||
return
|
||||
}
|
||||
|
||||
// save to mongoDb
|
||||
let reserve = ReserveResultPojo.create_from_contact(this.contact, this.page.url(), 1, publishType)
|
||||
await this.mongoManager.saveReserveToDb(reserve)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user