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