示例#1
0
def booking_record(username):
    db = mysql.connector.connect(host="127.0.0.1",
                                 user='******',
                                 password='******',
                                 database="mydb")
    cur = db.cursor()
    cur.execute('SELECT id FROM bookings WHERE id = "{}"'.format(username))
    data_to_read = cur.fetchall()
    if data_to_read == []:
        db.close()
        raise NotFound

    cur.execute('SELECT * FROM bookings WHERE id = "{}"'.format(username))
    data_to_read = cur.fetchall()
    db.close()
    rowarray_list = {}
    for row in data_to_read:
        t = row[2]
        if row[1] not in rowarray_list:
            rowarray_list[row[1]] = []

        rowarray_list[row[1]].append(t)

    j = json.dumps(rowarray_list, indent=4, sort_keys=True)
    parsed = json.loads(j)
    return nice_json(parsed)
示例#2
0
def movie_info(movieid):
    db = mysql.connector.connect(host="127.0.0.1",
                                 user='******',
                                 password='******',
                                 database="mydb")
    cur = db.cursor()
    cur.execute('SELECT id FROM movies WHERE id = "{}"'.format(movieid))
    data_to_read = cur.fetchall()
    if data_to_read == []:
        db.close()
        raise NotFound

    cur.execute('SELECT * FROM movies WHERE id = "{}"'.format(movieid))
    data_to_read = cur.fetchall()
    db.close()
    rowarray_list = {}
    for row in data_to_read:
        d = collections.OrderedDict()
        d['title'] = row[0]
        d['rating'] = row[1]
        d['director'] = row[2]
        d['id'] = row[3]
        rowarray_list[d['id']] = d

    j = json.dumps(d, indent=4, sort_keys=True)
    parsed = json.loads(j)
    parsed["uri"] = "/movies/{}".format(movieid)
    return nice_json(parsed)
示例#3
0
def user_record(username):
    db = mysql.connector.connect(host='127.0.0.1',
                                 user='******',
                                 password='******',
                                 database='mydb')
    cur = db.cursor()
    cur.execute('SELECT id FROM users WHERE id = "{}"'.format(username))
    data_to_read = cur.fetchall()
    if data_to_read == []:
        db1.close()
        raise NotFound

    cur.execute('SELECT * FROM users WHERE id = "{}"'.format(username))
    data_to_read = cur.fetchall()
    db.close()
    rowarray_list = {}
    for row in data_to_read:
        d = collections.OrderedDict()
        d['id'] = row[0]
        d['name'] = row[1]
        d['last_active'] = row[2]
        rowarray_list[d['id']] = d

    j = json.dumps(rowarray_list, indent=4, sort_keys=True)
    parsed = json.loads(j)
    return nice_json(parsed)
示例#4
0
def hello():
    return nice_json({
        "uri": "/",
        "subresource_uris": {
            "bookings": "/bookings",
            "booking": "/bookings/<username>"
        }
    })
示例#5
0
def movie_info(movieid):
    if movieid not in movies:
        raise NotFound

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

    return nice_json(result)
示例#6
0
def hello():
    return nice_json({
        "uri": "/",
        "subresource_uris": {
            "movies": "/movies",
            "movie": "/movies/<id>"
        }
    })
示例#7
0
def hello():
    return nice_json({
        "uri": "/",
        "subresource_uris": {
            "showtimes": "/showtimes",
            "showtime": "/showtimes/<date>"
        }
    })
示例#8
0
def hello():
    return nice_json({
        "uri": "/",
        "subresource_uris": {
            "users": "/users",
            "user": "******",
            "bookings": "/users/<username>/bookings",
            "suggested": "/users/<username>/suggested"
        }
    })
示例#9
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
    """
    db = mysql.connector.connect(host="127.0.0.1",
                                 user='******',
                                 password='******',
                                 database="mydb")
    cur = db.cursor()
    cur.execute('SELECT id FROM users WHERE id = "{}"'.format(username))
    data_to_read = cur.fetchall()
    db.close()
    if data_to_read == []:
        raise NotFound("User '{}' not found.".format(username))

    try:
        users_bookings = requests.get(
            "http://bookings-service:8080/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.items():
        result[date] = []
        for movieid in movies:
            try:
                movies_resp = requests.get(
                    "http://movies-service:8080/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)
示例#10
0
def movie_record():
    db = mysql.connector.connect(host="127.0.0.1",
                                 user='******',
                                 password='******',
                                 database="mydb")
    cur = db.cursor()
    cur.execute("SELECT * FROM movies")
    data_to_read = cur.fetchall()
    rowarray_list = {}
    for row in data_to_read:
        d = collections.OrderedDict()
        d['title'] = row[0]
        d['rating'] = row[1]
        d['director'] = row[2]
        d['id'] = row[3]
        rowarray_list[d['id']] = d

    j = json.dumps(rowarray_list, indent=4, sort_keys=True)
    parsed = json.loads(j)
    return nice_json(parsed)
示例#11
0
def booking_list():
    db = mysql.connector.connect(host="127.0.0.1",
                                 user='******',
                                 password='******',
                                 database="mydb")
    cur = db.cursor()
    cur.execute("SELECT * FROM bookings")
    data_to_read = cur.fetchall()
    db.close()
    rowarray_list = {}
    for row in data_to_read:
        t = row[1]
        if row[0] not in rowarray_list:
            rowarray_list[row[0]] = {}

        if row[1] not in rowarray_list[row[0]].keys():
            rowarray_list[row[0]][row[1]] = []

        rowarray_list[row[0]][row[1]].append(row[2])

    j = json.dumps(rowarray_list, indent=4, sort_keys=True)
    parsed = json.loads(j)
    return nice_json(parsed)
示例#12
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://bookings-service/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.items():
        result[date] = []
        for movieid in movies:
            try:
                movies_resp = requests.get("http://movies-service/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)
示例#13
0
def booking_record(username):
    if username not in bookings:
        raise NotFound

    return nice_json(bookings[username])
示例#14
0
def movie_record():
    return nice_json(movies)
示例#15
0
def booking_list():
    return nice_json(bookings)
示例#16
0
def showtimes_record(date):
    if date not in showtimes:
        raise NotFound
    print(showtimes[date])
    return nice_json(showtimes[date])
示例#17
0
def showtimes_list():
    return nice_json(showtimes)
示例#18
0
def users_list():
    return nice_json(users)
示例#19
0
def user_record(username):
    if username not in users:
        raise NotFound

    return nice_json(users[username])