Skip to content
This repository
Browse code

Add local caching example

  • Loading branch information...
commit 6ceea65209ebbb681c69504101e192709f46f04a 1 parent a9a1faa
Jonathan Soma authored March 28, 2013
4  README.md
Source Rendered
@@ -203,6 +203,10 @@ See the `postProcess` call? That's called on every row after Tabletop.Model gets
203 203
 
204 204
 A sample lives in `/examples/timeline_setter/`
205 205
 
  206
+### Caching/Not hitting Google Spreadsheets
  207
+
  208
+Use `proxy`! Generate flatfiles using [Flatware](https://github.com/jsoma/flatware) or set up your own cache using something like `/caching/local.rb`.
  209
+
206 210
 # Notes
207 211
 
208 212
 ## Strange behavior
26  caching/local.rb
... ...
@@ -0,0 +1,26 @@
  1
+#####
  2
+# Run as 
  3
+# ruby local.rb "https://docs.google.com/spreadsheet/pub?hl=en_US&hl=en_US&key=0AmYzu_s7QHsmdE5OcDE1SENpT1g2R2JEX2tnZ3ZIWHc&output=html"
  4
+######
  5
+
  6
+require 'open-uri'
  7
+require 'json'
  8
+
  9
+dirty_key = ARGV[0]
  10
+key = dirty_key.gsub(/.*key=(.*?)\&.*/,'\1')
  11
+
  12
+puts key
  13
+
  14
+base_json_url = "https://spreadsheets.google.com/feeds/worksheets/#{key}/public/basic?alt=json-in-script&callback=Tabletop.singleton.loadSheets"
  15
+
  16
+base_json_content = open(base_json_url).read
  17
+
  18
+sheet_ids = base_json_content.scan(/\/public\/basic\/(\w*)/).flatten.uniq
  19
+
  20
+sheet_ids.each do |sheet_id|
  21
+  sheet_url = "https://spreadsheets.google.com//feeds/list/#{key}/#{sheet_id}/public/values?alt=json-in-script&sq=&callback=Tabletop.singleton.loadSheet"
  22
+  content = open(sheet_url).read
  23
+  File.open("#{key}-#{sheet_id}", 'w') { |f| f.write(content) } 
  24
+end
  25
+
  26
+File.open("#{key}", 'w') { |f| f.write(base_json_content) } 
1  examples/proxy/index.html
@@ -21,7 +21,6 @@
21 21
         Tabletop.init( { key: public_spreadsheet_url,
22 22
                          callback: showInfo,
23 23
                          proxy: 'https://s3.amazonaws.com/flatware',
24  
-                         wanted: [ "Cats", "Courses" ],
25 24
                          debug: true } )
26 25
       })
27 26
         

0 notes on commit 6ceea65

Please sign in to comment.
Something went wrong with that request. Please try again.