Fix file path issue.

This commit is contained in:
2023-05-19 18:27:56 +02:00
parent 16426f96a9
commit b85b84f4b9
4 changed files with 19 additions and 7 deletions

View File

@@ -1,20 +1,21 @@
const fs = require('fs');
const path = require('path');
function batchAccounts(accounts, batchSize) {
const sortedDir = '../accounts/sorted';
if (!fs.existsSync(sortedDir)) {
fs.mkdirSync(sortedDir);
if (!fs.existsSync(path.join(__dirname, sortedDir))) {
fs.mkdirSync(path.join(__dirname, sortedDir));
}
for (let i = 0; i < accounts.length; i += batchSize) {
const batch = accounts.slice(i, i + batchSize);
const batchNumber = Math.ceil((i + 1) / batchSize);
const batchFilename = `${sortedDir}/batch${batchNumber}.json`;
fs.writeFileSync(batchFilename, JSON.stringify(batch, null, 2));
fs.writeFileSync(path.join(__dirname, batchFilename), JSON.stringify(batch, null, 2));
}
}
const accounts = require('../accounts/accounts.json');
const accounts = require(path.join(__dirname, '../accounts/accounts.json'));
batchAccounts(accounts, 6);
module.exports = { batchAccounts };

View File

@@ -1,4 +1,5 @@
const fs = require('fs');
const path = require('path');
const { By, Key, until } = require('selenium-webdriver');
const { createIdentity } = require('./identityHandler');
@@ -100,13 +101,13 @@ async function createAccount(driver) {
let accounts = [];
if (fs.existsSync('../accounts/accounts.json')) {
if (fs.existsSync(path.join(__dirname, '../accounts/accounts.json'))) {
const content = fs.readFileSync('accounts.json', 'utf8');
accounts = JSON.parse(content);
}
accounts.push(account);
fs.writeFileSync('../accounts/accounts.json', JSON.stringify(accounts));
fs.writeFileSync(path.join(__dirname, '../accounts/accounts.json'), JSON.stringify(accounts));
console.log('Account saved to accounts.json, there are currently ' + accounts.length + ' accounts');