Merge branch 'master' of bitbucket.org:panleicim/appointment_tool_js
This commit is contained in:
+113
-32
@@ -7,7 +7,8 @@ const {
|
||||
shell
|
||||
} = require('electron')
|
||||
const GeoCaptchaSolver = require("./GeoCaptchaSolver");
|
||||
// const RDV_URL = "http://192.168.0.13:8000/test_appointment.html";
|
||||
const SlidingCaptchaSolver = require("./SlidingCaptchaSolver");
|
||||
// const RDV_URL = "http://192.168.0.41:8000/test_appointment.html"
|
||||
const RDV_URL = "https://rendezvousparis.hermes.com/client/register";
|
||||
const BLANK_URL = "about:blank"
|
||||
const ERROR_CAPTCHA_UNSOLVABLE = "ERROR_CAPTCHA_UNSOLVABLE";
|
||||
@@ -36,6 +37,7 @@ const CAPTCHA_ERROR_MESSAGE = "Error verifying captcha, please try again"
|
||||
const CAPTCHA_ERROR_MESSAGE_FR = "La vérification du captcha a échoué"
|
||||
const REGEX_RDV_URL = "https:\/\/rendezvousparis\.hermes\.com\/client\/register\/[A-Z0-9]+"
|
||||
const DEFAULT_STORE = 'faubourg';
|
||||
|
||||
const searchTexts = ['hermes+rdv+online+paris', 'hermes+rdv+enligne+paris', 'hermes+rdv+en+ligne+paris', 'hermes+rendezvous+en+ligne+paris', 'hermes+appointment+online+paris', 'hermes+appointment+online+paris', 'appointment+hermes+paris+on+line', 'hermes+rendez+vous+online+paris', 'hermes+rendez+vous+paris+en+ligne', 'hermes+rendez+vous+paris+enligne', 'hermes+rendez+vous+paris+online', 'online+appointment+hermes+paris', 'hermes+online+appointment+paris', 'paris+hermes+online+appointment']
|
||||
|
||||
function delay(delayInMs) {
|
||||
@@ -58,6 +60,10 @@ function log(message) {
|
||||
appointmentLogger.log({level: "info", message: message})
|
||||
}
|
||||
|
||||
function logWithDevice(message, device) {
|
||||
appointmentLogger.log({level: "info", message: device.model() + ":" + message})
|
||||
}
|
||||
|
||||
class CommandorPage {
|
||||
constructor(contact, device, mongoManager, selectedStore = DEFAULT_STORE, audioAnalyse = false, alertBeep = false) {
|
||||
this.contact = contact;
|
||||
@@ -101,7 +107,6 @@ class CommandorPage {
|
||||
try {
|
||||
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(RDV_URL, {timeout: 90 * 1000});
|
||||
} catch (e) {
|
||||
log(e)
|
||||
this.isTerminated = true
|
||||
@@ -113,10 +118,13 @@ class CommandorPage {
|
||||
log(e)
|
||||
}
|
||||
try {
|
||||
// await this.setUpCookies()
|
||||
this.page.locator(':nth-match(:text("rendezvousparis"), 1)').click()
|
||||
} catch (e) {
|
||||
log(e)
|
||||
this.isTerminated = true
|
||||
if (!this.page.url().includes(RDV_URL)) {
|
||||
this.isTerminated = true;
|
||||
}
|
||||
}
|
||||
|
||||
let cancel
|
||||
@@ -185,7 +193,7 @@ class CommandorPage {
|
||||
if (!page.isClosed()) {
|
||||
if (!this.isPhoneInput) {
|
||||
await page.locator(PHONE_NUMBER).focus();
|
||||
await page.locator(PHONE_NUMBER).fill("+33" + this.contact.phoneNumber);
|
||||
await page.locator(PHONE_NUMBER).fill("+330" + this.contact.phoneNumber);
|
||||
this.isPhoneInput = true;
|
||||
}
|
||||
}
|
||||
@@ -288,6 +296,7 @@ class CommandorPage {
|
||||
}
|
||||
|
||||
async clickValid(page) {
|
||||
await this.saveCookies()
|
||||
await delay(getRandomWaitTime())
|
||||
try {
|
||||
if (!this.page.isClosed()) {
|
||||
@@ -357,7 +366,7 @@ class CommandorPage {
|
||||
let captcha_container = await iframeHandler.locator(CAPTCHA_CONTAINER)
|
||||
let html = await captcha_container.innerHTML()
|
||||
console.log("audio_tag: " + html);
|
||||
return html.includes("You have been blocked")
|
||||
return html.includes("You have been blocked") || html.includes("Vous avez été bloqué")
|
||||
}
|
||||
|
||||
async onPageLoad(currentPage) {
|
||||
@@ -374,29 +383,42 @@ class CommandorPage {
|
||||
shell.beep()
|
||||
}
|
||||
}
|
||||
log("发现datadome");
|
||||
logWithDevice("发现datadome", this.device);
|
||||
} else if (content.includes("502 Bad Gateway")) {
|
||||
logWithDevice("502 Bad Gateway found", this.device)
|
||||
await this.page.reload()
|
||||
} else if (currentPage.url().includes("sorry")) {
|
||||
await this.resetBrowser()
|
||||
} else if (content.includes("PROXY_CONNECTION_FAILED")) {
|
||||
logWithDevice("PROXY_CONNECTION_FAILED, will reload page", this.device);
|
||||
await delay(2000)
|
||||
await this.page.reload()
|
||||
} else if (content.includes("ERR_NETWORK_CHANGED")) {
|
||||
logWithDevice("ERR_NETWORK_CHANGED, will reload page", this.device);
|
||||
await delay(2000)
|
||||
await this.page.reload()
|
||||
} else if (content.includes("CACHE_MISS")) {
|
||||
logWithDevice("CACHE_MISS, will reload page", this.device);
|
||||
await delay(2000)
|
||||
// await this.setUpCookies()
|
||||
await this.page.reload()
|
||||
} else if (content.includes("ERR_TIMED_OUT")) {
|
||||
logWithDevice("ERR_TIMED_OUT, will reload page", this.device);
|
||||
await delay(2000)
|
||||
await this.page.reload()
|
||||
} else if (content.includes("408 Request Time-out")) {
|
||||
logWithDevice("Request Time-out, will reload page", this.device);
|
||||
await delay(2000)
|
||||
await this.page.reload()
|
||||
} else {
|
||||
if (currentPage.url() === RDV_URL) {
|
||||
await this.fillFields(this.page);
|
||||
await this.saveCookies()
|
||||
// if (this.isFillingFields)
|
||||
// await this.getErrors()
|
||||
} else {
|
||||
if (content.includes(MESSAGE_URL_VALIDATION_FR) || content.includes(MESSAGE_URL_VALIDATION_EN)) {
|
||||
log("successful");
|
||||
// save cookies
|
||||
try {
|
||||
|
||||
let cookies = await this.context.cookies();
|
||||
let cookiesInJson = [];
|
||||
cookies.forEach((cookie) => {
|
||||
cookiesInJson.push(JSON.stringify(cookie))
|
||||
})
|
||||
await require("fs").writeFileSync(this.contact.mail + '.txt', cookiesInJson.join('\n'));
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
}
|
||||
await this.push_message_to_queue(PublishType.SUCCESS);
|
||||
} else if (content.includes(EMPTY_RESPONSE_ERROR)) {
|
||||
log("EMPTY_RESPONSE_ERROR error received, will quit")
|
||||
@@ -412,45 +434,102 @@ class CommandorPage {
|
||||
}
|
||||
}
|
||||
|
||||
async saveCookies() {
|
||||
log("saveCookies() called.")
|
||||
try {
|
||||
let cookies = await this.page.context().cookies();
|
||||
let cookiesInJson = [];
|
||||
cookies.forEach((cookie) => {
|
||||
cookiesInJson.push(JSON.stringify(cookie))
|
||||
})
|
||||
await require("fs").writeFileSync(this.contact.mail + '.txt', cookiesInJson.join('\n'));
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
}
|
||||
}
|
||||
|
||||
async setUpCookies() {
|
||||
// load cookies from file
|
||||
try {
|
||||
logWithDevice("will add cookies", this.device)
|
||||
const fs = require('fs');
|
||||
// let cookiesFile = fs.readFileSync('vampuka_fisherleyba@aol.com.txt', 'utf8');
|
||||
let cookiesFile = fs.readFileSync(this.contact.mail + '.txt', 'utf8');
|
||||
let cookiesList = cookiesFile.split("\n")
|
||||
let cookiesListToAdd = []
|
||||
cookiesList.forEach((cookie) => {
|
||||
let cookieToAdd = JSON.parse(cookie)
|
||||
// if (cookieToAdd.name === "datadome") {
|
||||
cookiesListToAdd.push(cookieToAdd)
|
||||
// }
|
||||
})
|
||||
await this.context.addCookies(cookiesListToAdd)
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
}
|
||||
}
|
||||
|
||||
async checkAudioBtn() {
|
||||
let isBlocked = await this.isBlocked()
|
||||
if (!isBlocked) {
|
||||
let audioBtn = await this.page.frameLocator("iframe").locator("#captcha__audio__button");
|
||||
log("audioBtn found")
|
||||
audioBtn.click()
|
||||
let captchaSolver = new GeoCaptchaSolver(this.page, this.device, this.isTerminated)
|
||||
await captchaSolver.solve((isSuccessful) => {
|
||||
if (!isSuccessful) {
|
||||
this.isTerminated = true
|
||||
//try to sliding capthca at first
|
||||
let slidingCaptchaSolver = new SlidingCaptchaSolver(this.device);
|
||||
await slidingCaptchaSolver.solve(this.page, async (isSuccessful) => {
|
||||
console.log("check isAlwaysBlocked")
|
||||
let isAlwaysBlocked = await this.isBlocked();
|
||||
if (isAlwaysBlocked) {
|
||||
await this.resolveByAudio();
|
||||
}
|
||||
})
|
||||
} else {
|
||||
log("audioBtn not found")
|
||||
console.log("audioBtn not found")
|
||||
console.log("we are blocked")
|
||||
//
|
||||
await this.resetBrowser()
|
||||
}
|
||||
}
|
||||
|
||||
async resolveByAudio() {
|
||||
let audioBtn = await this.page.frameLocator("iframe").locator("#captcha__audio__button");
|
||||
log("audioBtn found")
|
||||
audioBtn.click()
|
||||
let captchaSolver = new GeoCaptchaSolver(this.page, this.device, this.isTerminated)
|
||||
await captchaSolver.solve((isSuccessful) => {
|
||||
if (!isSuccessful) {
|
||||
this.isTerminated = true
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
async onResponse(response) {
|
||||
// let rex = new RegExp(REGEX_RDV_URL)
|
||||
// log("onResponse with url:" + response.url())
|
||||
// if (rex.test(response.url())) {
|
||||
// log("rdv url found:" + response.url())
|
||||
// await this.push_message_to_db(PublishType.SUCCESS, response.url())
|
||||
let rex = new RegExp(REGEX_RDV_URL)
|
||||
log("onResponse with url:" + response.url())
|
||||
// log("onResponse with url:" + response.body())
|
||||
if (rex.test(response.url())) {
|
||||
log("rdv url found:" + response.url())
|
||||
// save cookies
|
||||
await this.saveCookies();
|
||||
await this.push_message_to_db(PublishType.SUCCESS, response.url())
|
||||
}
|
||||
// if (response.url().includes("geo.captcha-delivery.com/interstitial")) {
|
||||
// logWithDevice("interstitial: response.status is " + response.status())
|
||||
// await this.setUpCookies()
|
||||
// }
|
||||
}
|
||||
|
||||
async push_message_to_queue(publishType) {
|
||||
let url = this.page.url();
|
||||
await this.push_message_to_db(publishType, url)
|
||||
}
|
||||
|
||||
async push_message_to_db(publishType, url) {
|
||||
let splitedUrl = url.split("/");
|
||||
let id = splitedUrl[splitedUrl.length - 1];
|
||||
if (url === "https://rendezvousparis.hermes.com/client/welcome") {
|
||||
return
|
||||
}
|
||||
// save to mongoDb
|
||||
let reserve = ReserveResultPojo.create_from_contact(this.contact, id, this.page.url(), this.choosedStore, publishType);
|
||||
let reserve = ReserveResultPojo.create_from_contact(this.contact, id, url, this.choosedStore, publishType);
|
||||
reserve.source_from = this.device.model();
|
||||
await this.mongoManager.saveReserveToDb(reserve.to_mongo_dict())
|
||||
await this.deleteFromBlackList()
|
||||
@@ -523,6 +602,8 @@ class CommandorPage {
|
||||
await delay(1000)
|
||||
this.isTerminated = true
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
module.exports = CommandorPage
|
||||
Reference in New Issue
Block a user