Last active
          August 29, 2015 14:02 
        
      - 
      
- 
        Save johnholdun/67190164681879f106a5 to your computer and use it in GitHub Desktop. 
    Get all your dang tumblr posts
  
        
  
    
      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 'json' | |
| require 'open-uri' | |
| hostname = 'irc' | |
| posts = [] | |
| page = 1 | |
| pages = 1 | |
| per_page = 20 | |
| begin | |
| result = JSON.load open("http://#{ hostname }.tumblr.com/api/read/json?debug=1&count=#{ per_page }&start=#{ page * per_page }").read | |
| pages = [1, (result['posts-total'].to_f / per_page).ceil.to_i].max if page == 1 | |
| posts += result['posts'] | |
| page += 1 | |
| end while page < pages | |
| posts = posts.compact.uniq | |
| puts "fetched #{ posts.size } post#{ 's' if posts.size != 1 } from #{ hostname }" | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment