Beispiel #1
0
def movie_info(movieid):
    if movieid not in movies:
        raise NotFound

    result = movies[movieid]
    result["uri"] = "/movies/{}".format(movieid)

    return nice_json(result)
Beispiel #2
0
def hello():
    return nice_json({
        "uri": "/",
        "subresource_uris": {
            "bookings": "/bookings",
            "booking": "/bookings/<username>"
        }
    })
Beispiel #3
0
def hello():
    return nice_json({
        "uri": "/",
        "subresource_uris": {
            "movies": "/movies",
            "movie": "/movies/<id>"
        }
    })
def hello():
    return nice_json({
        "uri": "/",
        "subresource_uris": {
            "showtimes": "/showtimes",
            "showtime": "/showtimes/<date>"
        }
    })
Beispiel #5
0
def hello():
    return nice_json({
        "uri": "/",
        "subresource_uris": {
            "users": "/users",
            "user": "******",
            "bookings": "/users/<username>/bookings",
            "suggested": "/users/<username>/suggested"
        }
    })
Beispiel #6
0
def user_bookings(username):
    """
    Gets booking information from the 'Bookings Service' for the user, and
     movie ratings etc. from the 'Movie Service' and returns a list.
    :param username:
    :return: List of Users bookings
    """
    if username not in users:
        raise NotFound("User '{}' not found.".format(username))

    try:
        users_bookings = requests.get("http://127.0.0.1:5003/bookings/{}".format(username))
    except requests.exceptions.ConnectionError:
        raise ServiceUnavailable("The Bookings service is unavailable.")

    if users_bookings.status_code == 404:
        raise NotFound("No bookings were found for {}".format(username))

    users_bookings = users_bookings.json()

    # For each booking, get the rating and the movie title
    result = {}
    for date, movies in users_bookings.iteritems():
        result[date] = []
        for movieid in movies:
            try:
                movies_resp = requests.get("http://127.0.0.1:5001/movies/{}".format(movieid))
            except requests.exceptions.ConnectionError:
                raise ServiceUnavailable("The Movie service is unavailable.")
            movies_resp = movies_resp.json()
            result[date].append({
                "title": movies_resp["title"],
                "rating": movies_resp["rating"],
                "uri": movies_resp["uri"]
            })

    return nice_json(result)
Beispiel #7
0
def user_record(username):
    if username not in users:
        raise NotFound

    return nice_json(users[username])
Beispiel #8
0
def get_booking_by_username(username):
    if username not in bookings:
        return "No booking found with username {}".format(username)

    return nice_json(bookings[username])
Beispiel #9
0
def get_user_by_username(username):
    if username not in users:
        return "No user found with username {}".format(username)

    return nice_json(users[username])
Beispiel #10
0
def showtimes_list():
    result = requests.get("http://127.0.0.1:5002/showtimes")
    result = result.json()

    return nice_json(result)
Beispiel #11
0
def querydatabase(db, table):
    con = sqlite3.connect(db)
    cur = con.cursor()
    c = cur.execute("SELECT *from " + table)
    return nice_json(cur.fetchall())
Beispiel #12
0
def booking_record(username):
    if username not in bookings:
        raise NotFound

    return nice_json(bookings[username])
Beispiel #13
0
def showtimes_list():
    return nice_json(showtimes)
Beispiel #14
0
def root():
    return nice_json(ROOT_MOVIES)
def get_all_flights():
    return nice_json(flight_dates)
def get_passenger_flights(passenger):
    return nice_json(passengers[passenger]["flight"])
def get_passenger_specific_flight(passenger):
    passenger_flight = passengers[passenger]["flight"]
    response = requests.get(
        "http://127.0.0.1:5001/flights/{}".format(passenger_flight)).json()
    return nice_json(response)
def get_passenger_info(passenger):
    return nice_json(passengers[passenger])
def get_all_passengers():
    return nice_json(passengers)
Beispiel #20
0
def movies_list():
    result = requests.get("http://127.0.0.1:5001/movies")
    result = result.json()

    return nice_json(result)
Beispiel #21
0
def movie_record():
    return nice_json(movies)
def showtimes_list():
    return nice_json(showtimes)
Beispiel #23
0
def booking_list():
    return nice_json(bookings)
Beispiel #24
0
def querydatabasebyID(db, table, id):
    con = sqlite3.connect(db)
    cur = con.cursor()
    cur.execute("SELECT * from " + table + " WHERE id = ? ", (id, ))
    return nice_json(cur.fetchall())
Beispiel #25
0
def showtimes_record(date):
    if date not in showtimes:
        raise NotFound
    print showtimes[date]
    return nice_json(showtimes[date])
Beispiel #26
0
def user_record(username):
    if username not in users:
        raise NotFound

    return nice_json(users[username])
def get_all_flights_from_date(date):
    return nice_json(flight_dates[date])
Beispiel #28
0
def user_bookings_add(username, page):

    with open("{}/tokens/token.json".format(root_dir()), "r") as ff:
        try:
            token = json.load(ff)
        except:
            raise Unauthorized()
    headers = {
        "Content-Type": "application/json",
        "Authorization": "Bearer {}".format(token['access_token'])
    }
    auth_check = requests.get("http://127.0.0.1:5004/check", headers=headers)
    auth_check = auth_check.json()
    if auth_check['msg'] != 'OK':
        raise Unauthorized(auth_check['msg'])

    headers = {
        "Content-Type": "application/json",
        "Authorization": "Bearer {}".format(token['refresh_token'])
    }
    if auth_check['msg'] == 'Token has expired':
        auth_refresh = requests.post("http://127.0.0.1:5004/refresh",
                                     headers=headers)

    if username not in users:
        raise NotFound("User '{}' not found.".format(username))

    if request.method == 'GET':
        result = {}
        try:
            showtimes = requests.get(
                "http://127.0.0.1:5002/showtimes/{}".format(page))
        except requests.exceptions.ConnectionError:
            raise ServiceUnavailable("The Showtimes service is unavailable.")

        showtimes = showtimes.json()

        for movieid in showtimes:
            result[movieid] = []
            try:
                movies_resp = requests.get(
                    "http://127.0.0.1:5001/movies/{}".format(movieid))
            except requests.exceptions.ConnectionError:
                raise ServiceUnavailable("The Movie service is unavailable.")
            try:
                movies_resp = movies_resp.json()
            except ValueError:
                raise ServiceUnavailable("Sorry! No movies in this day.")
            result[movieid].append({
                "title": movies_resp["title"],
                "rating": movies_resp["rating"]
            })

        return nice_json(result)

    if request.method == 'POST':
        raw = request.get_json()
        try:
            user_resp = requests.get(
                "http://127.0.0.1:5000/users/{}".format(username))
        except:
            raise ServiceUnavailable(
                "Sorry, service unavailable at the moment!")
        try:
            result = requests.post(
                "http://127.0.0.1:5003/bookings/{}/add".format(username),
                json={username: raw})
        except:
            raise ServiceUnavailable(
                "Sorry, service unavailable at the moment!")
        result = result.json()
        user_resp = user_resp.json()
        content = {
            "id": user_resp["id"],
            "name": user_resp["name"],
            "last_active": 0
        }
        content = {username: content}
        with open("{}/database/users.json".format(root_dir())) as ff:
            data = json.load(ff)

        data.update(content)
        with open("{}/database/users.json".format(root_dir()), "w+") as ff:
            json.dump(data, ff)
        users.update(content)
        return nice_json(result)

    raise NotImplementedError()
def showtimes_record(date):
    if date not in showtimes:
        raise NotFound
    print showtimes[date]
    return nice_json(showtimes[date])
Beispiel #30
0
def movie_record():

    print(request.remote_addr)
    return nice_json(movies)
Beispiel #31
0
def users_list():
    return nice_json(users)
Beispiel #32
0
def check():
    ret = {'msg': 'OK'}
    result = nice_json(ret)
    return result, 200
Beispiel #33
0
def movie_record():
    return nice_json(movies)
Beispiel #34
0
def booking_list():
    return nice_json(bookings)
def users():
    if request.method == 'POST':
        raise NotImplementedError()
    else:
        return nice_json([x.to_json() for x in User.query.all()])
Beispiel #36
0
def get_all_bookings():
    return nice_json(bookings)
def user_record(username):
    user = User.query.filter_by(username=username).first()
    if user is None:
        raise NotFound

    return nice_json(user.to_json())
Beispiel #38
0
def users_list():
    return nice_json(users)
Beispiel #39
0
def booking_record(username):
    if username not in bookings:
        raise NotFound

    return nice_json(bookings[username])
Beispiel #40
0
def get_all_users():
    return nice_json(users)