Beispiel #1
0
def get_random_actor():
    while True:
        query = "select actor_id, name from actors ORDER BY rand() limit 200"
        results = engine.execute(query)
        actor = get_actor_with_3_movies(results)
        if actor:
            return actor
Beispiel #2
0
def get_random_actor():
    while True:
        query = "select actor_id, name from actors ORDER BY rand() limit 200"
        results = engine.execute(query)
        actor = get_actor_with_3_movies(results)
        if actor:
            return actor
Beispiel #3
0
def get_cast_excluding(movie_name, excluding):
    escaped = MySQLdb.escape_string(movie_name)
    escaped_excluding = MySQLdb.escape_string(excluding)
    query = "SELECT A.actor_id, A.name " \
            "FROM actors A " \
            "JOIN acts AC on AC.actor_id = A.actor_id " \
            "JOIN movies M on M.movie_id = AC.movie_id " \
            "WHERE M.name= '{}' AND A.name <> '{}'".format(escaped, escaped_excluding)
    cast = engine.execute(query).fetchall()
    return cast
Beispiel #4
0
def get_cast_excluding(movie_name, excluding):
    escaped = MySQLdb.escape_string(movie_name)
    escaped_excluding = MySQLdb.escape_string(excluding)
    query = "SELECT A.actor_id, A.name " \
            "FROM actors A " \
            "JOIN acts AC on AC.actor_id = A.actor_id " \
            "JOIN movies M on M.movie_id = AC.movie_id " \
            "WHERE M.name= '{}' AND A.name <> '{}'".format(escaped, escaped_excluding)
    cast = engine.execute(query).fetchall()
    return cast
Beispiel #5
0
def get_actor_with_3_movies(results):
    for result in results:
        actor_name = result[1]
        actor_id = result[0]
        query = "select name " \
                "from movies M " \
                "JOIN acts AC on M.movie_id = AC.movie_id " \
                "where AC.actor_id = {}".format(actor_id)
        movies = engine.execute(query).fetchall()
        if len(movies) > 3:
            movies = [movie[0] for movie in movies]
            return jsonify({
                "actor_id": actor_id,
                "name": actor_name,
                "movies": movies
            })
Beispiel #6
0
def get_actor_with_3_movies(results):
    for result in results:
        actor_name = result[1]
        actor_id = result[0]
        query = "select name " \
                "from movies M " \
                "JOIN acts AC on M.movie_id = AC.movie_id " \
                "where AC.actor_id = {}".format(actor_id)
        movies = engine.execute(query).fetchall()
        if len(movies) > 3:
            movies = [movie[0] for movie in movies]
            return jsonify({
                "actor_id": actor_id,
                "name": actor_name,
                "movies": movies
            })