Permalink
Browse files

fix for google spreadsheets cors issue

  • Loading branch information...
davidguttman committed Nov 14, 2015
1 parent 4591813 commit ce5362fb62d418400caae94ce1b763993092c6cf
Showing with 12 additions and 28 deletions.
  1. +8 −13 fetch.js
  2. +3 −2 package.json
  3. +1 −13 transform.js
View
@@ -1,20 +1,15 @@
+var tabletop = require('tabletop')
var csv = require('csv')
var request = require('superagent')
module.exports = function(url, cb) {
- request(url, function(err, res) {
- if (err) return cb(err)
-
- csvToArray(res.text, cb)
+ tabletop.init({
+ key: url,
+ simpleSheet: true,
+ callback: function (data, tt) {
+ console.log('data', data)
+ cb(null, data)
+ }
})
-
}
-
-function csvToArray (text, cb) {
- csv()
- .from.string(text)
- .to.array(function(array) {
- cb(null, array)
- })
-}
View
@@ -4,7 +4,7 @@
"description": "",
"main": "index.js",
"scripts": {
- "test": "echo \"Error: no test specified\" && exit 1"
+ "start": "beefy index.js"
},
"author": "",
"license": "BSD",
@@ -13,7 +13,8 @@
"browserify": "~2.35.1"
},
"dependencies": {
+ "csv": "~0.3.6",
"superagent": "~0.15.7",
- "csv": "~0.3.6"
+ "tabletop": "^1.4.2"
}
}
View
@@ -1,5 +1,4 @@
-module.exports = function (rawData) {
- var movies = toJSON(rawData)
+module.exports = function (movies) {
addCalcuations(movies)
return movies
}
@@ -19,14 +18,3 @@ function convertNumbers (movie) {
numProps.forEach(function(prop) { movie[prop] = parseFloat(movie[prop]) })
return movie
}
-
-function toJSON (rows) {
- var colNames = rows.shift()
- return jsonRows = rows.map(function(values) {
- var row = {}
- values.forEach(function(val, i) {
- row[colNames[i]] = val
- })
- return row
- })
-}

0 comments on commit ce5362f

Please sign in to comment.