Permalink
Browse files

Read and parse Google Drive spreadsheet as CSV

  • Loading branch information...
1 parent 592ea46 commit 3b557cac7ed6bde41799ca34e38415953cf6667d @wdenton wdenton committed Apr 3, 2013
Showing with 21 additions and 2 deletions.
  1. +1 −1 config.json.example
  2. +20 −1 my-librarians.rb
View
2 config.json.example
@@ -1,4 +1,4 @@
{
- "something": "value",
+ "spreadsheet_url": "https://docs.google.com/spreadsheet/pub?key=0Ao-FPaoAEqtUdDduMXBVWjRDN3lvZlRhRVpHTEczcVE&single=true&gid=0&output=csv",
"other": "Another value"
}
View
21 my-librarians.rb
@@ -24,14 +24,17 @@
require 'json'
require 'cgi'
+require 'csv'
require 'rubygems'
require 'bundler/setup'
-
require 'sinatra'
+# require 'rack-cache'
+
require 'nokogiri'
require 'open-uri'
+
before do
# Make this the default
content_type 'application/json'
@@ -46,8 +49,24 @@
end
end
+spreadsheet_url = settings.config["spreadsheet_url"]
+
+open(spreadsheet_url) do |f|
+ unless f.status[0] == "200"
+ STDERR.puts f.status
+ # TODO Fail nicely
+ else
+ CSV.parse(f.read, {:headers => true, :header_converters => :symbol}) do |row|
+ # row[:librarian], row[:subject_codes], row[:liaison_codes] and row[:url] are now
+ # available thanks to those header commands.
+ puts row[:librarian]
+ end
+ end
+end
+
get "/" do
+ courses = params[:courses].downcase.split(",")
end

0 comments on commit 3b557ca

Please sign in to comment.