can send appointment request

This commit is contained in:
2022-09-07 19:38:29 +02:00
parent 6266083ab8
commit b0d52afc00
5 changed files with 74 additions and 72 deletions
+11 -11
View File
@@ -1,10 +1,7 @@
const {_android: android} = require('playwright');
const ExcelUtil = require("./src/excel/ExcelUtil");
const CommandorPage = require("./src/workers/CommandorPage");
const RDV_URL = "https://rendezvousparis.hermes.com/client/register";
// const RDV_URL = "https://bot.sannysoft.com/";
// const RDV_URL = "http://192.168.0.44:8000/test_appointment.html"
const MongoManager = require("./src/workers/mongo_manager");
function delay(delayInms) {
return new Promise(resolve => {
@@ -14,15 +11,18 @@ function delay(delayInms) {
});
}
const mongoManager = new MongoManager();
mongoManager.connect()
let excelUtil = new ExcelUtil();
let contactList = excelUtil.readContacts();
let commandor = new CommandorPage(contactList[2]);
// (async () => {
(async () => {
// Connect to the device.
const [device] = await android.devices();
console.log(`Model: ${device.model()}`);
console.log(`Serial: ${device.serial()}`);
const [device] = await android.devices();
console.log(`Model: ${device.model()}`);
console.log(`Serial: ${device.serial()}`);
let commandor = new CommandorPage(contactList[3], device, mongoManager);
//read contacts form excel
await commandor.loadPage();
await commandor.loadPage();
// Take screenshot of the whole device.
// })();
})();
+3 -1
View File
@@ -3,4 +3,6 @@ const PublishType = {
ERROR: "ERROR",
PENDING: "PENDING",
DUPLICATED: "DUPLICATED",
}
}
module.exports = PublishType
+7 -3
View File
@@ -1,5 +1,8 @@
const PublishType = require("./PublishType");
class ReserveResultPojo {
constructor(id, phoneNumber, passportNumber, mail, lastName, firstName, storeType, url) {
constructor(id, phoneNumber, passportNumber, mail, lastName, firstName, storeType, url, type = PublishType.ERROR) {
this.id = id;
this.phoneNumber = phoneNumber;
this.passportNumber = passportNumber;
@@ -8,6 +11,7 @@ class ReserveResultPojo {
this.storeType = storeType;
this.url = url;
this.mail = mail;
this.type = type;
}
to_mongo_dict() {
@@ -23,8 +27,8 @@ class ReserveResultPojo {
}
}
static create_from_contact(contactPojo, id, url, storeType) {
return new ReserveResultPojo(id, contactPojo.phoneNumber, contactPojo.passportNumber, contactPojo.mail, contactPojo.lastName, contactPojo.firstName, storeType, url);
static create_from_contact(contactPojo, id, url, storeType, type) {
return new ReserveResultPojo(id, contactPojo.phoneNumber, contactPojo.passportNumber, contactPojo.mail, contactPojo.lastName, contactPojo.firstName, storeType, url, type);
}
}
+51 -41
View File
@@ -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)
}
}
+2 -16
View File
@@ -7,11 +7,6 @@ const ACCEPTED_APPOINTMENT_LIST = "ACCEPTED_APPOINTMENT_LIST"
const EMAIL_LIST = "EMAIL_LIST"
const DESTINATION_EMAIL_LIST = "DESTINATION_EMAIL_LIST"
const mongoose = require("mongoose");
mongoose.Promise = global.Promise;
mongoose.connect(`mongodb://${MONGO_DB_URL}:27017/appointment`);
const {MongoClient} = require('mongodb');
const ReserveResultPojo = require("../models/ReserveResultPojo");
const ContactPojo = require("../models/ContactPojo");
@@ -52,14 +47,5 @@ class MongoManager {
}
}
let manag = new MongoManager();
(async () => {
await manag.connect()
// console.log(await manag.getAllSuccessfulItemsForDay('2022-09-06'))
// let reserv = new ReserveResultPojo('U4S4RN', '753426925', '84838026', "gnautaurasa@hotmail.com", 'jingyi', 'DU', 1, 'https://rendezvousparis.hermes.com/client/register/U4S4RN');
let contact = new ContactPojo('753426925', '84838026', 'DU', 'jingyi',
"gnautaurasa@hotmail.com"
);
let reserv = ReserveResultPojo.create_from_contact(contact, 'U4S4RN', 'https://rendezvousparis.hermes.com/client/register/U4S4RN', 1)
await manag.saveReserveToDb(reserv.to_mongo_dict());
})()
module.exports = MongoManager