Esempio n. 1
0
def movies_decade(decade):
    decade = serverParameterChecks.isYearInvalid(decade)
    if decade is True:
        movie = json.dumps({
            "error":
            "Please enter in any year part of a specific decade. 2010s = 2010-2019"
        })
        return (movie)

    decade = int(str(decade)[:3])

    try:
        regx = re.compile("^{}".format(decade))
        movie = db.movies.aggregate([{
            "$match": {
                "release_date": regx
            }
        }, {
            "$sample": {
                "size": 1
            }
        }])
        movie = movie.next()
        movie = serverParameterChecks.JSONEncoder().encode(movie)
    except:
        movie = json.dumps({"error": "No movies found in the specified year."})

    return (movie)
Esempio n. 2
0
def movies_year(year):
    year = serverParameterChecks.isYearInvalid(year)
    if year is True:
        movie = json.dumps({
            "error":
            "Movie release year has to be a number between {0}-{1}".format(
                min_release_year, max_release_year)
        })
        return (movie)

    try:
        regx = re.compile("^{}".format(year))
        movie = db.movies.aggregate([{
            "$match": {
                "release_date": regx
            }
        }, {
            "$sample": {
                "size": 1
            }
        }])
        movie = movie.next()
        movie = serverParameterChecks.JSONEncoder().encode(movie)
    except Exception as e:
        print(e)
        movie = json.dumps({"error": "No movies found in the specified year."})

    return (movie)
Esempio n. 3
0
def movies_rating_range(ratingRange):

    ratingRange = serverParameterChecks.isRatingRangeInvalid(ratingRange)
    if ratingRange is True:
        movie = json.dumps(
            {"error": "Movie range has to be in the following format: 0.0-10"})
        return (movie)
    try:
        movie = db.movies.aggregate([{
            "$match": {
                "vote_average": {
                    "$gte": ratingRange[0],
                    "$lte": ratingRange[1]
                }
            }
        }, {
            "$sample": {
                "size": 1
            }
        }])
        movie = movie.next()
        movie = serverParameterChecks.JSONEncoder().encode(movie)
    except:
        movie = json.dumps(
            {"error": "No movies found in the range specified."})

    return (movie)
Esempio n. 4
0
def movies_rating(rating):
    if serverParameterChecks.isRatingInvalid(rating):
        movie = json.dumps({
            "error":
            "Movie rating has to be a integer/decimal number between 0 and 10."
        })
        return (movie)
    try:
        movie = db.movies.aggregate([{
            "$match": {
                "vote_average": {
                    "$gte": float(rating)
                }
            }
        }, {
            "$sample": {
                "size": 1
            }
        }])
        movie = movie.next()
        movie = serverParameterChecks.JSONEncoder().encode(movie)
    except:
        movie = json.dumps(
            {"error": "No movies above this rating found in Database."})

    return (movie)
Esempio n. 5
0
def movies():
    try:
        movie = db.movies.aggregate([{"$sample": {"size": 1}}])
        movie = movie.next()
        movie = serverParameterChecks.JSONEncoder().encode(movie)
    except:
        movie = json.dumps({"error": "No movies found in Database."})
    return (movie)
Esempio n. 6
0
def movies_title(title):
    if serverParameterChecks.isStringParameterInvalid(title):
        movie = json.dumps({
            "error":
            "Movie title length invalid or contains invalid characters."
        })
        return (movie)

    try:
        movie = db.movies.find({"title": title})
        movie = movie.next()
        movie = serverParameterChecks.JSONEncoder().encode(movie)
    except:
        movie = json.dumps(
            {"error": "No movie with this title found in database."})

    return (movie)
Esempio n. 7
0
def movies_id(id):
    if serverParameterChecks.isIDInvalid(id):
        movie = json.dumps({
            "error":
            "Movie ID has to be a number. Ensure it is greater than 0 and smaller than 1{}"
            .format("0" * max_ID_length)
        })
        return (movie)

    try:
        movie = db.movies.find({"id": int(id)})
        movie = movie.next()
        movie = serverParameterChecks.JSONEncoder().encode(movie)
    except:
        movie = json.dumps(
            {"error": "No movie with this ID found in database."})

    return (movie)
Esempio n. 8
0
def actors_id(id):
    actor = ""

    if serverParameterChecks.isIDInvalid(id):
        actor = json.dumps({
            "error":
            "Actor ID has to be a number. Ensure it is greater than 0 and smaller than 1{}"
            .format("0" * max_ID_length)
        })
        return (actor)

    try:
        actor = db.actors.find({"actor_id": int(id)})
        actor = actor.next()
        actor = serverParameterChecks.JSONEncoder().encode(actor)
    except:
        actor = json.dumps(
            {"error": "No actor with this ID found in database."})
    return (actor)
Esempio n. 9
0
def credits_title(title):
    credits = ""

    if serverParameterChecks.isStringParameterInvalid(title):
        movie = json.dumps({
            "error":
            "Movie title length invalid or contains invalid characters."
        })
        return (movie)

    try:
        credits = db.credits.find({"title": title})
        credits = credits.next()
        credits = serverParameterChecks.JSONEncoder().encode(credits)
    except:
        credits = json.dumps(
            {"error": "No credits with this title found in database."})

    return (credits)
Esempio n. 10
0
def actors_name(name):
    actor = ""

    if serverParameterChecks.isStringParameterInvalid(name):
        actor = json.dumps({
            "error":
            "Actor name length invalid or contains invalid characters."
        })
        return (actor)

    try:
        print(name)
        actor = db.actors.find({"name": name})
        actor = actor.next()
        actor = serverParameterChecks.JSONEncoder().encode(actor)
    except Exception:
        actor = json.dumps(
            {"error": "No actor with this name found in database."})

    return (actor)
Esempio n. 11
0
def credits_id(id):
    credits = ""

    if serverParameterChecks.isIDInvalid(id):
        credits = json.dumps({
            "error":
            "Movie ID has to be a number. Ensure it is greater than 0 and smaller than 1{}"
            .format("0" * max_ID_length)
        })
        return (credits)

    try:
        credits = db.credits.find({"movie_id": int(id)})
        credits = credits.next()
        credits = serverParameterChecks.JSONEncoder().encode(credits)
    except:
        credits = json.dumps(
            {"error": "No credits with this ID found in database."})

    return (credits)