-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from AmolDerickSoans/feature/stateManagement
Feature/state management
- Loading branch information
Showing
25 changed files
with
14,730 additions
and
846 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); |
Oops, something went wrong.