Skip to content
Snippets Groups Projects
Commit a0033b18 authored by Ubuntu's avatar Ubuntu
Browse files

Modified showtimes.py to fetch movie titles

parent fd5e32b3
Branches master
No related tags found
No related merge requests found
#
import requests
#
from services import root_dir, nice_json
from flask import Flask
from werkzeug.exceptions import NotFound
......@@ -9,8 +12,16 @@ app = Flask(__name__)
with open("{}/database/showtimes.json".format(os.getcwd()), "r") as f:
showtimes = json.load(f)
##
MOVIES_SERVICE_URL = "http://127.0.0.1:5001/movies"
def get_movie_title(movie_id):
response = requests.get(f"{MOVIES_SERVICE_URL}/{movie_id}")
if response.status_code == 200:
return response.json().get("title")
return none
##
@app.route("/", methods=['GET'])
def hello():
return nice_json({
......@@ -31,8 +42,13 @@ def showtimes_list():
def showtimes_record(date):
if date not in showtimes:
raise NotFound
print(showtimes[date])
return nice_json(showtimes[date])
#convert movie IDs to movie titles
movie_ids = showtimes[date]
movie_titles = [get_movie_title(movie_id) for movie_id in movie_ids]
# print(showtimes[date])
# return nice_json(showtimes[date])
return nice_json(movie_titles)
if __name__ == "__main__":
app.run(port=5002, debug=True)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment