From 6af1c31f72eb5632b04986c93338a2ff95f314d8 Mon Sep 17 00:00:00 2001 From: "George, Naman Mathew (PG/T - Comp Sci & Elec Eng)" <ng00868@surrey.ac.uk> Date: Fri, 28 Mar 2025 11:25:11 +0000 Subject: [PATCH] Edit showtimes.py --- showtimes.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/showtimes.py b/showtimes.py index e9ff629..c0c2a53 100644 --- a/showtimes.py +++ b/showtimes.py @@ -2,12 +2,15 @@ from services import root_dir, nice_json from flask import Flask from werkzeug.exceptions import NotFound import json +import requests import os app = Flask(__name__) +movies_service = "http://127.0.0.1:5001/movies/{}" +showtimes_db = f"{os.getcwd()}/database/showtimes.json" -with open("{}/database/showtimes.json".format(os.getcwd()), "r") as f: +with open(showtimes_db, "r") as f: showtimes = json.load(f) @@ -24,7 +27,7 @@ def hello(): @app.route("/showtimes", methods=['GET']) def showtimes_list(): - return nice_json(showtimes) + nice_json(showtimes) @app.route("/showtimes/<date>", methods=['GET']) @@ -32,7 +35,11 @@ def showtimes_record(date): if date not in showtimes: raise NotFound print(showtimes[date]) - return nice_json(showtimes[date]) + result = [] + for movie_id in showtimes[date]: + resp = requests.get(movies_service.format(movie_id)) + result.append(resp.json()["title"]) + return nice_json(result) if __name__ == "__main__": app.run(port=5002, debug=True) -- GitLab