Skip to content

Instantly share code, notes, and snippets.

@aantix
Created January 19, 2011 02:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aantix/785603 to your computer and use it in GitHub Desktop.
Save aantix/785603 to your computer and use it in GitHub Desktop.
Imports the data for a specific Mechanical Turk HIT (by title) and stores the data in an excel spreadsheet.
# turk_import_to_excel.rb hit_title file_output.xls sandbox=false dispose_hit=false
# ruby turk_import_to_excel.rb 'Find resources to help the disabled/underprivileged people of San Francisco, CA' /tmp/output.xls false false
#
# 255 char limitation for spreadsheet cell : http://blog.eastfacesoftware.com/2008/01/14/ruby-spreadsheet-excel-gem-255-character-limit/
#
require 'rubygems'
require 'rturk'
require "spreadsheet/excel"
puts "Search for : '#{ARGV[0]}'"
AWSACCESSKEYID = 'XXXXXXXXXXXXXXX'
AWSACCESSKEY = 'YYYYYYYYYYYYYYY'
sandbox = ARGV[2].nil? ? false : (ARGV[2].downcase == 'true' ? true : false)
dispose_hit = ARGV[3].nil? ? false : (ARGV[3].downcase == 'true' ? true : false)
RTurk.setup(AWSACCESSKEYID, AWSACCESSKEY, :sandbox => sandbox)
hits = RTurk::Hit.all_reviewable
workbook = Spreadsheet::Excel.new(ARGV[1])
worksheet = workbook.add_worksheet("Imported Values #{Time.now}")
row = 1
hits.each do |hit|
puts hit.details.title
if hit.details.title == ARGV[0]
hit.assignments.each do |assignment|
column = 1
values = assignment.answers.each do |k, v|
value = v.nil? ? '' : v
worksheet.write(row, column, value.force_encoding('ASCII-8BIT'))
column+=1
end
row+=1
assignment.approve!('')
end
hit.dispose! if dispose_hit
end
end
workbook.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment