Пример #1
0
def get(attribute, value):
    if attribute == "films":
        return swapi.get_film(value).title
    if attribute == "species":
        return swapi.get_species(value).name
    if attribute == "starships":
        return swapi.get_starship(value).name
    if attribute == "vehicles":
        return swapi.get_vehicle(value).name
Пример #2
0
 def test_repr_(self):
     starship = swapi.get_starship(3)
     self.assertEquals('<Starship - Star Destroyer>', starship.__repr__())
     vehicle = swapi.get_vehicle(4)
     self.assertEquals('<Vehicle - Sand Crawler>', vehicle.__repr__())
     film = swapi.get_film(1)
     self.assertEquals('<Film - A New Hope>', film.__repr__())
     planet = swapi.get_planet(1)
     self.assertEquals('<Planet - Tatooine>', planet.__repr__())
     species = swapi.get_species(1)
     self.assertEquals('<Species - Human>', species.__repr__())
Пример #3
0
 def test_repr_(self):
     starship = swapi.get_starship(3)
     self.assertEquals('<Starship - Star Destroyer>', starship.__repr__())
     vehicle = swapi.get_vehicle(4)
     self.assertEquals('<Vehicle - Sand Crawler>', vehicle.__repr__())
     film = swapi.get_film(1)
     self.assertEquals('<Film - A New Hope>', film.__repr__())
     planet = swapi.get_planet(1)
     self.assertEquals('<Planet - Tatooine>', planet.__repr__())
     species = swapi.get_species(1)
     self.assertEquals('<Species - Human>', species.__repr__())
Пример #4
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
Пример #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
Пример #6
0
 def test_starship_get_pilots(self):
     starship = swapi.get_starship(3)
     self.assertEquals(type(starship.get_pilots()), PeopleQuerySet)
Пример #7
0
 def test_starship_get_films(self):
     starship = swapi.get_starship(3)
     self.assertEquals(type(starship.get_films()), FilmQuerySet)
Пример #8
0
        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))
    except:
        starship = swapi.get_starship(10)
    tweet = "#StarWars\nStarship\nName: " + starship.name + "\nModel: " + starship.model + "\nManufacturer: " + starship.manufacturer + "\nMax Atmosphering Speed: " + starship.max_atmosphering_speed + "\nStarship Class: " + starship.starship_class + "\nCargo Capacity: " + starship.cargo_capacity
elif (opc == 5):
    #vehicles
    try:
        vehicle = swapi.get_vehicle(randint(1, 39))
    except:
        vehicle = swapi.get_vehicle(14)
    tweet = "#StarWars\nVehicle\nName: " + vehicle.name + "\nModel :" + vehicle.model + "\nManufacturer :" + vehicle.manufacturer + "\nMax Atmosphering Speed: " + vehicle.max_atmosphering_speed + "\nVehicle Class: " + vehicle.vehicle_class + "\nCargo Capacity: " + vehicle.cargo_capacity

try:
    if (opc == 6):
        comic = xkcd.getRandomComic()
        url = comic.getImageLink()
Пример #9
0
 def test_starship_get_pilots(self):
     starship = swapi.get_starship(3)
     self.assertEquals(type(starship.get_pilots()), PeopleQuerySet)
Пример #10
0
 def test_starship_get_films(self):
     starship = swapi.get_starship(3)
     self.assertEquals(type(starship.get_films()), FilmQuerySet)
Пример #11
0
def starship():
    swapi.get_starship(randint(1, 37))