This commit is contained in:
jlord 2013-07-31 17:36:14 -07:00
parent cab07cae8d
commit 5f64fb79b8
4 changed files with 0 additions and 130 deletions

View File

@ -1 +0,0 @@
[{"contributerstwitter":"jllord","name":"Sweet Bar Bakery","address":"2355 Broadway","city":"Oakland","state":"Ca","long":"-122.266011839473","lat":"37.8129222733119","country":"USA","wifipassword":"cupcakes","outlets":"yes","couch":"no","largetable":"yes","brewing":"","outdoorseating":"yes","hexcolor":"#B9FCFC","rowNumber":1},{"contributerstwitter":"jllord","name":"Awaken Cafe","address":"1429 Broadway","city":"Oakland","state":"Ca","long":"-122.271131495076","lat":"37.8046753170488","country":"USA","wifipassword":"iced coffee","outlets":"yes","couch":"yes","largetable":"yes","brewing":"Four Barrel","outdoorseating":"","hexcolor":"#B9FCFC","rowNumber":2},{"contributerstwitter":"jllord","name":"Panther Coffee","address":"2390 NW 2nd Ave","city":"Miami","state":"Fl","long":"-80.1991536666667","lat":"25.8000021666667","country":"USA","wifipassword":"espresso","outlets":"yes","couch":"no","largetable":"yes","brewing":"In-house","outdoorseating":"yes","hexcolor":"#B9FCFC","rowNumber":3},{"contributerstwitter":"jllord","name":"Haddon Hill Cafe","address":"504 Wesley Ave","city":"Oakland","state":"Ca","long":"-122.2488474","lat":"37.8049159","country":"USA","wifipassword":"haddon10","outlets":"yes","couch":"no","largetable":"yes","brewing":"Sight Glass","outdoorseating":"yes","hexcolor":"#B9FCFC","rowNumber":4},{"contributerstwitter":"jllord","name":"SubRosa Coffee","address":"419 40th Street","city":"Oakland","state":"Ca","long":"-122.2604838","lat":"37.8283586","country":"USA","wifipassword":"-","outlets":"yes","couch":"no","largetable":"no","brewing":"Four Barrel","outdoorseating":"yes","hexcolor":"#B9FCFC","rowNumber":5}]

View File

@ -1,32 +0,0 @@
{
"name": "sheetsee-maplist",
"version": "0.0.0",
"description": "cache google spreadsheet data, draw map and render external tooltips for markers",
"main": "index.js",
"scripts": {
"start": "browservefy test.js"
},
"repository": "",
"keywords": [
"sheetsee",
"map"
],
"author": "jllord",
"license": "BSD",
"devDependencies": {
"browserify": "~2.7.2"
},
"dependencies": {
"jsonp": "0.0.3",
"feed-tables": "~0.1.3",
"mapbox.js": "~0.6.7",
"filesystem-browserify": "0.0.1",
"beefy": "0.0.11",
"tabletop": "1.3.1",
"hasinternet": "0.0.0",
"cheerio": "~0.10.8",
"filed": "0.0.7",
"router": "~0.6.2"
}
}

View File

@ -1,92 +0,0 @@
// dependencies
var fs = require('fs')
var http = require('http')
var Tabletop = require('tabletop')
var dns = require('dns')
var hasInternet = require('hasinternet')
var cheerio = require('cheerio')
var filed = require('filed')
var router = require('router')
// globals
var sheetData = []
var lastFetch
var KEY = '0Ao5u1U6KYND7dFVkcnJRNUtHWUNKamxoRGg4ZzNiT3c'
// 0Ao5u1U6KYND7dGN5QngweVJUWE16bTRob0d2a3dCbnc has lat/long
// cool
// 0Ao5u1U6KYND7dGJpT3cxTGZrZS1WdWo5RnNpa1dZQmc removed lat/long
// for geocoding testing
// 0AvFUWxii39gXdFhqZzdTeU5DTWtOdENkQ1Y5bHdqT0E pet friends
// ready, set, go!
function reqHandler (req, res) {
var route = router()
route.get('/', serveRoot)
route.get('/js/*', serveStatic)
route.get('/css/*', serveStatic)
route.get('/img/*', serveStatic)
route(req, res)
}
function serveRoot(req, res) {
hasInternet(function answer(err, internet) {
if (internet) return freshData(req, res)
console.log("you are offline, fetching stored data")
localData(req, res, buildPage)
})
}
// if you're offline
function localData(req, res, cb) {
fs.readFile(KEY + '.json', function (err, data) {
if (err) throw err;
var staleData = JSON.parse(data)
cb(req, res, staleData)
})
}
// if online
function freshData(req, res) {
function tabletopCb(data, tabletop){
loadSheet(data, tabletop)
buildPage(req, res, data)
}
var options = {key: KEY, callback: tabletopCb, simpleSheet: true}
if (!sheetData.length || (Date.now() - lastFetch) > 6000000000000000000) {
console.log("you are online with old data, fetching new")
Tabletop.init(options)
}
else {
console.log("you are online with fresh data")
localData(req, res, buildPage)
}
}
function loadSheet(data, tabletop) {
sheetData = data
lastFetch = Date.now()
fs.writeFile(KEY +'.json', JSON.stringify(sheetData))
}
function buildPage(req, res, data) {
var fileLocation = __dirname + '/index.html';
var fileStream = fs.readFile(fileLocation, function (err, contents){
var $ = cheerio.load(contents)
$("head").append("<script type='text/javascript'>var gData = " + JSON.stringify(data) + "</script>");
var completePage = $.html()
return res.end(completePage)
})
}
function serveStatic (req, res) {
filed(__dirname + req.url).pipe(res);
}
var server = http.createServer(reqHandler)
var port = process.env.PORT || 3300
server.listen(port)
console.log('Listening on port 3300')

View File

@ -1,5 +0,0 @@
var SheetSee = require('./')
var URL = "https://docs.google.com/spreadsheet/pub?key=0Ao5u1U6KYND7dGN5QngweVJUWE16bTRob0d2a3dCbnc&output=html"
new SheetSee(URL)