Last active
December 19, 2015 14:09
-
-
Save johnbintz/5966905 to your computer and use it in GitHub Desktop.
Basic Ruby script to create cards for nanDECK from Google Drive spreadsheet data
This file contains hidden or 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
CARD_INFO = { | |
animal: { color: '#aa0000', border: '#ff0000' }, | |
vegetable: { color: '#00aa00', border: '#00ff00' }, | |
mineral: { color: '#0000aa', border: '#0000ff' } | |
}.freeze | |
# install this as a standalone gem | |
# or use a Gemfile and bundle exec with this script | |
require 'google_drive' | |
session = GoogleDrive.login('[email protected]', 'password') | |
# example spreadsheet at https://docs.google.com/spreadsheet/ccc?key=0AnOc_ZMuJyvQdHpUOU1IWEJCa0FMUXFXLVRsTE9ueWc#gid=0 | |
# see how we got the key for below? | |
sheet = session.spreadsheet_by_key("0AnOc_ZMuJyvQdHpUOU1IWEJCa0FMUXFXLVRsTE9ueWc") | |
output = [ | |
"UNIT=INCH", | |
"CARDSIZE=2.5,3.5", | |
"BORDER=NONE", | |
"DPI=300", | |
"PAGE = 8.5, 11, PORTRAIT", | |
"MARGINS = 0.5, 0.5, 0.25, 0.25" | |
] | |
# sheets themselves are zero-based indexed... | |
first = sheet.worksheets[0] | |
card_index = 1 | |
# ...but the data in spreadsheets uses one-based indexing! | |
# be sure to skip the heading | |
for row in 2..first.num_rows - 1 | |
# data now comes from google drive directly! | |
name, value, type = first[row, 1], first[row, 2], first[row, 3].to_sym | |
info = CARD_INFO[type] | |
output << "RECTANGLE = #{card_index}, 0, 0, 2.5, 3.5, #{info[:border]}, #{info[:color]}, 0.25" | |
output << "FONT = Tahoma, 14, B, #000000" | |
output << %{TEXT = #{card_index}, "#{name}", 0.5, 0.5, 1.5, 0.5, center} | |
output << "FONT = Tahoma, 32, B, #000000" | |
output << %{TEXT = #{card_index}, "#{value}", 0.5, 1.5, 1.5, 1.0, center} | |
end | |
File.open('output.txt', 'wb') { |fh| fh.print output.join("\n") } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment