Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor pep8 fixes #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions services/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
import json
from flask import make_response


def root_dir():
""" Returns root director for this project """
return os.path.dirname(os.path.realpath(__file__ + '/..'))


def nice_json(arg):
response = make_response(json.dumps(arg, sort_keys = True, indent=4))
response = make_response(json.dumps(arg, sort_keys=True, indent=4))
response.headers['Content-type'] = "application/json"
return response
return response
5 changes: 3 additions & 2 deletions services/bookings.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@ def hello():
def booking_list():
return nice_json(bookings)


@app.route("/bookings/<username>")
def booking_record(username):
if username not in bookings:
raise NotFound

return nice_json(bookings[username])

if __name__ == "__main__":
app.run(port=5003, debug = True)

if __name__ == "__main__":
app.run(port=5003, debug=True)
6 changes: 4 additions & 2 deletions services/movies.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
with open("{}/database/movies.json".format(root_dir()), "r") as f:
movies = json.load(f)


@app.route("/")
def hello():
return nice_json({
Expand All @@ -19,6 +20,7 @@ def hello():
}
})


@app.route("/movies/<movieid>")
def movie_info(movieid):
if movieid not in movies:
Expand All @@ -29,11 +31,11 @@ def movie_info(movieid):

return nice_json(result)


@app.route("/movies")
def movie_record():
return nice_json(movies)


if __name__ == "__main__":
app.run(port=5001, debug = True)

app.run(port=5001, debug=True)
6 changes: 5 additions & 1 deletion services/showtimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
with open("{}/database/showtimes.json".format(root_dir()), "r") as f:
showtimes = json.load(f)


@app.route("/")
def hello():
return nice_json({
Expand All @@ -19,16 +20,19 @@ def hello():
}
})


@app.route("/showtimes")
def showtimes_list():
return nice_json(showtimes)


@app.route("/showtimes/<date>")
def showtimes_record(date):
if date not in showtimes:
raise NotFound
print showtimes[date]
return nice_json(showtimes[date])


if __name__ == "__main__":
app.run(port=5002, debug = True)
app.run(port=5002, debug=True)
9 changes: 6 additions & 3 deletions services/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,20 @@ def hello():
}
})


@app.route("/users")
def users_list():
return nice_json(users)


@app.route("/users/<username>")
def user_record(username):
if username not in users:
raise NotFound

return nice_json(users[username])


@app.route("/users/<username>/bookings")
def user_bookings(username):
"""
Expand All @@ -46,7 +49,7 @@ def user_bookings(username):
raise NotFound("User '{}' not found.".format(username))

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

Expand All @@ -61,7 +64,7 @@ def user_bookings(username):
result[date] = []
for movieid in movies:
try:
movies_resp = requests.get("http://127.0.0.1:5001/movies/{}".format(movieid))
movies_resp = requests.get("http://0:5001/movies/{}".format(movieid))
except requests.exceptions.ConnectionError:
raise ServiceUnavailable("The Movie service is unavailable.")
movies_resp = movies_resp.json()
Expand All @@ -86,4 +89,4 @@ def user_suggested(username):


if __name__ == "__main__":
app.run(port = 5000, debug = True)
app.run(port=5000, debug=True)