From 191a3203b6eeb758961cf2a18cfa03c99ed5a146 Mon Sep 17 00:00:00 2001 From: Paul Foster Date: Fri, 12 Oct 2018 01:07:26 -0600 Subject: [PATCH] comitting initial attempt --- elderspy/app.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 elderspy/app.py diff --git a/elderspy/app.py b/elderspy/app.py new file mode 100644 index 0000000..b56fe4c --- /dev/null +++ b/elderspy/app.py @@ -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()