Skip to content
Snippets Groups Projects
Commit 7b8f5db7 authored by Foster, Sam C (UG - Computer Science)'s avatar Foster, Sam C (UG - Computer Science)
Browse files

added json dumps instead of flask nicely

parent 053160a0
No related branches found
No related tags found
No related merge requests found
from services import root_dir, nice_json
from flask import Flask from flask import Flask
from werkzeug.exceptions import NotFound from werkzeug.exceptions import NotFound
import json import json
...@@ -11,13 +10,14 @@ with open("{}/database/movies.json".format(os.getcwd()), "r") as f: ...@@ -11,13 +10,14 @@ with open("{}/database/movies.json".format(os.getcwd()), "r") as f:
@app.route("/", methods=['GET']) @app.route("/", methods=['GET'])
def hello(): def hello():
return nice_json({ data = {
"uri": "/", "uri": "/",
"subresource_uris": { "subresource_uris": {
"movies": "/movies", "movies": "/movies",
"movie": "/movies/<id>" "movie": "/movies/<id>"
} }
}) }
return json.dumps(data)
@app.route("/movies/<movieid>", methods=['GET']) @app.route("/movies/<movieid>", methods=['GET'])
def movie_info(movieid): def movie_info(movieid):
...@@ -27,12 +27,12 @@ def movie_info(movieid): ...@@ -27,12 +27,12 @@ def movie_info(movieid):
result = movies[movieid] result = movies[movieid]
result["uri"] = "/movies/{}".format(movieid) result["uri"] = "/movies/{}".format(movieid)
return nice_json(result) return json.dumps(result)
@app.route("/movies", methods=['GET']) @app.route("/movies", methods=['GET'])
def movie_record(): def movie_record():
return nice_json(movies) return json.dumps(movies)
if __name__ == "__main__": if __name__ == "__main__":
......
from services import root_dir, nice_json
from flask import Flask from flask import Flask
from werkzeug.exceptions import NotFound from werkzeug.exceptions import NotFound
import json import json
...@@ -16,18 +15,19 @@ with open(showtimes_db, "r") as f: ...@@ -16,18 +15,19 @@ with open(showtimes_db, "r") as f:
@app.route("/", methods=['GET']) @app.route("/", methods=['GET'])
def hello(): def hello():
return nice_json({ data = {
"uri": "/", "uri": "/",
"subresource_uris": { "subresource_uris": {
"showtimes": "/showtimes", "showtimes": "/showtimes",
"showtime": "/showtimes/<date>" "showtime": "/showtimes/<date>"
}
} }
}) return json.dumps(data)
@app.route("/showtimes", methods=['GET']) @app.route("/showtimes", methods=['GET'])
def showtimes_list(): def showtimes_list():
nice_json(showtimes) return json.dumps(showtimes)
@app.route("/showtimes/<date>", methods=['GET']) @app.route("/showtimes/<date>", methods=['GET'])
...@@ -39,7 +39,7 @@ def showtimes_record(date): ...@@ -39,7 +39,7 @@ def showtimes_record(date):
for movie_id in showtimes[date]: for movie_id in showtimes[date]:
resp = requests.get(movies_service.format(movie_id)) resp = requests.get(movies_service.format(movie_id))
result.append(resp.json()["title"]) result.append(resp.json()["title"])
return nice_json(result) return json.dumps(result)
if __name__ == "__main__": if __name__ == "__main__":
app.run(port=5002, debug=True) 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