Merge pull request #3 from Code-Club-Crew/elderspy

imnotacheater
This commit is contained in:
Paul Foster 2018-10-12 16:09:01 -06:00 committed by GitHub
commit 652c3006ff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

35
elderspy/app.py Normal file
View file

@ -0,0 +1,35 @@
import requests
import json
def getStarships(url):
r = requests.get(url)
data = json.loads(r.text)
return data
def getPilot(piloturl):
r = requests.get(piloturl)
pilot = json.loads(r.text)
name = pilot['name']
return name
def extractAndPrint(data):
ships = data['results']
for x in range(len(ships)):
ship = ships[x]
if bool(ship['pilots']) != False:
print("The " + ship['name'] + " was piloted by...")
pilots = ship['pilots']
for i in range(len(pilots)):
piloturl = pilots[i]
print("\t" + getPilot(piloturl))
url = 'https://swapi.co/api/starships/'
while url != "":
try:
data = getStarships(url)
url = data['next']
extractAndPrint(data)
except:
quit()