Created
August 13, 2012 17:42
-
-
Save danchoi/3342704 to your computer and use it in GitHub Desktop.
reformat Boston Ruby Workshop applications
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# | |
# What: | |
# | |
# This script pulls down the Google Spreadsheet for the Boston Ruby Workshop | |
# on August 17 and 18 and reformats it. Note that you need permissions to | |
# access the doc for this to work. | |
# | |
# Instructions: | |
# | |
# To execute the gist: | |
# | |
# Download it to a file with | |
# wget https://gist.github.com/raw/3342704/f30f67d372c02d93a24d526a571bf7b4a831b998/applicants.rb | |
# | |
# Run with | |
# ruby applicants.rb | |
# | |
# The script will save the output to applications.txt. | |
begin | |
require 'google_drive' | |
rescue LoadError | |
abort "Please gem install google_drive" | |
end | |
print "Your google username (e.g. [email protected]): " | |
login = gets.chomp | |
print "Your password: " | |
system "stty -echo" | |
password = gets.chomp | |
system "stty echo" | |
puts "\nThank you. Logging in and fetching worksheet data." | |
session = GoogleDrive.login(login,password) | |
ws = session.spreadsheet_by_key("0Amj8BH7hPwq6dHpSRHp4RDBTWUV3WWlCV2xuMjBBQlE").worksheets[0] | |
def fmt s | |
IO.popen("fmt", 'w+') {|f| | |
f.puts s | |
f.close_write | |
f.read | |
} | |
end | |
outfile = "applications.txt" | |
out = File.open(outfile, 'w') | |
questions = ws.rows[0] | |
ws.rows[1..-1].each_with_index do |r, num| | |
out.puts '=' * 30 | |
out.puts "Application ##{num + 1}" | |
r.each_with_index do |col, i| | |
out.puts fmt(questions[i]) | |
out.puts fmt(col).gsub(/^/, ' ') | |
out.puts | |
end | |
end | |
out.close | |
puts File.read(outfile) | |
puts | |
puts "Output saved to #{outfile}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment