forked from jlord/sheetdown
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakeTable.js
More file actions
31 lines (25 loc) · 849 Bytes
/
makeTable.js
File metadata and controls
31 lines (25 loc) · 849 Bytes
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
var request = require('request')
var csv = require('binary-csv')
var concat = require('concat-stream')
module.exports = function makeTable(KEY, callback) {
var base = 'https://docs.google.com/spreadsheet/pub?hl=en_US&hl=en_US&key='
var query = '&single=true&gid=0&output=csv'
var URL = base + KEY + query
var csvParser = csv({json: true})
request(URL).pipe(csvParser).pipe(concat(rows))
function rows(data) {
var table = '|'
var headers = Object.keys(data[0])
var underHeaders = ''
headers.map(function(key) {
table += key + '|'
underHeaders += ' ------ |'
})
table += '\n|' + underHeaders + '\n'
data.map(function(row) {
var values = headers.map(function(h) { return row[h] })
table += '|' + values.join('|') + '|\n'
})
return callback("null", table)
}
}