can read ini file
This commit is contained in:
@@ -2,7 +2,9 @@ const {app, BrowserWindow, ipcMain} = require('electron')
|
|||||||
const {_android: android} = require('playwright');
|
const {_android: android} = require('playwright');
|
||||||
const startBookWithNumbers = require('./src/appointment')
|
const startBookWithNumbers = require('./src/appointment')
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
|
const homedir = require('os').homedir();
|
||||||
|
const loadIniFile = require('read-ini-file')
|
||||||
|
const configFilePath = path.join(homedir, 'config.ini')
|
||||||
const createWindow = () => {
|
const createWindow = () => {
|
||||||
const win = new BrowserWindow({
|
const win = new BrowserWindow({
|
||||||
width: 800,
|
width: 800,
|
||||||
@@ -34,10 +36,14 @@ app.on('window-all-closed', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
function startBook(startNumber, endNumber, selectedStore) {
|
function startBook(startNumber, endNumber, selectedStore) {
|
||||||
console.log("startNumber: " + startNumber)
|
console.log("startNumber: " + startNumber);
|
||||||
console.log("endNumber: " + endNumber)
|
console.log("endNumber: " + endNumber);
|
||||||
console.log("selectedStore: " + selectedStore)
|
console.log("selectedStore: " + selectedStore);
|
||||||
startBookWithNumbers(startNumber, endNumber, selectedStore).then(() => {
|
//load config.ini file
|
||||||
|
let config = loadIniFile.sync(configFilePath);
|
||||||
|
console.log(config);
|
||||||
|
let contactExcelFilePath = config.DEFAULT.contact_list_file;
|
||||||
|
startBookWithNumbers(startNumber, endNumber, selectedStore, contactExcelFilePath).then(() => {
|
||||||
console.log("stop")
|
console.log("stop")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@nodegui/nodegui": "^0.57.1",
|
"@nodegui/nodegui": "^0.57.1",
|
||||||
|
"alert": "^5.1.1",
|
||||||
"axios": "^0.27.2",
|
"axios": "^0.27.2",
|
||||||
"beepbeep": "^1.3.0",
|
"beepbeep": "^1.3.0",
|
||||||
"electron-squirrel-startup": "^1.0.0",
|
"electron-squirrel-startup": "^1.0.0",
|
||||||
@@ -18,6 +19,7 @@
|
|||||||
"mongoose": "^6.5.4",
|
"mongoose": "^6.5.4",
|
||||||
"node-xlsx": "^0.21.0",
|
"node-xlsx": "^0.21.0",
|
||||||
"playwright": "1.23.0",
|
"playwright": "1.23.0",
|
||||||
|
"read-ini-file": "^3.0.1",
|
||||||
"winston": "^3.8.2"
|
"winston": "^3.8.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|||||||
+11
-2
@@ -2,6 +2,7 @@ const {_android: android} = require('playwright');
|
|||||||
const ExcelUtil = require("./excel/ExcelUtil");
|
const ExcelUtil = require("./excel/ExcelUtil");
|
||||||
const CommandorPage = require("./workers/CommandorPage");
|
const CommandorPage = require("./workers/CommandorPage");
|
||||||
const {MongoManager, formatDate} = require("./workers/mongo_manager");
|
const {MongoManager, formatDate} = require("./workers/mongo_manager");
|
||||||
|
const alert = require('alert');
|
||||||
|
|
||||||
const mongoManager = new MongoManager();
|
const mongoManager = new MongoManager();
|
||||||
|
|
||||||
@@ -57,18 +58,26 @@ async function startWithList(contacts, device, selectedStore) {
|
|||||||
}, Promise.resolve());
|
}, Promise.resolve());
|
||||||
}
|
}
|
||||||
|
|
||||||
async function startBookWithNumbers(startNumber, endNumber, selectedStore) {
|
async function startBookWithNumbers(startNumber, endNumber, selectedStore, pathToExcelFile = '/Users/lpan/Desktop/contact_all.xlsx') {
|
||||||
let allContactList = excelUtil.readContacts();
|
let allContactList = excelUtil.readContacts(pathToExcelFile);
|
||||||
let contactList;
|
let contactList;
|
||||||
if (endNumber <= allContactList.length) {
|
if (endNumber <= allContactList.length) {
|
||||||
contactList = allContactList.slice(startNumber, endNumber);
|
contactList = allContactList.slice(startNumber, endNumber);
|
||||||
} else {
|
} else {
|
||||||
contactList = allContactList;
|
contactList = allContactList;
|
||||||
}
|
}
|
||||||
|
if (contactList.length === 0) {
|
||||||
|
alert("联系人数为0")
|
||||||
|
return
|
||||||
|
}
|
||||||
mongoManager.connect().then(r => {
|
mongoManager.connect().then(r => {
|
||||||
filterAlreadyBookedContacts(contactList).then(listToBook => {
|
filterAlreadyBookedContacts(contactList).then(listToBook => {
|
||||||
console.log("number of contacts to book:" + listToBook.length)
|
console.log("number of contacts to book:" + listToBook.length)
|
||||||
android.devices().then((devices) => {
|
android.devices().then((devices) => {
|
||||||
|
if (devices.length === 0) {
|
||||||
|
alert("未找到连接的设备");
|
||||||
|
return
|
||||||
|
}
|
||||||
let segmentNumber = listToBook.length / devices.length;
|
let segmentNumber = listToBook.length / devices.length;
|
||||||
for (let i = 0; i < devices.length; i++) {
|
for (let i = 0; i < devices.length; i++) {
|
||||||
startWithList(listToBook.slice(i * segmentNumber, segmentNumber * (i + 1)), devices[i], selectedStore);
|
startWithList(listToBook.slice(i * segmentNumber, segmentNumber * (i + 1)), devices[i], selectedStore);
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ const ContactPojo = require("../models/ContactPojo");
|
|||||||
|
|
||||||
class ExcelUtil {
|
class ExcelUtil {
|
||||||
|
|
||||||
readContacts() {
|
readContacts(pathToExcelFile) {
|
||||||
let workSheetsFromFile = xlsx.parse('/Users/lpan/Desktop/contact_all.xlsx');
|
let workSheetsFromFile = xlsx.parse(pathToExcelFile);
|
||||||
let contactList = [];
|
let contactList = [];
|
||||||
workSheetsFromFile[0].data.forEach(
|
workSheetsFromFile[0].data.forEach(
|
||||||
(info, index, list) => {
|
(info, index, list) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user