title: Print more than 20 posts from Tumblr API
body: <p>Good afternoon, </p>
  
  <p>I'm very new to Python, but I'm trying to write a code which will allow me to download all of the posts (including the "notes") 
  from a specified Tumblr account to my computer.</p>
  
  <p>Given my inexperience with coding, I was trying to find a pre-made script which would allow me to do this. I found several brilliant scripts on GitHub, but none of them actually return the notes from Tumblr posts (as far as I can see, although please do correct me if anyone knows of one that does!).</p>
  
  <p>Therefore, I tried to write my own script. I've had some success with the code below. It prints the most recent 20 posts from the given Tumblr (albeit in a rather ugly format -- essentially hundreds of lines of texts all printed into one line of a notepad file):</p>
  
  <pre><code>#This script prints all the posts (including tags, comments) and also the 
  #first 20notes from all the Tumblr blogs.
  
  import pytumblr
  
  # Authenticate via API Key
  client = pytumblr.TumblrRestClient('myapikey')
  
  #offset = 0
  
  # Make the request
  client.posts('staff', limit=2000, offset=0, reblog_info=True, notes_info=True, 
  filter='html')
  #print out into a .txt file
  with open('out.txt', 'w') as f:
  print &gt;&gt; f, client.posts('staff', limit=2000, offset=0, reblog_info=True, 
  notes_info=True, filter='html')
  </code></pre>
  
  <p>However, I want the script to continuously print posts until it reaches the end of the specified blog. </p>
  
  <p>I searched this site and found a very similar question (<a href="https://stackoverflow.com/questions/21689852/getting-only-20-posts-returned-through-pytumblr">Getting only 20 posts returned through PyTumblr</a>), which has been answered by the stackoverflow user poke. However, I can't seem to actually implement poke's solution so that it works for my data. Indeed, when I run the following script, no output at all is produced.</p>
  
  <pre><code>import pytumblr
  
  # Authenticate via API Key
  client = pytumblr.TumblrRestClient('myapikey')
  blog = ('staff')
  def getAllPosts (client, blog):
  offset = 0
  while True:
      posts = client.posts(blog, limit=20, offset=offset, reblog_info=True, notes_info=True)
      if not posts:
          return
  
      for post in posts:
          yield post
  
  
      offset += 20
  </code></pre>
  
  <p>I should note that there are several posts on this site (e.g.<a href="https://stackoverflow.com/questions/26176275/getting-more-than-50-notes-with-tumblr-api">Getting more than 50 notes with Tumblr API</a>) about Tumblr notes, most of them asking how to download more than 50 notes per posts. I'm perfectly happy with just 50 notes per post, it is the number of posts that I would like to increase.</p>
  
  <p>Also, I've tagged this post as Python, however, if there is a better way to get the data I require using another programming language, that would be more than okay.</p>
  
  <p>Thank you very much in advance for your time!</p>