Created
September 29, 2010 07:34
-
-
Save rtanglao/602412 to your computer and use it in GitHub Desktop.
write js lat,long,avg colour to stdout
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
| #!/usr/bin/env ruby | |
| require 'json' | |
| require 'pp' | |
| pages = 0 | |
| total = 0 | |
| perpage = 0 | |
| ARGF.each_line do |line| | |
| serializedJSON = line | |
| flickr_data_page = JSON.parse(serializedJSON) | |
| page = flickr_data_page["photos"]["page"].to_i | |
| if page == 1 | |
| total = flickr_data_page["photos"]["total"].to_i | |
| perpage = flickr_data_page["photos"]["perpage"].to_i | |
| pages = flickr_data_page["photos"]["pages"].to_i | |
| end | |
| if page == pages | |
| num_photos = total % perpage | |
| else | |
| num_photos = perpage | |
| end | |
| $stderr.printf "page:%d of:%d\n", page, pages | |
| 0.upto num_photos-1 do |photo_index| | |
| if flickr_data_page["photos"]["photo"][photo_index].has_key?("avg_colour_m") | |
| printf("[%s,%s,0x%s],\n", flickr_data_page["photos"]["photo"][photo_index]["latitude"], | |
| flickr_data_page["photos"]["photo"][photo_index]["longitude"], | |
| flickr_data_page["photos"]["photo"][photo_index]["avg_colour_m"]["variable"][6]["statistic"][0]["hex"] | |
| ) | |
| end | |
| end | |
| end |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
reads serialized JSON flickr metadata with average colour
writes array of [lat,long,avg colour] to stdout