Beispiel #1
0
def person():
    swapi.get_person(randint(1, 87))


#61 planets
#7 films
#39 vehicles
#37 starships
#37 species
#87 people
Beispiel #2
0
def index(request):
    try:
        request.session['visited']
    except:
        request.session['visited'] = {}
    """ BLOQUE TODOS LOS PERSONAJES """
    # pjss = swapi.get_all("people")
    # pjs = [pjss]
    """ FIN BLOQUE """
    """ BLOQUE DIEZ PRIMEROS PERSONAJES """
    pjs = []
    for i in range(1, 11):
        pjs.append(swapi.get_person(i))
    """ FIN BLOQUE """
    return render(request, "index.html", {
        'pjs': pjs,
        'visited': request.session['visited']
    })
Beispiel #3
0
def gen_dict_info_from_movie(id):

    movie = swapi.get_film(id)
    characters = []
    planets = []
    species = []
    spaceships = []
    vehicles = []
    """ get all characters from a movie and store them """
    for person in movie.characters:
        person_id = person.split('/')[5]
        characters.append((swapi.get_person(person_id)).name)

    #print (characters)
    #print(len(characters))
    """ get all planets from a movie and store them """
    for planet in movie.planets:
        planet_id = planet.split('/')[5]
        planets.append((swapi.get_planet(planet_id)).name)

    #print (planets)
    """ get all species from a movie and store them """
    for specie in movie.species:
        specie_id = specie.split('/')[5]
        species.append((swapi.get_species(specie_id)).name)
    """ get all starships from a movie and store them """
    for spaceship in movie.starships:
        ship_id = spaceship.split('/')[5]
        spaceships.append((swapi.get_starship(ship_id)).name)
    """ get all vehicles from a movie and store them """
    for vehicle in movie.vehicles:
        vehicle_id = vehicle.split('/')[5]
        vehicles.append((swapi.get_vehicle(vehicle_id)).name)

    dict = {
        'title': movie.title,
        'characters': characters,
        'planets': planets,
        'species': species,
        'spaceships': spaceships,
        'vehicles': vehicles
    }
    return dict
Beispiel #4
0
    def get_context_data(self, **kwargs):
        """
        Get people from the api and save them to the database after
        truncating all data
        """
        data = super().get_context_data(**kwargs)

        Person.objects.all().delete()

        # Person with id of 1
        person_1 = swapi.get_person(1)

        Person.objects.create(name=person_1.name,
                              eye_color=person_1.eye_color,
                              height=person_1.height,
                              birth_year=person_1.birth_year,
                              gender='hidden')

        people = swapi.get_all('people')
        people_with_blue_eyes = []

        for person in people.items:
            if person.eye_color == 'blue':
                people_with_blue_eyes.append(person)

        # People with blue eyes
        for person in people_with_blue_eyes:
            if person.name != person_1.name:
                Person.objects.create(
                    name=person.name if person.name else 'hidden',
                    eye_color='hidden',
                    height=person.height if person.height else 'hidden',
                    birth_year='hidden',
                    gender=person.gender if person.gender else 'hidden')

        data.update({'people': Person.objects.all()})
        return data
Beispiel #5
0
def swapi_to_action(text):
    try:
        if get_match(text, 'swapi')[0]:
            index = get_match(text, 'swapi')[1]
            if index == 0:
                i = swapi.get_planet(randint(1, 61))
                print i
            if index == 1:
                i = swapi.get_film(randint(1, 7))
                print i
            if index == 2:
                i = swapi.get_vehicle(randint(1, 39))
                print i
            if index == 3:
                i = swapi.get_starship(randint(1, 37))
                print i
            if index == 4:
                i = wapi.get_specie(randint(1, 37))
                print i
            if index == 5:
                i = swapi.get_person(randint(1, 87))
                print i
    except:
        pass
Beispiel #6
0
import swapi

luke = swapi.get_person(1)
print(luke.name, type(luke.name))
Beispiel #7
0
def swapi_streaming(*args, **kwargs):
    luke = swapi.get_person(1)
    return luke
Beispiel #8
0
 def test_get_person(self):
     luke = swapi.get_person(1)
     self.assertEquals(luke.name, "Luke Skywalker")
     self.assertEquals(
         '<Person - Luke Skywalker>', luke.__repr__())
Beispiel #9
0
 def test_get_person_homeworld(self):
     luke = swapi.get_person(1)
     home = luke.get_homeworld()
     tatooine = swapi.get_planet(1)
     self.assertEquals(type(home), Planet)
     self.assertEquals(home.name, tatooine.name)
Beispiel #10
0
 def test_get_person_species(self):
     luke = swapi.get_person(1)
     species = swapi.get_species(1)
     human = luke.get_species()
     self.assertEquals(type(species), Species)
Beispiel #11
0
 def test_get_person_films(self):
     luke = swapi.get_person(1)
     films = luke.get_films()
     self.assertEquals(type(films.items[0]), Film)
     self.assertEquals(films.__repr__(), "<FilmQuerySet - 4>")
Beispiel #12
0
 def test_get_person_vehicles(self):
     luke = swapi.get_person(1)
     vehicles = luke.get_vehicles()
     self.assertEquals(type(vehicles.items[0]), Vehicle)
     self.assertEquals(vehicles.__repr__(), "<VehicleQuerySet - 2>")
Beispiel #13
0
import swapi
pm = swapi.get_film(4)
jj = swapi.get_person(36)
for c in pm.get_characters().iter():
    if c.name == jj.name:
        print("Why George, why.")
Beispiel #14
0
 def test_get_person_starships(self):
     luke = swapi.get_person(1)
     starships = luke.get_starships()
     self.assertEquals(type(starships.items[0]), Starship)
     self.assertEquals(starships.__repr__(), "<StarshipQuerySet - 2>")
Beispiel #15
0
def q5(person_id):
    person = swapi.get_person(person_id)
    species = person.get_species().iter()
    names = [sp.name for sp in species]
    return names
Beispiel #16
0
import os  ## import curent os
import facebook  ## imports the facebook sdk
import random
import swapi  ## imports the star wars api
from PIL import Image, ImageDraw  ## imports pillow

token = "your token here :p"


def pes():
    rs = random.randint(1, 82)
    return rs
    ## Ranomizer component to get random number between 1 and 82


SW_id = swapi.get_person(
    pes())  ## calls swapi to get person using randomizer above

SW_more = SW_id.get_homeworld()  ## gets chosen persons homeworld

SW_data = SW_id.get_vehicles(
)  ## gets number of chosen persons driven vehicles

SW_space = SW_id.get_starships(
)  ## gets number of chosen persons flown spaceships

species = SW_id.get_species()  ## gets chosen persons species

spe = species.items  ## lists their species

SW_space2 = SW_space.items  ## lists their flown starships
Beispiel #17
0
 def test_get_person_species(self):
     luke = swapi.get_person(1)
     species = swapi.get_species(1)
     human = luke.get_species()
     self.assertEquals(type(species), Species)
Beispiel #18
0
 def test_get_person_homeworld(self):
     luke = swapi.get_person(1)
     home = luke.get_homeworld()
     tatooine = swapi.get_planet(1)
     self.assertEquals(type(home), Planet)
     self.assertEquals(home.name, tatooine.name)
Beispiel #19
0
 def test_get_person_vehicles(self):
     luke = swapi.get_person(1)
     vehicles = luke.get_vehicles()
     self.assertEquals(type(vehicles.items[0]), Vehicle)
     self.assertEquals(vehicles.__repr__(), "<VehicleQuerySet - 2>")
Beispiel #20
0
def get_person(id):
    return swapi.get_person(id)
Beispiel #21
0
 def test_get_person_films(self):
     luke = swapi.get_person(1)
     films = luke.get_films()
     self.assertEquals(type(films.items[0]), Film)
     self.assertEquals(films.__repr__(), "<FilmQuerySet - 5>")
Beispiel #22
0
if (opc == 1):
    #films
    try:
        film = swapi.get_film(randint(1, 7))
    except:
        film = swapi.get_film(1)
    tweet = "#StarWars\nFilm\nTitle: " + film.title + "\nDirector: " + film.director + "\nRelease Date: " + film.release_date + "\nOpening Crawl:"
    if (len(tweet) < 276):
        ocL = len(film.opening_crawl)
        tL = len(tweet)
        tot = (ocL if ocL + tL <= 276 else 276 - tL)
        tweet += film.opening_crawl[:tot] + "..."
elif (opc == 2):
    #people
    try:
        person = swapi.get_person(randint(1, 87))
    except:
        person = swapi.get_person(1)
    home = person.get_homeworld()
    tweet = "#StarWars\nPerson\nName: " + person.name + "\nHeight: " + person.height + "\nMass: " + person.mass + "\nHair Color: " + person.hair_color + "\nSkin Color: " + person.skin_color + "\nEye Color: " + person.eye_color + "\nBirth Year: " + person.birth_year + "\nGender: " + person.gender + "\nHomeworld: " + home.name
elif (opc == 3):
    #planets
    try:
        planet = swapi.get_planet(randint(1, 61))
    except:
        planet = swapi.get_planet(1)
    tweet = "#StarWars\nPlanet\nName: " + planet.name + "\nRotation Period: " + planet.rotation_period + "\nOrbital Period: " + planet.orbital_period + "\nDiameter: " + planet.diameter + "\nClimate:" + planet.climate + "\nGravity: " + planet.gravity + "\nTerrain: " + planet.terrain + "\nSurface_water:" + planet.surface_water + "\nPopulation:" + planet.population
elif (opc == 4):
    #starships
    try:
        starship = swapi.get_starship(randint(1, 37))
Beispiel #23
0
 def test_get_person_starships(self):
     luke = swapi.get_person(1)
     starships = luke.get_starships()
     self.assertEquals(type(starships.items[0]), Starship)
     self.assertEquals(starships.__repr__(), "<StarshipQuerySet - 2>")
def getCharacterInfo(id):
    return swapi.get_person(id)
Beispiel #25
0
 def test_get_person(self):
     luke = swapi.get_person(1)
     self.assertEquals(luke.name, "Luke Skywalker")
     self.assertEquals('<Person - Luke Skywalker>', luke.__repr__())