NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

/* jshint esversion: 8 */
require('dotenv').config({
path: '../.env'
});
const csv = require('csv');
const path = require('path')
const {
read_csv_data
} = require('./../lib/utils');
const fs = require('fs')
//const input_path = '/Users/njain/Desktop/datasource-status-check/lib/unidays_student_id_card_example.csv';
const output_path = '/Users/njain/Desktop/datasource-status-check/lib/upload_output.csv';
const input_path = '/Users/njain/Desktop/datasource-status-check/lib/upload.csv';
const {
sendItemUploadRequest
} = require('../lib/m1-api-repository');

const BATCH_SIZE = process.env.BATCH_SIZE;
const column_name_1 = "m1_uri_front";
const column_name_2 = "m1_uri_back";

const unique_external_ids = new Map()

async function student_id_upload() {
const ip = path.join(__dirname, 'sample_student_ids', '1.jpeg')
//console.log(__dirname, sample_student_ids, '1.jpeg')
//const csv_data = await read_csv_data(input_path);
//console.log(csv_data);
let ans = await sendItemUploadRequest(ip, './logs/test.json')
let out = JSON.parse(ans)
console.log("ans",out[0]?.uri)
//console.log(await sendItemUploadRequest('/Users/njain/Desktop/datasource-status-check/core/sample_student_ids/1.jpeg', './logs/test.json'));
//console.log('')

//await process_csv(csv_data);
//console.log(await sendItemUploadRequest(input_path, './logs/test.json'));
}



async function get_curr_batch_promises(curr_batch) {

return curr_batch.map(async (batch_row) => {

let m1_uri_obj = {};

try {
//console.log("qaaa111")
if (batch_row.cardFront_fileID) {
//console.log("qaaa444")
let input_path = '/Users/njain/Desktop/datasource-status-check/core/sample_student_ids/' + batch_row.cardFront_fileID
//console.log("input_path1", input_path)
//console.log(await sendItemUploadRequest(input_path, './logs/test.json'))
let output = await sendItemUploadRequest(input_path, './logs/test.json')
//console.log(output[0])
let ans = JSON.parse(output)
//console.log("outputoutput", output[0].uri)
if (ans[0].uri) {
m1_uri_obj.front = ans[0].uri
}

}
//console.log("qaa2222")
// if (batch_row.cardBack_fileID) {
// //console.log("qaaa555")
// let input_path = '/Users/njain/Desktop/datasource-status-check/core/sample_student_ids/' + batch_row.cardBack_fileID
// //console.log("input_path2", input_path)
// //console.log(await sendItemUploadRequest(input_path, './logs/test.json'))
// let output = await sendItemUploadRequest(input_path, './logs/test.json');
// let ans = JSON.parse(output)
// //console.log("heree", output[0])
// if (ans[0].uri) {
// m1_uri_obj.back = ans[0].uri
// }
// }
} catch (e) {
console.log(e);
}

return m1_uri_obj;
});
}


async function process_csv(csv_data) {
//let column_name = 'individual_id';

const output_write_stream = fs.createWriteStream(output_path, {
flags: 'a'
});
const stringify = csv.stringify({
header: true
});
output_write_stream.on('finish', () => {
console.log('CSV writing completed.');
});
output_write_stream.on('error', (error) => {
console.error('Error writing CSV:', error);
});

stringify.pipe(output_write_stream);

let curr_batch = [];

for (let row of csv_data) {

curr_batch.push(row);

if (curr_batch.length >= BATCH_SIZE) {
const batch = curr_batch.splice(0, BATCH_SIZE);
console.log("heree");
let data = await process_batch(batch)
console.log("heree222");
add_column_for_curr_batch(batch, column_name_1, column_name_2, data);
batch.forEach((batchRow) => {
stringify.write(batchRow);
})
}
}

if (curr_batch.length > 0) {
let data = await process_batch(curr_batch)
add_column_for_curr_batch(curr_batch, column_name_1, column_name_2, data);
curr_batch.forEach((row) => {
stringify.write(row);
});
}

stringify.end();
}

async function process_batch(batch) {
//await delay(3000)
const promises = await get_curr_batch_promises(batch);
const results = await Promise.all(promises);
console.log("results", results)
return results;
}

function add_column_for_curr_batch(batch, column_name_1, column_name_2, data) {
for (let i = 0; i < batch.length; i++) {
const value1 = data[i].front !== undefined ? data[i].front : ''; // Handle blank data
//const value2 = data[i].back !== undefined ? data[i].back : ''; // Handle blank data
batch[i][column_name_1] = value1;
//batch[i][column_name_2] = value2;
}
};

student_id_upload();
     
 
what is notes.io
 

Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 14 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.