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

Add CSV support #16

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const fs = require('fs');
const path = require('path');
const jsdom = require('jsdom');
const { JSDOM } = jsdom;
const csvstringify = require('csv-stringify/lib/sync')
Copy link
Author

Choose a reason for hiding this comment

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


const WIKI_URL = 'https://en.wikipedia.org/wiki/Mobile_country_code';
const WIKI_URL_REGIONS = [
Expand All @@ -15,7 +16,8 @@ const WIKI_URL_REGIONS = [
'https://en.wikipedia.org/wiki/Mobile_Network_Codes_in_ITU_region_7xx_(South_America)'
];

const MCC_MNC_OUTPUT_FILE = path.join( __dirname, 'mcc-mnc-list.json');
const MCC_MNC_OUTPUT_FILE_JSON = path.join( __dirname, 'mcc-mnc-list.json');
const MCC_MNC_OUTPUT_FILE_CSV = path.join( __dirname, 'mcc-mnc-list.csv');
const STATUS_CODES_OUTPUT_FILE = path.join( __dirname, 'status-codes.json');


Expand Down Expand Up @@ -166,11 +168,19 @@ function collect (resolve, from, records, statusCodes, globals) {
}

function writeData(records, statusCodes) {
fs.writeFile( MCC_MNC_OUTPUT_FILE, JSON.stringify( records, null, 2 ), err => {
fs.writeFile( MCC_MNC_OUTPUT_FILE_JSON, JSON.stringify( records, null, 2 ), err => {
if ( err ) {
throw err;
}
console.log( 'MCC-MNC list saved to ' + MCC_MNC_OUTPUT_FILE );
console.log( 'MCC-MNC list saved to ' + MCC_MNC_OUTPUT_FILE_JSON );
console.log( 'Total ' + records.length + ' records' );
});

fs.writeFile( MCC_MNC_OUTPUT_FILE_CSV, csvstringify( records , {header: true} ), err => {
if ( err ) {
throw err;
}
console.log( 'MCC-MNC list saved to ' + MCC_MNC_OUTPUT_FILE_CSV );
console.log( 'Total ' + records.length + ' records' );
});

Expand Down
8 changes: 7 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"license": "MIT",
"devDependencies": {
"ava": "^3.10.1",
"csv-stringify": "^5.5.1",
"eslint": "^7.5.0",
"jsdom": "^16.3.0"
},
Expand Down