Forked from
COM3014 / microservices
1 commit ahead of the upstream repository.
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
showtimes.py 1.04 KiB
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(showtimes_db, "r") as f:
showtimes = json.load(f)
@app.route("/", methods=['GET'])
def hello():
return nice_json({
"uri": "/",
"subresource_uris": {
"showtimes": "/showtimes",
"showtime": "/showtimes/<date>"
}
})
@app.route("/showtimes", methods=['GET'])
def showtimes_list():
nice_json(showtimes)
@app.route("/showtimes/<date>", methods=['GET'])
def showtimes_record(date):
if date not in showtimes:
raise NotFound
print(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)