Created
October 17, 2011 17:57
-
-
Save elskwid/1293280 to your computer and use it in GitHub Desktop.
Where Art Thou for Hack4Reno
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
# gems and thangs | |
require 'rest_client' | |
require 'json' | |
# go easy on the fingers | |
data_url = "http://hack4reno.socrata.com/api/views/gbbk-wygz/rows.json" | |
rc = RestClient | |
# we'll take anything right now | |
result = ask "", :choices => "[ANY]" | |
begin | |
resp = rc.get data_url, {:accept => :json} | |
json = JSON.parse(resp) | |
# data | |
d = json['data'] | |
# find it | |
art = d.find{|r| r[0].to_s == result.value} | |
log "FOUND >> #{art.inspect}" | |
# array columns | |
# 8 : first_name | |
# 9: last_name | |
# 10: year | |
# 12 : art_piece | |
# 16 : amount | |
# parse it out | |
full_name = "#{art[8]} #{art[9]}".strip | |
piece_name = art[12].strip if art[12] | |
artist_part = " by #{full_name}" unless full_name == "" | |
year_part = " created in #{art[10]}" if art[10] | |
piece_part = " is named '#{piece_name}'" unless piece_name == "" | |
amount_part = " for $#{art[16]}" if art[16] | |
say "I found it! Art piece ##{result.value}#{piece_part}#{artist_part}#{year_part}#{amount_part}." | |
rescue Exception => e | |
log "EXCEPTION >> #{e.inspect}" | |
say "I had a problem finding that piece of art, would you mind trying again?" | |
end | |
# EOL |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment