Last active
October 3, 2017 22:44
-
-
Save liquidgenius/64ad42fd0c15da88dfe41e1b2515ed9a to your computer and use it in GitHub Desktop.
Convenience function for paginated data with Jamonek/Robinhood
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
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 |
Usage:
orh = depaginate(rh.order_history())
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.