Created
August 3, 2011 23:55
-
-
Save bitemyapp/1124184 to your computer and use it in GitHub Desktop.
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
require "rubygems" | |
require "json" | |
require "httparty" | |
require "zip/zipfilesystem" | |
$tmp = "/home/callen/tmp/" | |
def judgments_url(job_id) | |
"https://api.crowdflower.com/v1/jobs/#{job_id}.csv?type=json&key=88530fff071fd1301c1279efb35281997b3b9e10" | |
end | |
def zip_path(job_id) | |
return $tmp + "job_#{job_id}.zip" | |
end | |
def json_path(job_id) | |
return $tmp + "job_#{job_id}.json" | |
end | |
class Crowdflower | |
include HTTParty | |
end | |
job_id = 56809 | |
jsonf = Crowdflower.get(judgments_url(job_id)) | |
sio = StringIO.new(jsonf.body) | |
File.open(zip_path(job_id), "w") { | |
|f| | |
f.write(sio.read) | |
} | |
list = [] | |
`cd #{$tmp}; unzip -o job_#{job_id}.zip` | |
File.open(json_path(job_id), "r") { | |
|f| | |
while(line = f.gets) | |
list << JSON.parse(line) | |
end | |
} | |
row = list[0]["results"]["judgments"][0] | |
print row["data"]["flag"] | |
value = (row["data"]["flag"] == "Yes") | |
# key = unit_id | |
print "\n" | |
print "Yes == \"Yes\" " + value.to_s | |
print "\n" | |
print "unit_id: " + row["unit_id"].to_s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment