first commit
This commit is contained in:
Binary file not shown.
@@ -0,0 +1,31 @@
|
||||
const xlsx = require('node-xlsx');
|
||||
const ContactPojo = require("../models/ContactPojo");
|
||||
|
||||
class ExcelUtil {
|
||||
|
||||
readContacts() {
|
||||
let workSheetsFromFile = xlsx.parse('/Users/lpan/Desktop/contact_all.xlsx');
|
||||
console.log(workSheetsFromFile);
|
||||
// return a list of contactPojo
|
||||
let contactList = [];
|
||||
workSheetsFromFile[0].data.forEach(
|
||||
(info, index, list) => {
|
||||
// console.log("info:" + info)
|
||||
// console.log("index:" + index)
|
||||
if (index > 0) {
|
||||
let name = info[0].split(" ")
|
||||
let firstName = name[1];
|
||||
let lastName = name[0];
|
||||
let phoneNumber = info[1];
|
||||
let passportNumber = info[2];
|
||||
let mail = info[3];
|
||||
let newContact = new ContactPojo(phoneNumber, passportNumber, lastName, firstName, mail);
|
||||
contactList.push(newContact);
|
||||
}
|
||||
}
|
||||
)
|
||||
return contactList;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ExcelUtil
|
||||
@@ -0,0 +1,14 @@
|
||||
class ContactPojo {
|
||||
|
||||
constructor(phoneNumber, passportNumber, lastName, firstName, mail) {
|
||||
this.phoneNumber = phoneNumber;
|
||||
this.passportNumber = passportNumber;
|
||||
this.lastName = lastName;
|
||||
this.firstName = firstName;
|
||||
this.mail = mail;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
module.exports = ContactPojo
|
||||
@@ -0,0 +1,6 @@
|
||||
const PublishType = {
|
||||
SUCCESS: "SUCCESS",
|
||||
ERROR: "ERROR",
|
||||
PENDING: "PENDING",
|
||||
DUPLICATED: "DUPLICATED",
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
class ReserveResultPojo {
|
||||
constructor(id, phoneNumber, passportNumber, mail, lastName, firstName, storeType, url) {
|
||||
this.id = id;
|
||||
this.phoneNumber = phoneNumber;
|
||||
this.passportNumber = passportNumber;
|
||||
this.firstName = firstName;
|
||||
this.lastName = lastName;
|
||||
this.storeType = storeType;
|
||||
this.url = url;
|
||||
this.mail = mail;
|
||||
}
|
||||
|
||||
to_mongo_dict() {
|
||||
return {
|
||||
id: this.id,
|
||||
phone: this.phoneNumber,
|
||||
firstName: this.firstName,
|
||||
lastName: this.lastName,
|
||||
email: this.mail,
|
||||
passport: this.passportNumber,
|
||||
url: this.url,
|
||||
store_type: this.storeType
|
||||
}
|
||||
}
|
||||
|
||||
static create_from_contact(contactPojo, id, url, storeType) {
|
||||
return new ReserveResultPojo(id, contactPojo.phoneNumber, contactPojo.passportNumber, contactPojo.mail, contactPojo.lastName, contactPojo.firstName, storeType, url);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = ReserveResultPojo
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 194 KiB |
@@ -0,0 +1,193 @@
|
||||
const {_android: android} = require("playwright");
|
||||
const SolveCaptcha = require("./SolveCaptcha");
|
||||
|
||||
// const RDV_URL = "http://192.168.0.44:8000/test_appointment.html"
|
||||
const RDV_URL = "https://rendezvousparis.hermes.com/client/register";
|
||||
|
||||
const COUNTRY_ID = "#phone_country"
|
||||
const PHONE_NUMBER = "#phone_number"
|
||||
const EMAIL_ID = "#email"
|
||||
const PREFER_STORE = "#prefer"
|
||||
const LAST_NAME = "#surname"
|
||||
const FIRST_NAME = "#name"
|
||||
const CGU_ID = "#cgu"
|
||||
const PROCESSING_ID = "#processing"
|
||||
const PASSPORT_ID = "#passport_id"
|
||||
|
||||
const CONFIRMED_MESSAGE = "Your request for a Leather Goods appointment has been registered"
|
||||
const CONFIRMED_MESSAGE_FR = "Votre demande de rendez-vous Maroquinerie a bien été enregistrée et nous vous en remercions."
|
||||
const MESSAGE_URL_VALIDATION_FR = "Nous avons envoyé un lien par e-mail."
|
||||
const DOUBLE_REQUEST_ERROR_MESSAGE = "A request with the same data has already been validated today."
|
||||
const DOUBLE_REQUEST_ERROR_MESSAGE_FR = "Une demande avec les données saisies a déjà été validée aujourd’hui."
|
||||
const TOO_MANY_REQUEST_ERROR_MESSAGE = "Due to a large number of requests"
|
||||
const TOO_MANY_REQUEST_ERROR_MESSAGE_FR = "Suite à un trop grand nombre de demandes"
|
||||
const CAPTCHA_ERROR_MESSAGE = "Error verifying captcha, please try again"
|
||||
const CAPTCHA_ERROR_MESSAGE_FR = "La vérification du captcha a échoué"
|
||||
|
||||
function delay(delayInms) {
|
||||
return new Promise(resolve => {
|
||||
setTimeout(() => {
|
||||
resolve(2);
|
||||
}, delayInms);
|
||||
});
|
||||
}
|
||||
|
||||
function getRandom() {
|
||||
return Math.floor(Math.random() * 5);
|
||||
}
|
||||
|
||||
function getRandomWaitTime() {
|
||||
return getRandom() * 1000
|
||||
}
|
||||
|
||||
class CommandorPage {
|
||||
constructor(contact) {
|
||||
this.contact = contact;
|
||||
}
|
||||
|
||||
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'});
|
||||
|
||||
// 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();
|
||||
}
|
||||
|
||||
async chooseCountry(page) {
|
||||
await page.locator(COUNTRY_ID).focus();
|
||||
await delay(getRandomWaitTime())
|
||||
await page.click(COUNTRY_ID);
|
||||
await delay(getRandomWaitTime())
|
||||
await page.selectOption(COUNTRY_ID, 'FR');
|
||||
await delay(getRandomWaitTime())
|
||||
await page.click(COUNTRY_ID);
|
||||
}
|
||||
|
||||
async fillEmail(page) {
|
||||
await page.locator(EMAIL_ID).focus();
|
||||
await delay(getRandomWaitTime())
|
||||
await page.locator(EMAIL_ID).fill(this.contact.mail);
|
||||
}
|
||||
|
||||
async inputPhoneNumber(page) {
|
||||
await page.locator(PHONE_NUMBER).focus()
|
||||
await page.locator(PHONE_NUMBER).fill("0" + this.contact.phoneNumber)
|
||||
}
|
||||
|
||||
async inputName(page) {
|
||||
await page.locator(LAST_NAME).focus()
|
||||
await delay(getRandomWaitTime())
|
||||
await page.locator(LAST_NAME).fill(this.contact.lastName)
|
||||
await page.locator(FIRST_NAME).focus()
|
||||
await delay(getRandomWaitTime())
|
||||
await page.locator(FIRST_NAME).fill(this.contact.firstName)
|
||||
}
|
||||
|
||||
async inputPassportId(page) {
|
||||
await page.locator(PASSPORT_ID).focus()
|
||||
await delay(getRandomWaitTime())
|
||||
await page.locator(PASSPORT_ID).fill(this.contact.passportNumber.toString())
|
||||
}
|
||||
|
||||
async checkCGU(page) {
|
||||
await page.locator(CGU_ID).focus()
|
||||
await page.locator(CGU_ID).click()
|
||||
await delay(getRandomWaitTime())
|
||||
await page.locator(PROCESSING_ID).focus()
|
||||
await page.locator(PROCESSING_ID).click()
|
||||
}
|
||||
|
||||
async chooseStore(page) {
|
||||
await page.locator(PREFER_STORE).focus()
|
||||
await delay(1000)
|
||||
await page.click(PREFER_STORE);
|
||||
await page.selectOption(PREFER_STORE, "faubourg");
|
||||
await page.click(PREFER_STORE);
|
||||
}
|
||||
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
async clickValid(page) {
|
||||
await delay(getRandomWaitTime())
|
||||
try {
|
||||
page.evaluate(() => {
|
||||
document.getElementsByClassName("btn")[0].focus();
|
||||
})
|
||||
await delay(getRandomWaitTime())
|
||||
page.evaluate(() => {
|
||||
document.getElementsByClassName("btn")[0].click();
|
||||
})
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
}
|
||||
}
|
||||
|
||||
async resolveCaptcha(page) {
|
||||
this.captchaSolver = new SolveCaptcha(page);
|
||||
await this.captchaSolver.start((solution) => {
|
||||
console.log("solution is: " + solution);
|
||||
page.evaluate((solution) => {
|
||||
document.getElementById("g-recaptcha-response").innerHTML = solution;
|
||||
}, solution)
|
||||
this.clickValid()
|
||||
})
|
||||
}
|
||||
|
||||
async onPageLoad() {
|
||||
let content = await this.page.content();
|
||||
let captcha_url = "geo.captcha-delivery.com/captcha"
|
||||
|
||||
if (content.toString().includes(captcha_url)) {
|
||||
console.log("we are blockeds")
|
||||
} else {
|
||||
if (this.page.url() === RDV_URL) {
|
||||
await this.fillFields()
|
||||
} else {
|
||||
if (content.includes(MESSAGE_URL_VALIDATION_FR)) {
|
||||
console.log("successful")
|
||||
this.push_message_to_queue(PublishType.SUCCESS)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
push_message_to_queue(publishType) {
|
||||
let url = this.page.url()
|
||||
if (url === "https://rendezvousparis.hermes.com/client/welcome") {
|
||||
return
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = CommandorPage
|
||||
@@ -0,0 +1,65 @@
|
||||
const axios = require("axios");
|
||||
const CAPCHA_NOT_READY = "CAPCHA_NOT_READY";
|
||||
const REGEX_DATA_SITE_KEY = "data-sitekey=[\"a-z0-9A-Z]+";
|
||||
const API_KEY = "d66aaf490d8aa424a5175e1fbd1aadea";
|
||||
const SITE_KEY = "6LdUViwUAAAAAOBJjtMsmKc9C7200Djd31w2mCs7";
|
||||
|
||||
function delay(delayInms) {
|
||||
return new Promise(resolve => {
|
||||
setTimeout(() => {
|
||||
resolve(2);
|
||||
}, delayInms);
|
||||
});
|
||||
}
|
||||
|
||||
class SolveCaptcha {
|
||||
|
||||
constructor(page) {
|
||||
this.page = page;
|
||||
}
|
||||
|
||||
async start(handle_solution_received) {
|
||||
await this.solve_captcha(SITE_KEY, handle_solution_received)
|
||||
}
|
||||
|
||||
async solve_captcha(site_key, handle_solution_received) {
|
||||
console.log("solve_captcha(), for " + this.page.url())
|
||||
let url_get = `http://2captcha.com/in.php?key=${API_KEY}&method=userrecaptcha&googlekey=${site_key}&pageurl=${this.page.url()}`;
|
||||
|
||||
let res = await axios.get(url_get)
|
||||
console.log(`statusCode: ${res.status}`);
|
||||
console.log(res);
|
||||
let results = res.data.split("|");
|
||||
this.captcha_id = results[1];
|
||||
let solution = CAPCHA_NOT_READY;
|
||||
let status_code = 1;
|
||||
await delay(15 * 1000)
|
||||
while (solution === CAPCHA_NOT_READY || status_code !== 200) {
|
||||
await this.get_solution(this.captcha_id, (status, sol) => {
|
||||
status_code = status;
|
||||
solution = sol
|
||||
})
|
||||
await delay(5 * 1000)
|
||||
}
|
||||
handle_solution_received(solution)
|
||||
}
|
||||
|
||||
async get_solution(catcha_id, onSolutionFound) {
|
||||
console.log("get_solution() called")
|
||||
let url_response = `http://2captcha.com/res.php?key=${API_KEY}&action=get&id=${catcha_id}`;
|
||||
let res = await axios.get(url_response)
|
||||
console.log(`statusCode: ${res.status}`);
|
||||
console.log(res);
|
||||
let results = res.data.split("|");
|
||||
let solution
|
||||
if (results.length > 1)
|
||||
solution = results[1];
|
||||
else {
|
||||
solution = results[0]
|
||||
}
|
||||
onSolutionFound(res.status, solution)
|
||||
await delay(5 * 1000)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = SolveCaptcha
|
||||
@@ -0,0 +1,65 @@
|
||||
const MONGO_DB_URL = "mongo.lpaconsulting.fr"
|
||||
const CAPTCHA_ERROR_COLLECTION_PREFIX = "CAPTCHA_ERROR_"
|
||||
const BLACK_LIST = "BLACK_LIST"
|
||||
const DB_NAME = "appointment"
|
||||
const COLLECTION_NAME = "appointment"
|
||||
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");
|
||||
|
||||
function formatDate(date) {
|
||||
let d = new Date(date),
|
||||
month = '' + (d.getMonth() + 1),
|
||||
day = '' + d.getDate(),
|
||||
year = d.getFullYear();
|
||||
|
||||
if (month.length < 2)
|
||||
month = '0' + month;
|
||||
if (day.length < 2)
|
||||
day = '0' + day;
|
||||
|
||||
return [year, month, day].join('-');
|
||||
}
|
||||
|
||||
class MongoManager {
|
||||
constructor() {
|
||||
//init mongoDb
|
||||
let uri = `mongodb://appointment:Rdv%402022@${MONGO_DB_URL}/appointment`
|
||||
this.client = new MongoClient(uri)
|
||||
}
|
||||
|
||||
async connect() {
|
||||
await this.client.connect()
|
||||
this.db = this.client.db("appointment")
|
||||
}
|
||||
|
||||
async getAllSuccessfulItemsForDay(day) {
|
||||
return await this.db.collection(day).find().toArray()
|
||||
}
|
||||
|
||||
async saveReserveToDb(reservePojo) {
|
||||
let collectionName = formatDate(new Date())
|
||||
return await this.db.collection(collectionName).replaceOne({'_id': reservePojo.id,}, reservePojo, {upsert: true})
|
||||
}
|
||||
}
|
||||
|
||||
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());
|
||||
})()
|
||||
Reference in New Issue
Block a user