Created
March 7, 2020 16:42
-
-
Save astagi/41b1b3a8efd9d2637c539110882f32c0 to your computer and use it in GitHub Desktop.
This file contains 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
import requests | |
def get_all_planets(): | |
page = 0 | |
planets = [] | |
next_url = "https://swapi.co/api/planets/" | |
while next_url: | |
resp = requests.get(next_url).json() | |
next_url = resp['next'] | |
for json_planet in resp['results']: | |
planets.append(json_planet['name']) | |
yield json_planet['name'] | |
page += 1 | |
for planet in get_all_planets(): | |
print (planet) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment