Fetch participants from laconicd GQL endpoint

This commit is contained in:
Prathamesh Musale 2024-08-14 15:31:09 +05:30
parent fec00ac748
commit 1e0c58769b
3 changed files with 1847 additions and 13 deletions

View File

@ -5,21 +5,27 @@ import yargs from 'yargs';
import { hideBin } from 'yargs/helpers';
import { parse as csvParse } from 'csv-parse';
import * as csvWriter from 'csv-writer';
import dotenv from 'dotenv';
import { Registry } from '@cerc-io/registry-sdk';
dotenv.config();
const LACONICD_GQL_ENDPOINT = process.env.LACONICD_GQL_ENDPOINT || 'https://laconicd.laconic.com/api';
const LACONICD_RPC_ENDPOINT = process.env.LACONICD_RPC_ENDPOINT || 'https://laconicd.laconic.com';
const LACONICD_CHAIN_ID = process.env.LACONICD_CHAIN_ID || 'laconic_9000-1';
async function main(): Promise<void> {
const argv = _getArgv();
const participants = readOnboardedParticipants(argv.onboardedJson);
const registry = new Registry(LACONICD_GQL_ENDPOINT, LACONICD_RPC_ENDPOINT, LACONICD_CHAIN_ID);
const participants = await registry.getParticipants();
const subscribers = await readSubscribers(argv.subscribersCsv);
processSubscribers(participants, subscribers, argv.output);
}
function readOnboardedParticipants(onboardedJsonPath: string): any {
const jsonData = JSON.parse(fs.readFileSync(onboardedJsonPath, 'utf-8'));
return jsonData.participants;
}
async function readSubscribers(subscribersCsvPath: string): Promise<any> {
const fileContent = fs.readFileSync(subscribersCsvPath, { encoding: 'utf-8' });
const headers = ['subscriber_id', 'email', 'status', 'premium?', 'created_at', 'api_subscription_id'];
@ -83,12 +89,6 @@ async function processSubscribers(participants: any[], subscribers: any[], outpu
function _getArgv (): any {
return yargs(hideBin(process.argv))
.option('onboardedJson', {
alias: 'j',
type: 'string',
demandOption: true,
describe: 'Path to the onboarded JSON file',
})
.option('subscribersCsv', {
alias: 's',
type: 'string',

View File

@ -12,9 +12,11 @@
"typescript": "^5.5.4"
},
"dependencies": {
"@cerc-io/registry-sdk": "^0.2.6",
"csv-parse": "^5.5.6",
"csv-parser": "^3.0.0",
"csv-writer": "^1.6.0",
"dotenv": "^16.4.5",
"yargs": "^17.7.2"
}
}

1834
yarn.lock

File diff suppressed because it is too large Load Diff