Delete other people's solutions

This commit is contained in:
Daniel Flanagan 2022-10-21 10:11:52 -05:00
parent cd2548feac
commit 7522ade795
Signed by: lytedev
GPG key ID: 5B2020A0F9921EF4
8 changed files with 0 additions and 138 deletions

View file

@ -1,35 +0,0 @@
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()

View file

@ -1,12 +0,0 @@
FROM alpine:latest
WORKDIR /app
ADD . /app
RUN apk update && apk add \
py-pip \
python \
python-dev \
alpine-sdk
RUN pip install --upgrade pip
RUN pip install \
swapi
CMD python app.py

View file

@ -1,14 +0,0 @@
# Purpose
Connect to the Star Wars API located at http://swapi.co and return a list of Starships that have a named pilots and then name those Pilots.
# Directions
The Docker image has already been built and published to jagestah/swapitest
With docker installed on your system it should be as simple as `docker run jagestah/swapitest`
This Repo contains the documents used to build the Docker image

View file

@ -1,49 +0,0 @@
#! /bin/python
import json
import requests
import pprint
ship_url = 'https://swapi.co/api/starships/'
people_url = 'https://swapi.co/api/people/'
pp = pprint.PrettyPrinter()
#API call for the ships, looping or pagination
def get_ships(ship_url):
ships_results = requests.get(ship_url)
ship_data = ships_results.json()["results"]
while ships_results.json()["next"]:
ships_results = requests.get(ships_results.json()["next"])
ship_data = ship_data + ships_results.json()["results"]
print("Gathered ship data")
#Sends the results of all the ships in a single list and the people_url to get_people
get_people(people_url, ship_data)
#API call for all the people, looping for pagination
def get_people(people_url, ship_data):
people_results = requests.get(people_url)
people_data = people_results.json()["results"]
while people_results.json()["next"]:
people_results = requests.get(people_results.json()["next"])
people_data = people_data + people_results.json()["results"]
print("Gathered people data \n\r --------------------------------")
#Passes the list of ships and the list of people to list_ships
list_ships(people_data, ship_data)
#checks if the ships has pilots and prints the name of the ship if it does.
def list_ships(people_data, ship_data):
for ship in ship_data:
if ship["pilots"]:
print(ship["name"])
#Passes the ship's info to list_pilots as well as the people_data from before
list_pilots(people_data, ship)
#cross references the data from the ships that list the urls of pilots and prints the name for that entry
def list_pilots(people_data, ship):
for pilot_url in ship["pilots"]:
for person in people_data:
if person["url"] == pilot_url:
print(" "+person["name"])
if __name__ == "__main__":
get_ships(ship_url)

View file

@ -1,14 +0,0 @@
#!/usr/bin/env python
import swapi
import requests
ships = (swapi.get_all("starships"))
print (ships)
for ship in ships.iter():
if len(ship.pilots) > 0:
print(ship.name)
for pilot in ship.pilots:
response = requests.get(pilot)
data = response.json()
print(" "+data["name"].encode('utf-8'))

View file

@ -1 +0,0 @@
swapi

View file

@ -1,13 +0,0 @@
import requests
import json
import swapi
ships = swapi.get_all("starships")
for ship in ships.iter():
if ship.pilots:
print(ship.name)
for pilots in ship.pilots:
jason = requests.get(pilots)
data = jason.json()
print(' '+data['name'].encode('utf-8'))