Skip to content

Commit

Permalink
new model
Browse files Browse the repository at this point in the history
  • Loading branch information
AmolSoans committed Dec 21, 2024
1 parent 132d8ae commit 6447cdc
Show file tree
Hide file tree
Showing 14 changed files with 13,309 additions and 692 deletions.
2,473 changes: 2,473 additions & 0 deletions EQUITY_L.csv

Large diffs are not rendered by default.

51 changes: 51 additions & 0 deletions csv2db.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
const fs = require('fs');
const csv = require('csv-parser');

function csvToJson(csvFilePath, jsonFilePath) {
return new Promise((resolve, reject) => {
const results = { stocks: [] };
let lineCount = 0;

fs.createReadStream(csvFilePath)
.pipe(csv())
.on('data', (row) => {
lineCount++;
const symbol = row['SYMBOL'] ? String(row['SYMBOL']).trim() : null;
const companyName = row['NAME OF COMPANY'] ? String(row['NAME OF COMPANY']).trim() : null;

if (symbol && companyName) {
results.stocks.push({
ticker: symbol,
name: companyName,
});
console.log(`Converted: ${symbol} - ${companyName}`);
}
})
.on('end', () => {
console.log(`Total number of lines: ${lineCount}`);
fs.writeFile(jsonFilePath, JSON.stringify(results, null, 4), (err) => {
if (err) {
reject(`Error writing to JSON file: ${err}`);
} else {
console.log(`Successfully converted '${csvFilePath}' to '${jsonFilePath}'`);
resolve();
}
});
})
.on('error', (err) => {
reject(`Error reading or parsing CSV file: ${err}`);
});
});
}

// Example Usage:
const csvFile = 'EQUITY_L.csv';
const jsonFile = 'db.json';

csvToJson(csvFile, jsonFile)
.then(() => {
console.log("Conversion Complete");
})
.catch((error) => {
console.error("Error during conversion:", error);
});
Loading

0 comments on commit 6447cdc

Please sign in to comment.