Add a progress bar
This commit is contained in:
parent
f7a23e6acd
commit
a13326b7b4
@ -10,6 +10,7 @@
|
||||
|
||||
```bash
|
||||
# Update the values as required
|
||||
# By default, live laconicd testnet (laconicd.laconic.com) endpoint is configured
|
||||
cp .env.example .env
|
||||
```
|
||||
|
||||
|
@ -6,6 +6,7 @@ import { hideBin } from 'yargs/helpers';
|
||||
import { parse as csvParse } from 'csv-parse';
|
||||
import * as csvWriter from 'csv-writer';
|
||||
import dotenv from 'dotenv';
|
||||
import * as cliProgress from 'cli-progress';
|
||||
|
||||
import { StargateClient } from '@cosmjs/stargate';
|
||||
import { Registry } from '@cerc-io/registry-sdk';
|
||||
@ -29,7 +30,7 @@ async function main(): Promise<void> {
|
||||
}
|
||||
|
||||
async function readSubscribers(subscribersCsvPath: string): Promise<any> {
|
||||
const fileContent = fs.readFileSync(subscribersCsvPath, { encoding: 'utf-8' });
|
||||
const fileContent = fs.readFileSync(path.resolve(subscribersCsvPath), { encoding: 'utf-8' });
|
||||
const headers = ['subscriber_id', 'email', 'status', 'premium?', 'created_at', 'api_subscription_id'];
|
||||
|
||||
return csvParse(fileContent, { delimiter: ',', columns: headers }).toArray();
|
||||
@ -46,8 +47,14 @@ async function processSubscribers(client: StargateClient, participants: any[], s
|
||||
kycMap[participant.kycId] = participant;
|
||||
});
|
||||
|
||||
// Create a new progress bar instance
|
||||
const progressBar = new cliProgress.SingleBar({}, cliProgress.Presets.shades_classic);
|
||||
progressBar.start(subscribers.length, 0);
|
||||
|
||||
const onboardedSubscribers: any[] = [];
|
||||
for (const subscriber of subscribers) {
|
||||
for (let i = 0; i < subscribers.length; i++) {
|
||||
const subscriber = subscribers[i];
|
||||
|
||||
const hashedSubscriberId = hashSubscriberId(subscriber['subscriber_id']);
|
||||
const participant = kycMap[hashedSubscriberId];
|
||||
if (!participant) {
|
||||
@ -91,8 +98,19 @@ async function processSubscribers(client: StargateClient, participants: any[], s
|
||||
};
|
||||
|
||||
onboardedSubscribers.push(onboardedSubscriber);
|
||||
|
||||
// Update the progress bar
|
||||
progressBar.update(i + 1);
|
||||
|
||||
// Wait for a second every 10 entries
|
||||
if (i % 10 === 0) {
|
||||
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||
}
|
||||
}
|
||||
|
||||
// Stop the progress bar
|
||||
progressBar.stop();
|
||||
|
||||
const writer = csvWriter.createObjectCsvWriter({
|
||||
path: path.resolve(outputPath),
|
||||
header: [
|
||||
|
@ -6,6 +6,7 @@
|
||||
"license": "UNLICENSED",
|
||||
"private": true,
|
||||
"devDependencies": {
|
||||
"@types/cli-progress": "^3.11.6",
|
||||
"@types/node": "^22.2.0",
|
||||
"@types/yargs": "^17.0.33",
|
||||
"typescript": "^5.5.4"
|
||||
@ -13,6 +14,7 @@
|
||||
"dependencies": {
|
||||
"@cerc-io/registry-sdk": "^0.2.6",
|
||||
"@cosmjs/stargate": "^0.32.4",
|
||||
"cli-progress": "^3.12.0",
|
||||
"csv-parse": "^5.5.6",
|
||||
"csv-parser": "^3.0.0",
|
||||
"csv-writer": "^1.6.0",
|
||||
|
14
yarn.lock
14
yarn.lock
@ -751,6 +751,13 @@
|
||||
dependencies:
|
||||
"@types/node" "*"
|
||||
|
||||
"@types/cli-progress@^3.11.6":
|
||||
version "3.11.6"
|
||||
resolved "https://registry.yarnpkg.com/@types/cli-progress/-/cli-progress-3.11.6.tgz#94b334ebe4190f710e51c1bf9b4fedb681fa9e45"
|
||||
integrity sha512-cE3+jb9WRlu+uOSAugewNpITJDt1VF8dHOopPO4IABFc3SXYL5WE/+PTz/FCdZRRfIujiWW3n3aMbv1eIGVRWA==
|
||||
dependencies:
|
||||
"@types/node" "*"
|
||||
|
||||
"@types/google-protobuf@^3.15.5":
|
||||
version "3.15.12"
|
||||
resolved "https://registry.yarnpkg.com/@types/google-protobuf/-/google-protobuf-3.15.12.tgz#eb2ba0eddd65712211a2b455dc6071d665ccf49b"
|
||||
@ -1024,6 +1031,13 @@ cipher-base@^1.0.0, cipher-base@^1.0.1, cipher-base@^1.0.3:
|
||||
inherits "^2.0.1"
|
||||
safe-buffer "^5.0.1"
|
||||
|
||||
cli-progress@^3.12.0:
|
||||
version "3.12.0"
|
||||
resolved "https://registry.yarnpkg.com/cli-progress/-/cli-progress-3.12.0.tgz#807ee14b66bcc086258e444ad0f19e7d42577942"
|
||||
integrity sha512-tRkV3HJ1ASwm19THiiLIXLO7Im7wlTuKnvkYaTkyoAPefqjNg7W7DHKUlGRxy9vxDvbyCYQkQozvptuMkGCg8A==
|
||||
dependencies:
|
||||
string-width "^4.2.3"
|
||||
|
||||
cliui@^8.0.1:
|
||||
version "8.0.1"
|
||||
resolved "https://registry.yarnpkg.com/cliui/-/cliui-8.0.1.tgz#0c04b075db02cbfe60dc8e6cf2f5486b1a3608aa"
|
||||
|
Loading…
Reference in New Issue
Block a user