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 {_android: android} = require('playwright');
const ExcelUtil = require("./src/excel/ExcelUtil"); const ExcelUtil = require("./src/excel/ExcelUtil");
const CommandorPage = require("./src/workers/CommandorPage"); const CommandorPage = require("./src/workers/CommandorPage");
const MongoManager = require("./src/workers/mongo_manager");
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"
function delay(delayInms) { function delay(delayInms) {
return new Promise(resolve => { return new Promise(resolve => {
@@ -14,15 +11,18 @@ function delay(delayInms) {
}); });
} }
const mongoManager = new MongoManager();
mongoManager.connect()
let excelUtil = new ExcelUtil(); let excelUtil = new ExcelUtil();
let contactList = excelUtil.readContacts(); let contactList = excelUtil.readContacts();
let commandor = new CommandorPage(contactList[2]); (async () => {
// (async () => {
// Connect to the device. // Connect to the device.
const [device] = await android.devices(); const [device] = await android.devices();
console.log(`Model: ${device.model()}`); console.log(`Model: ${device.model()}`);
console.log(`Serial: ${device.serial()}`); console.log(`Serial: ${device.serial()}`);
let commandor = new CommandorPage(contactList[3], device, mongoManager);
//read contacts form excel //read contacts form excel
await commandor.loadPage(); await commandor.loadPage();
// Take screenshot of the whole device. // Take screenshot of the whole device.
// })(); })();
+2
View File
@@ -4,3 +4,5 @@ const PublishType = {
PENDING: "PENDING", PENDING: "PENDING",
DUPLICATED: "DUPLICATED", DUPLICATED: "DUPLICATED",
} }
module.exports = PublishType
+7 -3
View File
@@ -1,5 +1,8 @@
const PublishType = require("./PublishType");
class ReserveResultPojo { 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.id = id;
this.phoneNumber = phoneNumber; this.phoneNumber = phoneNumber;
this.passportNumber = passportNumber; this.passportNumber = passportNumber;
@@ -8,6 +11,7 @@ class ReserveResultPojo {
this.storeType = storeType; this.storeType = storeType;
this.url = url; this.url = url;
this.mail = mail; this.mail = mail;
this.type = type;
} }
to_mongo_dict() { to_mongo_dict() {
@@ -23,8 +27,8 @@ class ReserveResultPojo {
} }
} }
static create_from_contact(contactPojo, id, url, storeType) { 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); 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 {_android: android} = require("playwright");
const SolveCaptcha = require("./SolveCaptcha"); 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 = "http://192.168.0.44:8000/test_appointment.html"
const RDV_URL = "https://rendezvousparis.hermes.com/client/register"; const RDV_URL = "https://rendezvousparis.hermes.com/client/register";
@@ -41,34 +44,36 @@ function getRandomWaitTime() {
} }
class CommandorPage { class CommandorPage {
constructor(contact) { constructor(contact, device, mongoManager) {
this.contact = contact; this.contact = contact;
this.device = device;
this.mongoManager = mongoManager;
this.isFillingFields = false;
} }
async loadPage() { async loadPage() {
// Connect to the device. // Connect to the device.
const [device] = await android.devices(); console.log("loadPage() called");
console.log(`Model: ${device.model()}`);
console.log(`Serial: ${device.serial()}`); // --------------------- Browser -----------------------
{ // Launch Chrome browser.
// --------------------- Browser ----------------------- await this.device.shell('am force-stop com.android.chrome');
// Launch Chrome browser. const context = await this.device.launchBrowser({command: '--incognito'});
await device.shell('am force-stop com.android.chrome');
const context = await 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. // Close the device.
await device.close(); await this.device.close();
} }
async chooseCountry(page) { async chooseCountry(page) {
@@ -78,7 +83,7 @@ class CommandorPage {
await delay(getRandomWaitTime()) await delay(getRandomWaitTime())
await page.selectOption(COUNTRY_ID, 'FR'); await page.selectOption(COUNTRY_ID, 'FR');
await delay(getRandomWaitTime()) await delay(getRandomWaitTime())
await page.click(COUNTRY_ID); // await page.click(COUNTRY_ID);
} }
async fillEmail(page) { async fillEmail(page) {
@@ -125,26 +130,29 @@ class CommandorPage {
async fillFields(page) { async fillFields(page) {
await this.chooseStore(page) if (!this.isFillingFields) {
await this.inputName(page) this.isFillingFields = true;
await this.chooseCountry(page); await this.chooseStore(page);
await this.inputPhoneNumber(page) await this.inputName(page);
await this.fillEmail(page) await this.chooseCountry(page);
await this.inputPhoneNumber(page) await this.inputPhoneNumber(page)
await this.inputPassportId(page) await this.fillEmail(page)
await this.checkCGU(page) await this.inputPhoneNumber(page)
await this.resolveCaptcha(page) await this.inputPassportId(page)
await delay(100 * 1000) await this.checkCGU(page)
await this.resolveCaptcha(page)
await delay(100 * 1000)
}
} }
async clickValid(page) { async clickValid(page) {
await delay(getRandomWaitTime()) await delay(getRandomWaitTime())
try { try {
page.evaluate(() => { this.page.evaluate(() => {
document.getElementsByClassName("btn")[0].focus(); document.getElementsByClassName("btn")[0].focus();
}) })
await delay(getRandomWaitTime()) await delay(getRandomWaitTime())
page.evaluate(() => { this.page.evaluate(() => {
document.getElementsByClassName("btn")[0].click(); document.getElementsByClassName("btn")[0].click();
}) })
} catch (e) { } catch (e) {
@@ -163,30 +171,32 @@ class CommandorPage {
}) })
} }
async onPageLoad() { async onPageLoad(currentPage) {
let content = await this.page.content(); let content = await currentPage.content();
let captcha_url = "geo.captcha-delivery.com/captcha" let captcha_url = "geo.captcha-delivery.com/captcha"
if (content.toString().includes(captcha_url)) { if (content.toString().includes(captcha_url)) {
console.log("we are blockeds") console.log("we are blocked")
} else { } else {
if (this.page.url() === RDV_URL) { if (currentPage.url() === RDV_URL) {
await this.fillFields() await this.fillFields(this.page)
} else { } else {
if (content.includes(MESSAGE_URL_VALIDATION_FR)) { if (content.includes(MESSAGE_URL_VALIDATION_FR)) {
console.log("successful") 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() let url = this.page.url()
if (url === "https://rendezvousparis.hermes.com/client/welcome") { if (url === "https://rendezvousparis.hermes.com/client/welcome") {
return 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 EMAIL_LIST = "EMAIL_LIST"
const DESTINATION_EMAIL_LIST = "DESTINATION_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 {MongoClient} = require('mongodb');
const ReserveResultPojo = require("../models/ReserveResultPojo"); const ReserveResultPojo = require("../models/ReserveResultPojo");
const ContactPojo = require("../models/ContactPojo"); const ContactPojo = require("../models/ContactPojo");
@@ -52,14 +47,5 @@ class MongoManager {
} }
} }
let manag = new MongoManager();
(async () => { module.exports = MongoManager
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());
})()