Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEV: added csv export to states #103

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Empty file added output/.gitkeep
Empty file.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"cli-table3": "^0.6.0",
"cli-welcome": "^1.4.0",
"comma-number": "^2.0.1",
"csv-writer": "^1.6.0",
"lodash.orderby": "^4.6.0",
"log-symbols": "^4.0.0",
"meow": "^6.1.0",
Expand Down
16 changes: 16 additions & 0 deletions utils/getStates.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const to = require('await-to-js').default;
const handleError = require('cli-handle-error');
const orderBy = require('lodash.orderby');
const sortStatesValidation = require('./sortStatesValidation.js');
const createCsvWriter = require('csv-writer').createObjectCsvWriter;

module.exports = async (
spinner,
Expand Down Expand Up @@ -49,6 +50,21 @@ module.exports = async (
if (!json) {
spinner.info(`${cyan(`Sorted by:`)} ${sortBy}${isRev}`);
}

const csvWriter = createCsvWriter({
path: 'output/chart.csv',
header: [
{id: 'state', title: 'State'},
{id: 'cases', title: 'Cases'},
{id: 'todayCases', title: 'Cases (today)'},
{id: 'deaths', title: 'Deaths'},
{id: 'todayDeaths', title: 'Deaths (today)'},
{id: 'active', title: 'Active'},
]
});

csvWriter.writeRecords(allStates);

Comment on lines +53 to +67
Copy link

@pokimochi pokimochi Jul 25, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

corona states throws an error when the output folder does not exist. I suggest creating the directory if it doesn't exist before writing the records.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, I want to add code to remove this bug. How do I do this? Should I clone, make amends and then do a PR ? or something else ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i suggest you can clone and add a new commit to this pr with the fix, thanks

console.log(output.toString());
}
};