support black list
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
class BlackListContactPojo {
|
||||
constructor(contact) {
|
||||
this.phone = contact.phoneNumber;
|
||||
this.passport = contact.passportNumber;
|
||||
this.last_name = contact.lastName;
|
||||
this.first_name = contact.firstName;
|
||||
this.mail = contact.mail;
|
||||
this.update_at_in_s = (new Date()) / 1000;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = BlackListContactPojo
|
||||
@@ -0,0 +1,15 @@
|
||||
const CommandorPage = require("./workers/CommandorPage");
|
||||
const ContactPojo = require("./models/ContactPojo");
|
||||
const {MongoManager} =require("./workers/mongo_manager");
|
||||
const mongoManager = new MongoManager();
|
||||
|
||||
|
||||
mongoManager.connect().then(r => {
|
||||
let contact = new ContactPojo("0649614591", "1234567890", "PAN", "Lei", "panleicim@gmail.com")
|
||||
let commandPage = new CommandorPage(contact, null, mongoManager)
|
||||
commandPage.saveToBlackList().then(r => {
|
||||
console.log("saved to db")
|
||||
})
|
||||
|
||||
}
|
||||
)
|
||||
@@ -1,5 +1,6 @@
|
||||
const {SolveCaptcha, TWO_CAPTCHA_CONNECTION_FAILED} = require("./SolveCaptcha");
|
||||
const ReserveResultPojo = require("../models/ReserveResultPojo");
|
||||
const BlackListContactPojo = require("../models/BlackListContactPojo");
|
||||
const appointmentLogger = require("../utiles/LoggerUtils")
|
||||
const PublishType = require("../models/PublishType");
|
||||
const {
|
||||
@@ -293,7 +294,7 @@ class CommandorPage {
|
||||
}
|
||||
|
||||
async onPageLoad(currentPage) {
|
||||
console.log("onPageLoad called, url is "+currentPage.url())
|
||||
console.log("onPageLoad called, url is " + currentPage.url())
|
||||
try {
|
||||
let content = await currentPage.content();
|
||||
let captcha_url = "geo.captcha-delivery.com/captcha";
|
||||
@@ -374,21 +375,11 @@ class CommandorPage {
|
||||
this.isTerminated = true
|
||||
}
|
||||
|
||||
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(), 1, publishType);
|
||||
reserve.source_from = this.device.model();
|
||||
await this.mongoManager.saveReserveToDb(reserve.to_mongo_dict())
|
||||
await delay(2 * 1000)
|
||||
async saveToBlackList() {
|
||||
await this.mongoManager.saveBlackListToDb(new BlackListContactPojo(this.contact))
|
||||
this.isTerminated = true
|
||||
}
|
||||
|
||||
|
||||
async getErrors() {
|
||||
if (this.page.url() === BLANK_URL) {
|
||||
this.isTerminated = true;
|
||||
@@ -398,7 +389,7 @@ class CommandorPage {
|
||||
if (errorItem) {
|
||||
let errorContent = await errorItem.innerHTML();
|
||||
log("error:" + errorContent);
|
||||
this.handleError(errorContent);
|
||||
await this.handleError(errorContent);
|
||||
}
|
||||
} catch (e) {
|
||||
log(e);
|
||||
@@ -406,12 +397,12 @@ class CommandorPage {
|
||||
}
|
||||
}
|
||||
|
||||
handleError(errorContent) {
|
||||
async handleError(errorContent) {
|
||||
if (errorContent.includes(DOUBLE_REQUEST_ERROR_MESSAGE) || errorContent.includes(DOUBLE_REQUEST_ERROR_MESSAGE_FR)) {
|
||||
this.isTerminated = true;
|
||||
} else if (errorContent.includes(TOO_MANY_REQUEST_ERROR_MESSAGE) || errorContent.includes(TOO_MANY_REQUEST_ERROR_MESSAGE_FR)) {
|
||||
// todo, add contact to black list
|
||||
this.isTerminated = true;
|
||||
await this.saveToBlackList()
|
||||
} else if (errorContent.includes(CAPTCHA_ERROR_MESSAGE) || errorContent.includes(CAPTCHA_ERROR_MESSAGE_FR)) {
|
||||
this.isTerminated = true;
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ 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 BLACK_LIST_COLLECTION_NAME = "BLACK_LIST"
|
||||
|
||||
const {MongoClient} = require('mongodb');
|
||||
const ReserveResultPojo = require("../models/ReserveResultPojo");
|
||||
@@ -45,6 +45,10 @@ class MongoManager {
|
||||
let collectionName = formatDate(new Date())
|
||||
return await this.db.collection(collectionName).replaceOne({'_id': reservePojo.id,}, reservePojo, {upsert: true})
|
||||
}
|
||||
|
||||
async saveBlackListToDb(contact) {
|
||||
return await this.db.collection(BLACK_LIST_COLLECTION_NAME).replaceOne({'_id': contact.mail,}, contact, {upsert: true})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user