diff --git a/showtimes.py b/showtimes.py index e9ff6290707351ace5151e6b53c821547f494654..9748d5ce4fb2eaccdf272fda0763ef8aac78228d 100644 --- a/showtimes.py +++ b/showtimes.py @@ -1,3 +1,6 @@ +# +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)