-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
40 lines (30 loc) · 948 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
'use strict';
const xlsx = require('xlsx');
const fs = require('fs');
const FILENAME_WITH_PATH = './goodreads_library_export.csv';
assertFile();
const excelsheet = xlsx.readFile(FILENAME_WITH_PATH, {
type: 'file'
});
let books;
for (let sheetName of Object.keys(excelsheet.Sheets)) {
let sheet = excelsheet.Sheets[sheetName];
books = xlsx.utils.sheet_to_json(sheet).map(row => {
return {
title: row['Title'],
author_name: row['Author'],
my_rating: row['My Rating'],
date_read: row['Date Read'],
bookshelves: row['Exclusive Shelf'],
};
});
}
console.log('Total books ', books.length);
console.log('Total read books ', books.filter(book => book.bookshelves === 'read').length);
function assertFile() {
if (!fs.existsSync(FILENAME_WITH_PATH)) {
console.error(Error(`${FILENAME_WITH_PATH} doesnt exist`));
process.exit(0);
}
console.log(`Reading file from ${FILENAME_WITH_PATH}`)
}