Skip to content

Instantly share code, notes, and snippets.

@liquidgenius
Last active October 3, 2017 22:44
Show Gist options
  • Save liquidgenius/64ad42fd0c15da88dfe41e1b2515ed9a to your computer and use it in GitHub Desktop.
Save liquidgenius/64ad42fd0c15da88dfe41e1b2515ed9a to your computer and use it in GitHub Desktop.
Convenience function for paginated data with Jamonek/Robinhood
https://github.com/Jamonek/Robinhood
def depaginate (rh_data):
res = rh_data['results']
while rh_data['next'] not in ['null', None]:
rh_data = rh.get_url(rh_data['next'])
res.append(rh_data['results'][0])
return res
@liquidgenius
Copy link
Author

liquidgenius commented Oct 3, 2017

Useful for creating a uniform structure when dealing with the possibility of paginated responses. Importing time and adding time.sleep(.2) to the loop would add a buffer when querying the API consecutively.

@liquidgenius
Copy link
Author

liquidgenius commented Oct 3, 2017

Usage:
orh = depaginate(rh.order_history())

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment