manage accepted appointments

This commit is contained in:
2022-10-16 23:41:20 +02:00
parent b27cf3c806
commit c79c45db8a
6 changed files with 49 additions and 13 deletions
+21 -5
View File
@@ -6,6 +6,7 @@ const alert = require('alert');
const mongoManager = new MongoManager();
const SEVEN_DAYS_IN_S = 3600 * 24 * 7;
const THIRTY_DAYS_IN_S = 3600 * 24 * 30;
let excelUtil = new ExcelUtil();
let collectionName = formatDate(new Date())
@@ -24,8 +25,10 @@ async function filterAlreadyBookedContacts(contactList) {
// Connect to the device.
async function needToBook(contact, mongoManager) {
let alreadyBooked = await mongoManager.getAllSuccessfulItemsForDay(collectionName)
let blackListItems = await mongoManager.getAllBlackedListItems()
console.log("check contact with email " + contact.mail)
let alreadyBooked = await mongoManager.getAllSuccessfulItemsForDay(collectionName);
let blackListItems = await mongoManager.getAllBlackedListItems();
let alreadyAcceptedItems = await mongoManager.getAllAcceptedAppointments();
let needToBook = true;
await alreadyBooked.forEach((bookedItem) => {
if (bookedItem.email === contact.mail) {
@@ -36,12 +39,25 @@ async function needToBook(contact, mongoManager) {
if (needToBook) {
await blackListItems.forEach((blackListItem) => {
if (blackListItem.mail === contact.mail) {
console.log("=====handle blacklist item====")
console.log("=====handle blacklist item====");
console.log("update_at_s is " + blackListItem.update_at_in_s)
console.log("email is " + blackListItem.mail)
console.log("black list email is " + blackListItem.mail)
needToBook = blackListItem.update_at_in_s + SEVEN_DAYS_IN_S <= (new Date()) / 1000;
if (!needToBook) {
console.log("skip")
console.log("contact in blacklist -->skip");
}
}
})
}
if (needToBook) {
await alreadyAcceptedItems.forEach((acceptedItem) => {
if (acceptedItem.email === contact.mail) {
console.log("=====handle already accepted item====");
console.log("accepted_at is " + acceptedItem.accepted_at);
console.log("accepted email is " + acceptedItem.email);
needToBook = acceptedItem.accepted_at + THIRTY_DAYS_IN_S <= (new Date()) / 1000;
if (!needToBook) {
console.log("already accepted appointment --> skip");
}
}
})
+13 -7
View File
@@ -1,15 +1,21 @@
const CommandorPage = require("./workers/CommandorPage");
const ContactPojo = require("./models/ContactPojo");
const {MongoManager} =require("./workers/mongo_manager");
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.deleteFromBlackList().then(r => {
console.log("saved to db")
})
// let contact = new ContactPojo("0649614591", "1234567890", "PAN", "Lei", "panleicim@gmail.com")
// let commandPage = new CommandorPage(contact, null, mongoManager)
// commandPage.deleteFromBlackList().then(r => {
// console.log("saved to db")
// })
mongoManager.getAllAcceptedAppointments().then(acceptedList => {
acceptedList.forEach((item) => {
console.log(item.email)
console.log(item.accepted_at)
})
}
)
}
)
+1 -1
View File
@@ -7,7 +7,7 @@ const {
shell
} = require('electron')
const GeoCaptchaSolver = require("./GeoCaptchaSolver");
// const RDV_URL = "http://192.168.0.44:8000/test_appointment.html"
// const RDV_URL = "http://192.168.0.41:8000/test_appointment.html"
const RDV_URL = "https://rendezvousparis.hermes.com/client/register";
BLANK_URL = "about:blank"
const ERROR_CAPTCHA_UNSOLVABLE = "ERROR_CAPTCHA_UNSOLVABLE";
+4
View File
@@ -41,6 +41,10 @@ class MongoManager {
return await this.db.collection(day).find().toArray()
}
async getAllAcceptedAppointments() {
return await this.db.collection(ACCEPTED_APPOINTMENT_LIST).find().toArray()
}
async saveReserveToDb(reservePojo) {
let collectionName = formatDate(new Date())
return await this.db.collection(collectionName).replaceOne({'_id': reservePojo.id,}, reservePojo, {upsert: true})