Permalink
Browse files

Add local caching example

  • Loading branch information...
1 parent a9a1faa commit 6ceea65209ebbb681c69504101e192709f46f04a @jsoma committed Mar 29, 2013
Showing with 30 additions and 1 deletion.
  1. +4 −0 README.md
  2. +26 −0 caching/local.rb
  3. +0 −1 examples/proxy/index.html
View
@@ -203,6 +203,10 @@ See the `postProcess` call? That's called on every row after Tabletop.Model gets
A sample lives in `/examples/timeline_setter/`
+### Caching/Not hitting Google Spreadsheets
+
+Use `proxy`! Generate flatfiles using [Flatware](https://github.com/jsoma/flatware) or set up your own cache using something like `/caching/local.rb`.
+
# Notes
## Strange behavior
View
@@ -0,0 +1,26 @@
+#####
+# Run as
+# ruby local.rb "https://docs.google.com/spreadsheet/pub?hl=en_US&hl=en_US&key=0AmYzu_s7QHsmdE5OcDE1SENpT1g2R2JEX2tnZ3ZIWHc&output=html"
+######
+
+require 'open-uri'
+require 'json'
+
+dirty_key = ARGV[0]
+key = dirty_key.gsub(/.*key=(.*?)\&.*/,'\1')
+
+puts key
+
+base_json_url = "https://spreadsheets.google.com/feeds/worksheets/#{key}/public/basic?alt=json-in-script&callback=Tabletop.singleton.loadSheets"
+
+base_json_content = open(base_json_url).read
+
+sheet_ids = base_json_content.scan(/\/public\/basic\/(\w*)/).flatten.uniq
+
+sheet_ids.each do |sheet_id|
+ sheet_url = "https://spreadsheets.google.com//feeds/list/#{key}/#{sheet_id}/public/values?alt=json-in-script&sq=&callback=Tabletop.singleton.loadSheet"
+ content = open(sheet_url).read
+ File.open("#{key}-#{sheet_id}", 'w') { |f| f.write(content) }
+end
+
+File.open("#{key}", 'w') { |f| f.write(base_json_content) }
@@ -21,7 +21,6 @@
Tabletop.init( { key: public_spreadsheet_url,
callback: showInfo,
proxy: 'https://s3.amazonaws.com/flatware',
- wanted: [ "Cats", "Courses" ],
debug: true } )
})

0 comments on commit 6ceea65

Please sign in to comment.