save cookies to queue message
This commit is contained in:
@@ -12,6 +12,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@nodegui/nodegui": "^0.57.1",
|
"@nodegui/nodegui": "^0.57.1",
|
||||||
"alert": "^5.1.1",
|
"alert": "^5.1.1",
|
||||||
|
"amqplib": "^0.10.3",
|
||||||
"axios": "^0.27.2",
|
"axios": "^0.27.2",
|
||||||
"jimp": "^0.22.8",
|
"jimp": "^0.22.8",
|
||||||
"mongodb": "^4.9.1",
|
"mongodb": "^4.9.1",
|
||||||
|
|||||||
+45
-39
@@ -5,6 +5,7 @@ const {MongoManager, formatDate} = require("./workers/mongo_manager");
|
|||||||
const alert = require('alert');
|
const alert = require('alert');
|
||||||
const schedule = require("node-schedule");
|
const schedule = require("node-schedule");
|
||||||
const DeviceExcludeMode = require("./models/DeviceExcludeMode");
|
const DeviceExcludeMode = require("./models/DeviceExcludeMode");
|
||||||
|
const Sender = require("./queue/Sender");
|
||||||
const mongoManager = new MongoManager();
|
const mongoManager = new MongoManager();
|
||||||
const SEVEN_DAYS_IN_S = 3600 * 24 * 7;
|
const SEVEN_DAYS_IN_S = 3600 * 24 * 7;
|
||||||
// const NINETY_DAYS_IN_S = 3600 * 24 * 30 * 3;`
|
// const NINETY_DAYS_IN_S = 3600 * 24 * 30 * 3;`
|
||||||
@@ -15,7 +16,7 @@ let excludeMode = DeviceExcludeMode.SIX
|
|||||||
let three_to_excludes = ["bec11752", "4e8ca027", "hi7ljr5xduyt9pfi", "EPHUT20825001518"]
|
let three_to_excludes = ["bec11752", "4e8ca027", "hi7ljr5xduyt9pfi", "EPHUT20825001518"]
|
||||||
let four_to_excludes = ["bec11752", "4e8ca027", "hi7ljr5xduyt9pfi", "e30eb015", "EPHUT20825001518"]
|
let four_to_excludes = ["bec11752", "4e8ca027", "hi7ljr5xduyt9pfi", "e30eb015", "EPHUT20825001518"]
|
||||||
let seven_to_excludes = ["4e8ca027", "hi7ljr5xduyt9pfi", "e30eb015", "EPHUT20825001518", "bec11752", "fy65eqs4wkvcpf9h", "fuljaueqguugf6pn", "EPHUT20825001518"]
|
let seven_to_excludes = ["4e8ca027", "hi7ljr5xduyt9pfi", "e30eb015", "EPHUT20825001518", "bec11752", "fy65eqs4wkvcpf9h", "fuljaueqguugf6pn", "EPHUT20825001518"]
|
||||||
let six_to_excludes = ["4e8ca027", "hi7ljr5xduyt9pfi", "e30eb015", "EPHUT20825001518", "bec11752", "fy65eqs4wkvcpf9h", "07fbd156", "NFD669QK8XNFSCNN", "6X494TTWQGFALB79", "71a0371d", "YP6HVKLFE67T598L"]
|
let six_to_excludes = ["heuklr55wo8tfyvw", "192.168.102.87:5555", "APU7N16321020182", "9ae069bb", "4e8ca027", "hi7ljr5xduyt9pfi", "e30eb015", "EPHUT20825001518", "bec11752", "fy65eqs4wkvcpf9h", "NFD669QK8XNFSCNN", "6X494TTWQGFALB79", "71a0371d", "YP6HVKLFE67T598L"]
|
||||||
let nine_to_excludes = ["bec11752", "4e8ca027", "hi7ljr5xduyt9pfi", "e30eb015", "47e7e36b", "p7d6nbw8cu7duous", "njzxojhim7gedyvw", "fmiz5pa6rsx4u4ts", "fy65eqs4wkvcpf9h", "fuljaueqguugf6pn", "EPHUT20825001518", "W8GMFELRHIKZS84T"]
|
let nine_to_excludes = ["bec11752", "4e8ca027", "hi7ljr5xduyt9pfi", "e30eb015", "47e7e36b", "p7d6nbw8cu7duous", "njzxojhim7gedyvw", "fmiz5pa6rsx4u4ts", "fy65eqs4wkvcpf9h", "fuljaueqguugf6pn", "EPHUT20825001518", "W8GMFELRHIKZS84T"]
|
||||||
let for_scrpay = ["07fbd156", "47e7e36b", "4f55c3d4", "5ac879a2", "69db59f0", "71a0371d", "774687ff", "7b71fb20", "8f76f9e7", "99cyfiaebqcy6poj", "EPHUT20825001518", "J4AXB761H2322WJ", "W8GMFELRHIKZS84T", "ai9xv8hy599hvkee", "b41c1b72", "bec11752", "becb6e99", "c3ba032e", "d54e946", "e30eb015", "fmiz5pa6rsx4u4ts", "fuljaueqguugf6pn", "fy65eqs4wkvcpf9h", "hi7ljr5xduyt9pfi", "njzxojhim7gedyvw", "p7d6nbw8cu7duous"]
|
let for_scrpay = ["07fbd156", "47e7e36b", "4f55c3d4", "5ac879a2", "69db59f0", "71a0371d", "774687ff", "7b71fb20", "8f76f9e7", "99cyfiaebqcy6poj", "EPHUT20825001518", "J4AXB761H2322WJ", "W8GMFELRHIKZS84T", "ai9xv8hy599hvkee", "b41c1b72", "bec11752", "becb6e99", "c3ba032e", "d54e946", "e30eb015", "fmiz5pa6rsx4u4ts", "fuljaueqguugf6pn", "fy65eqs4wkvcpf9h", "hi7ljr5xduyt9pfi", "njzxojhim7gedyvw", "p7d6nbw8cu7duous"]
|
||||||
attributedPorts = []
|
attributedPorts = []
|
||||||
@@ -121,7 +122,7 @@ async function needToBook(contact, mongoManager, alreadyBooked) {
|
|||||||
return needToBook
|
return needToBook
|
||||||
}
|
}
|
||||||
|
|
||||||
async function startBook(contactPojo, device, selectedStore, audioAnalyse, alertBeep, port) {
|
async function startBook(contactPojo, device, sender, selectedStore, audioAnalyse, alertBeep, port) {
|
||||||
console.log(`model: ${device.model()}`);
|
console.log(`model: ${device.model()}`);
|
||||||
console.log(`serial: ${device.serial()}`);
|
console.log(`serial: ${device.serial()}`);
|
||||||
let alreadyBooked = await mongoManager.getAllSuccessfulItemsForDay(collectionName);
|
let alreadyBooked = await mongoManager.getAllSuccessfulItemsForDay(collectionName);
|
||||||
@@ -132,7 +133,7 @@ async function startBook(contactPojo, device, selectedStore, audioAnalyse, alert
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (await needToBook(contactPojo, mongoManager, alreadyBooked)) {
|
if (await needToBook(contactPojo, mongoManager, alreadyBooked)) {
|
||||||
let commandor = new CommandorPage(contactPojo, device, mongoManager, selectedStore, audioAnalyse, alertBeep, port);
|
let commandor = new CommandorPage(contactPojo, device, sender, mongoManager, selectedStore, audioAnalyse, alertBeep, port);
|
||||||
//read contacts form excel
|
//read contacts form excel
|
||||||
return await commandor.loadPage();
|
return await commandor.loadPage();
|
||||||
} else {
|
} else {
|
||||||
@@ -140,14 +141,14 @@ async function startBook(contactPojo, device, selectedStore, audioAnalyse, alert
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function startWithList(contacts, device, selectedStore, audioAnalyse, alertBeep, port) {
|
async function startWithList(contacts, device, sender, selectedStore, audioAnalyse, alertBeep, port) {
|
||||||
let duplicatedList = [].concat(contacts).concat(contacts).concat(contacts)
|
let duplicatedList = [].concat(contacts).concat(contacts).concat(contacts)
|
||||||
await duplicatedList.reduce(async (promise, contactPojo) => {
|
await duplicatedList.reduce(async (promise, contactPojo) => {
|
||||||
// This line will wait for the last async function to finish.
|
// This line will wait for the last async function to finish.
|
||||||
// The first iteration uses an already resolved Promise
|
// The first iteration uses an already resolved Promise
|
||||||
// so, it will immediately continue.
|
// so, it will immediately continue.
|
||||||
await promise;
|
await promise;
|
||||||
const contents = await startBook(contactPojo, device, selectedStore, audioAnalyse, alertBeep, port);
|
const contents = await startBook(contactPojo, device, sender, selectedStore, audioAnalyse, alertBeep, port);
|
||||||
console.log(contents);
|
console.log(contents);
|
||||||
}, Promise.resolve());
|
}, Promise.resolve());
|
||||||
}
|
}
|
||||||
@@ -213,41 +214,46 @@ async function startBookWithNumbers(startNumber, endNumber, selectedStore, pathT
|
|||||||
return attributedPort
|
return attributedPort
|
||||||
}
|
}
|
||||||
|
|
||||||
mongoManager.connect().then(r => {
|
let sender = new Sender()
|
||||||
filterAlreadyBookedContacts(contactList).then((listToBook) => {
|
sender.initConnection().then((r) => {
|
||||||
filterAlreadyAcceptedContacts(listToBook).then(notAcceptedContacts => {
|
console.log("queue connected")
|
||||||
filterBlacklistedContacts(notAcceptedContacts).then(listWithoutBlackContact => {
|
mongoManager.connect().then(r => {
|
||||||
console.log("number of contacts to book:" + listWithoutBlackContact.length)
|
filterAlreadyBookedContacts(contactList).then((listToBook) => {
|
||||||
android.devices().then((devices) => {
|
filterAlreadyAcceptedContacts(listToBook).then(notAcceptedContacts => {
|
||||||
if (devices.length === 0) {
|
filterBlacklistedContacts(notAcceptedContacts).then(listWithoutBlackContact => {
|
||||||
alert("未找到连接的设备");
|
console.log("number of contacts to book:" + listWithoutBlackContact.length)
|
||||||
return
|
android.devices().then((devices) => {
|
||||||
}
|
if (devices.length === 0) {
|
||||||
let device_to_excludes = three_to_excludes;
|
alert("未找到连接的设备");
|
||||||
if (excludeMode === DeviceExcludeMode.FOUR) {
|
return
|
||||||
device_to_excludes = four_to_excludes;
|
}
|
||||||
} else if (excludeMode === DeviceExcludeMode.NINE) {
|
let device_to_excludes = three_to_excludes;
|
||||||
device_to_excludes = nine_to_excludes;
|
if (excludeMode === DeviceExcludeMode.FOUR) {
|
||||||
} else if (excludeMode === DeviceExcludeMode.SEVEN) {
|
device_to_excludes = four_to_excludes;
|
||||||
device_to_excludes = seven_to_excludes
|
} else if (excludeMode === DeviceExcludeMode.NINE) {
|
||||||
} else if (excludeMode === DeviceExcludeMode.SIX) {
|
device_to_excludes = nine_to_excludes;
|
||||||
device_to_excludes = six_to_excludes
|
} else if (excludeMode === DeviceExcludeMode.SEVEN) {
|
||||||
}
|
device_to_excludes = seven_to_excludes
|
||||||
filteredDeviceList = devices.filter(device => !device_to_excludes.includes(device.serial()))
|
} else if (excludeMode === DeviceExcludeMode.SIX) {
|
||||||
let segmentNumber = listWithoutBlackContact.length / filteredDeviceList.length;
|
device_to_excludes = six_to_excludes
|
||||||
console.log("connected device number:" + filteredDeviceList.length)
|
}
|
||||||
console.log("segmentNumber:" + segmentNumber)
|
filteredDeviceList = devices.filter(device => !device_to_excludes.includes(device.serial()))
|
||||||
for (let i = 0; i < filteredDeviceList.length; i++) {
|
let segmentNumber = listWithoutBlackContact.length / filteredDeviceList.length;
|
||||||
let device = filteredDeviceList[i];
|
console.log("connected device number:" + filteredDeviceList.length)
|
||||||
let port = startForwordingForDevice(device)
|
console.log("segmentNumber:" + segmentNumber)
|
||||||
startWithList(listWithoutBlackContact.slice(i * segmentNumber, segmentNumber * (i + 1)), device, selectedStore, audioAnalyse, alertBeep, port);
|
for (let i = 0; i < filteredDeviceList.length; i++) {
|
||||||
}
|
let device = filteredDeviceList[i];
|
||||||
|
let port = startForwordingForDevice(device)
|
||||||
|
startWithList(listWithoutBlackContact.slice(i * segmentNumber, segmentNumber * (i + 1)), device, sender, selectedStore, audioAnalyse, alertBeep, port);
|
||||||
|
}
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
}
|
||||||
}
|
)
|
||||||
)
|
})
|
||||||
})
|
});
|
||||||
});
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {startBookWithNumbers, scheduleBookWithNumbers}
|
module.exports = {startBookWithNumbers, scheduleBookWithNumbers}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
const amqp = require("amqplib");
|
||||||
|
|
||||||
|
const QUEUE_HOST = "amqp://appointment:ZyuhJZ2xEYWhElhpJjy7YEpZGZwNYJz2fHIu@appointment.lpaconsulting.fr:5672"
|
||||||
|
const REQUEST_DATA_QUEUE = 'REQUEST_DATA';
|
||||||
|
|
||||||
|
class Sender {
|
||||||
|
channel;
|
||||||
|
connection;
|
||||||
|
|
||||||
|
async initConnection() {
|
||||||
|
this.connection = await amqp.connect(QUEUE_HOST);
|
||||||
|
this.channel = await this.connection.createChannel();
|
||||||
|
await this.channel.assertQueue(REQUEST_DATA_QUEUE, {persistent: true});
|
||||||
|
}
|
||||||
|
|
||||||
|
sendMessage(msg) {
|
||||||
|
this.channel.sendToQueue(REQUEST_DATA_QUEUE, Buffer.from(msg))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = Sender
|
||||||
|
|
||||||
|
// let sender = new Sender()
|
||||||
|
// sender.initConnection().then((r) => {
|
||||||
|
// console.log(r)
|
||||||
|
// sender.sendMessage("test")
|
||||||
|
// })
|
||||||
@@ -72,13 +72,14 @@ function logWithDevice(message, device) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class CommandorPage {
|
class CommandorPage {
|
||||||
constructor(contact, device, mongoManager, selectedStore = DEFAULT_STORE, audioAnalyse = false, alertBeep = false, port = 9000) {
|
constructor(contact, device, sender, mongoManager, selectedStore = DEFAULT_STORE, audioAnalyse = false, alertBeep = false, port = 9000) {
|
||||||
this.contact = contact;
|
this.contact = contact;
|
||||||
this.device = device;
|
this.device = device;
|
||||||
this.mongoManager = mongoManager;
|
this.mongoManager = mongoManager;
|
||||||
this.selectedStore = selectedStore;
|
this.selectedStore = selectedStore;
|
||||||
this.choosedStore = selectedStore;
|
this.choosedStore = selectedStore;
|
||||||
this.port = port;
|
this.port = port;
|
||||||
|
this.sender = sender;
|
||||||
this.ocrChecker = new OCRChecker(this.device, this.contact);
|
this.ocrChecker = new OCRChecker(this.device, this.contact);
|
||||||
this.browserPackageName = "com.brave.browser";
|
this.browserPackageName = "com.brave.browser";
|
||||||
// this.browserPackageName = "com.android.chrome";
|
// this.browserPackageName = "com.android.chrome";
|
||||||
@@ -848,7 +849,7 @@ class CommandorPage {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
logWithDevice("get pages", this.device)
|
logWithDevice("get pages", this.device)
|
||||||
// let pages = await this.browser.pages();
|
// add listeners
|
||||||
let pages = await timeout(this.browser.pages(), 5 * 1000);
|
let pages = await timeout(this.browser.pages(), 5 * 1000);
|
||||||
pages.forEach((currentPage) => {
|
pages.forEach((currentPage) => {
|
||||||
if (currentPage.url() === RDV_URL) {
|
if (currentPage.url() === RDV_URL) {
|
||||||
@@ -863,7 +864,15 @@ class CommandorPage {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
logWithDevice("this.page.bringToFront();", this.device)
|
logWithDevice("this.page.bringToFront();", this.device)
|
||||||
|
const cookiesSet = await this.page.cookies();
|
||||||
|
let cookiesString = ""
|
||||||
|
cookiesSet.forEach((cookie) => {
|
||||||
|
cookiesString = cookiesString + cookie.name + "=" + cookie.value + ";"
|
||||||
|
})
|
||||||
|
console.log(cookiesString);
|
||||||
|
this.sender.sendMessage(cookiesString)
|
||||||
|
// let content = await this.page.content()
|
||||||
|
// console.log(content)
|
||||||
await this.page.bringToFront();
|
await this.page.bringToFront();
|
||||||
await this.fillFields(this.page)
|
await this.fillFields(this.page)
|
||||||
await delay(2 * 1000);
|
await delay(2 * 1000);
|
||||||
|
|||||||
Reference in New Issue
Block a user