Skip to content

Instantly share code, notes, and snippets.

@tsabat
Last active August 29, 2015 14:19
Show Gist options
  • Save tsabat/02fb41490f4f0fbf6533 to your computer and use it in GitHub Desktop.
Save tsabat/02fb41490f4f0fbf6533 to your computer and use it in GitHub Desktop.

Hey, here are the images you asked for.

The page breaks the browser cause of the sheer size. I could alter this to download the images for you, but i don't know what u really want to accomplish.

For posterity, here's the code:

#!/usr/bin/env ruby

require 'httparty'
require 'awesome_print'

@urls = []

def url(blob)
  blob['imageUrl']
end

def img(url)
  "<img src='#{url}' >"
end

%w(BLACK BLUE BROWN GRAY GREEN ORANGE PINK PURPLE RED TURQUOISE WHITE YELLOW).each do |color|
  ap "processing #{color}"
  processed = 1
  page      = 1
  status    = { 'totalImageCount' => '100' }

  while processed < status['totalImageCount'].to_i
    rslt   = HTTParty.get("http://rximage.nlm.nih.gov/api/rximage/1/rxnav?&resolution=full&color=#{color}&rPage=#{page}&rPageSize=100")
    status = rslt['replyStatus']

    ap processed
    ap status

    rslt['nlmRxImages'].each do |image|
      @urls << url(image)
    end

    processed += status['imageCount']
    page += 1
  end
end

File.write(
  '/tmp/out.html',
  @urls.map { |url| img(url) }.join('</br>')
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment